Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Backup/DeleteBackupTest.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;
4
5
use Mockery\MockInterface;
6
use Illuminate\Http\Response;
7
use Pterodactyl\Models\Backup;
8
use Pterodactyl\Models\Permission;
9
use Illuminate\Support\Facades\Event;
10
use Pterodactyl\Events\ActivityLogged;
11
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
12
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
13
14
class DeleteBackupTest extends ClientApiIntegrationTestCase
15
{
16
private MockInterface $repository;
17
18
public function setUp(): void
19
{
20
parent::setUp();
21
22
$this->repository = $this->mock(DaemonBackupRepository::class);
23
}
24
25
public function testUserWithoutPermissionCannotDeleteBackup()
26
{
27
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_CREATE]);
28
29
$backup = Backup::factory()->create(['server_id' => $server->id]);
30
31
$this->actingAs($user)->deleteJson($this->link($backup))
32
->assertStatus(Response::HTTP_FORBIDDEN);
33
}
34
35
/**
36
* Tests that a backup can be deleted for a server and that it is properly updated
37
* in the database. Once deleted there should also be a corresponding record in the
38
* activity logs table for this API call.
39
*/
40
public function testBackupCanBeDeleted()
41
{
42
Event::fake([ActivityLogged::class]);
43
44
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);
45
46
/** @var Backup $backup */
47
$backup = Backup::factory()->create(['server_id' => $server->id]);
48
49
$this->repository->expects('setServer->delete')->with(
50
\Mockery::on(function ($value) use ($backup) {
51
return $value instanceof Backup && $value->uuid === $backup->uuid;
52
})
53
)->andReturn(new Response());
54
55
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
56
57
$backup->refresh();
58
$this->assertSoftDeleted($backup);
59
60
$this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);
61
62
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
63
}
64
}
65
66