Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Schedule;
4
5
use Pterodactyl\Models\Task;
6
use Illuminate\Http\Response;
7
use Pterodactyl\Models\Schedule;
8
use Pterodactyl\Models\Permission;
9
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
10
11
class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
12
{
13
/**
14
* Test that a schedule can be deleted from the system.
15
*/
16
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
17
public function testScheduleCanBeDeleted(array $permissions)
18
{
19
[$user, $server] = $this->generateTestAccount($permissions);
20
21
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
22
$task = Task::factory()->create(['schedule_id' => $schedule->id]);
23
24
$this->actingAs($user)
25
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
26
->assertStatus(Response::HTTP_NO_CONTENT);
27
28
$this->assertDatabaseMissing('schedules', ['id' => $schedule->id]);
29
$this->assertDatabaseMissing('tasks', ['id' => $task->id]);
30
}
31
32
/**
33
* Test that no error is returned if the schedule does not exist on the system at all.
34
*/
35
public function testNotFoundErrorIsReturnedIfScheduleDoesNotExistAtAll()
36
{
37
[$user, $server] = $this->generateTestAccount();
38
39
$this->actingAs($user)
40
->deleteJson("/api/client/servers/$server->uuid/schedules/123456789")
41
->assertStatus(Response::HTTP_NOT_FOUND);
42
}
43
44
/**
45
* Ensure that a schedule belonging to another server cannot be deleted and its presence is not
46
* revealed to the user.
47
*/
48
public function testNotFoundErrorIsReturnedIfScheduleDoesNotBelongToServer()
49
{
50
[$user, $server] = $this->generateTestAccount();
51
$server2 = $this->createServerModel(['owner_id' => $user->id]);
52
53
$schedule = Schedule::factory()->create(['server_id' => $server2->id]);
54
55
$this->actingAs($user)
56
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
57
->assertStatus(Response::HTTP_NOT_FOUND);
58
59
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
60
}
61
62
/**
63
* Test that an error is returned if the subuser does not have the required permissions to
64
* delete the schedule from the server.
65
*/
66
public function testErrorIsReturnedIfSubuserDoesNotHaveRequiredPermissions()
67
{
68
[$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_UPDATE]);
69
70
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
71
72
$this->actingAs($user)
73
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
74
->assertStatus(Response::HTTP_FORBIDDEN);
75
76
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
77
}
78
79
public static function permissionsDataProvider(): array
80
{
81
return [[[]], [[Permission::ACTION_SCHEDULE_DELETE]]];
82
}
83
}
84
85