Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Backup/DeleteBackupTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;34use Mockery\MockInterface;5use Illuminate\Http\Response;6use Pterodactyl\Models\Backup;7use Pterodactyl\Models\Permission;8use Illuminate\Support\Facades\Event;9use Pterodactyl\Events\ActivityLogged;10use Pterodactyl\Repositories\Wings\DaemonBackupRepository;11use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;1213class DeleteBackupTest extends ClientApiIntegrationTestCase14{15private MockInterface $repository;1617public function setUp(): void18{19parent::setUp();2021$this->repository = $this->mock(DaemonBackupRepository::class);22}2324public function testUserWithoutPermissionCannotDeleteBackup()25{26[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_CREATE]);2728$backup = Backup::factory()->create(['server_id' => $server->id]);2930$this->actingAs($user)->deleteJson($this->link($backup))31->assertStatus(Response::HTTP_FORBIDDEN);32}3334/**35* Tests that a backup can be deleted for a server and that it is properly updated36* in the database. Once deleted there should also be a corresponding record in the37* activity logs table for this API call.38*/39public function testBackupCanBeDeleted()40{41Event::fake([ActivityLogged::class]);4243[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);4445/** @var Backup $backup */46$backup = Backup::factory()->create(['server_id' => $server->id]);4748$this->repository->expects('setServer->delete')->with(49\Mockery::on(function ($value) use ($backup) {50return $value instanceof Backup && $value->uuid === $backup->uuid;51})52)->andReturn(new Response());5354$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);5556$backup->refresh();57$this->assertSoftDeleted($backup);5859$this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);6061$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);62}63}646566