forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteLocationCommandTest.php
More file actions
128 lines (104 loc) · 4.42 KB
/
DeleteLocationCommandTest.php
File metadata and controls
128 lines (104 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Tests\Unit\Commands\Location;
use Mockery as m;
use Pterodactyl\Models\Location;
use Tests\Unit\Commands\CommandTestCase;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Console\Commands\Location\DeleteLocationCommand;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class DeleteLocationCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\Location\DeleteLocationCommand
*/
protected $command;
/**
* @var \Pterodactyl\Services\Locations\LocationDeletionService|\Mockery\Mock
*/
protected $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface|\Mockery\Mock
*/
protected $repository;
/**
* Setup tests.
*/
public function setUp(): void
{
parent::setUp();
$this->deletionService = m::mock(LocationDeletionService::class);
$this->repository = m::mock(LocationRepositoryInterface::class);
$this->command = new DeleteLocationCommand($this->deletionService, $this->repository);
$this->command->setLaravel($this->app);
}
/**
* Test that a location can be deleted.
*/
public function testLocationIsDeleted()
{
$locations = collect([
$location1 = factory(Location::class)->make(),
$location2 = factory(Location::class)->make(),
]);
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$display = $this->runCommand($this->command, [], [$location2->short]);
$this->assertNotEmpty($display);
$this->assertStringContainsString(trans('command/messages.location.deleted'), $display);
}
/**
* Test that a location is deleted if passed in as an option.
*/
public function testLocationIsDeletedIfPassedInOption()
{
$locations = collect([
$location1 = factory(Location::class)->make(),
$location2 = factory(Location::class)->make(),
]);
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$display = $this->withoutInteraction()->runCommand($this->command, [
'--short' => $location2->short,
]);
$this->assertNotEmpty($display);
$this->assertStringContainsString(trans('command/messages.location.deleted'), $display);
}
/**
* Test that prompt shows back up if the user enters the wrong parameters.
*/
public function testInteractiveEnvironmentAllowsReAttemptingSearch()
{
$locations = collect([
$location1 = factory(Location::class)->make(),
$location2 = factory(Location::class)->make(),
]);
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$display = $this->runCommand($this->command, [], ['123_not_exist', 'another_not_exist', $location2->short]);
$this->assertNotEmpty($display);
$this->assertStringContainsString(trans('command/messages.location.no_location_found'), $display);
$this->assertStringContainsString(trans('command/messages.location.deleted'), $display);
}
/**
* Test that no re-attempt is performed in a non-interactive environment.
*/
public function testNonInteractiveEnvironmentThrowsErrorIfNoLocationIsFound()
{
$locations = collect([
$location1 = factory(Location::class)->make(),
$location2 = factory(Location::class)->make(),
]);
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldNotReceive('handle');
$display = $this->withoutInteraction()->runCommand($this->command, ['--short' => 'randomTestString']);
$this->assertNotEmpty($display);
$this->assertStringContainsString(trans('command/messages.location.no_location_found'), $display);
}
}