-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDeleteBackupTest.php
64 lines (48 loc) · 2.18 KB
/
DeleteBackupTest.php
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
<?php
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;
use Mockery\MockInterface;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Permission;
use Illuminate\Support\Facades\Event;
use Pterodactyl\Events\ActivityLogged;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
class DeleteBackupTest extends ClientApiIntegrationTestCase
{
private MockInterface $repository;
protected function setUp(): void
{
parent::setUp();
$this->repository = $this->mock(DaemonBackupRepository::class);
}
public function testUserWithoutPermissionCannotDeleteBackup()
{
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_CREATE]);
$backup = Backup::factory()->create(['server_id' => $server->id]);
$this->actingAs($user)->deleteJson($this->link($backup))
->assertStatus(Response::HTTP_FORBIDDEN);
}
/**
* Tests that a backup can be deleted for a server and that it is properly updated
* in the database. Once deleted there should also be a corresponding record in the
* activity logs table for this API call.
*/
public function testBackupCanBeDeleted()
{
Event::fake([ActivityLogged::class]);
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);
/** @var \Pterodactyl\Models\Backup $backup */
$backup = Backup::factory()->create(['server_id' => $server->id]);
$this->repository->expects('setServer->delete')->with(
\Mockery::on(function ($value) use ($backup) {
return $value instanceof Backup && $value->uuid === $backup->uuid;
})
)->andReturn(new Response());
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
$backup->refresh();
$this->assertSoftDeleted($backup);
$this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
}
}