Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Client\Server\Schedule;34use Pterodactyl\Models\Task;5use Illuminate\Http\Response;6use Pterodactyl\Models\Schedule;7use Pterodactyl\Models\Permission;8use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;910class DeleteServerScheduleTest extends ClientApiIntegrationTestCase11{12/**13* Test that a schedule can be deleted from the system.14*/15#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]16public function testScheduleCanBeDeleted(array $permissions)17{18[$user, $server] = $this->generateTestAccount($permissions);1920$schedule = Schedule::factory()->create(['server_id' => $server->id]);21$task = Task::factory()->create(['schedule_id' => $schedule->id]);2223$this->actingAs($user)24->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")25->assertStatus(Response::HTTP_NO_CONTENT);2627$this->assertDatabaseMissing('schedules', ['id' => $schedule->id]);28$this->assertDatabaseMissing('tasks', ['id' => $task->id]);29}3031/**32* Test that no error is returned if the schedule does not exist on the system at all.33*/34public function testNotFoundErrorIsReturnedIfScheduleDoesNotExistAtAll()35{36[$user, $server] = $this->generateTestAccount();3738$this->actingAs($user)39->deleteJson("/api/client/servers/$server->uuid/schedules/123456789")40->assertStatus(Response::HTTP_NOT_FOUND);41}4243/**44* Ensure that a schedule belonging to another server cannot be deleted and its presence is not45* revealed to the user.46*/47public function testNotFoundErrorIsReturnedIfScheduleDoesNotBelongToServer()48{49[$user, $server] = $this->generateTestAccount();50$server2 = $this->createServerModel(['owner_id' => $user->id]);5152$schedule = Schedule::factory()->create(['server_id' => $server2->id]);5354$this->actingAs($user)55->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")56->assertStatus(Response::HTTP_NOT_FOUND);5758$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);59}6061/**62* Test that an error is returned if the subuser does not have the required permissions to63* delete the schedule from the server.64*/65public function testErrorIsReturnedIfSubuserDoesNotHaveRequiredPermissions()66{67[$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_UPDATE]);6869$schedule = Schedule::factory()->create(['server_id' => $server->id]);7071$this->actingAs($user)72->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")73->assertStatus(Response::HTTP_FORBIDDEN);7475$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);76}7778public static function permissionsDataProvider(): array79{80return [[[]], [[Permission::ACTION_SCHEDULE_DELETE]]];81}82}838485