Skip to content

Commit

Permalink
add Photo delete test
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 19, 2025
1 parent c9fea58 commit 87c00ca
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/Feature_v2/Photo/PhotoDeleteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Photo;

use Tests\Feature_v2\Base\BaseApiV2Test;

class PhotoDeleteTest extends BaseApiV2Test
{
public function testDeletePhotoUnauthorizedForbidden(): void
{
$response = $this->deleteJson('Photo', []);
$this->assertUnprocessable($response);

$response = $this->deleteJson('Photo', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->album2->id,
]);
$this->assertUnauthorized($response);

$response = $this->actingAs($this->userNoUpload)->deleteJson('Photo', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->album2->id,
]);
$this->assertForbidden($response);
}

public function testDeletePhotoAuthorizedOwner(): void
{
$response = $this->actingAs($this->userMayUpload1)->deleteJson('Photo', []);
$this->assertUnprocessable($response);

$response = $this->actingAs($this->userLocked)->deleteJson('Photo', [
'photo_ids' => [$this->photo1->id],
]);
$this->assertForbidden($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertOk($response);
$response->assertJsonCount(2, 'resource.photos');

$response = $this->actingAs($this->userMayUpload1)->deleteJson('Photo', [
'photo_ids' => [$this->photo1->id],
]);
$this->assertNoContent($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertOk($response);
$response->assertJsonCount(1, 'resource.photos');
}
}

0 comments on commit 87c00ca

Please sign in to comment.