Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 17, 2025
1 parent 9b3ead7 commit 3749241
Show file tree
Hide file tree
Showing 8 changed files with 496 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tests/Feature_v2/Album/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ public function testGet(): void

$response = $this->getJson('Gallery::getUploadLimits');
$this->assertOk($response);

$response = $this->getJson('Gallery::Footer');
$this->assertOk($response);
}
}
14 changes: 14 additions & 0 deletions tests/Feature_v2/Album/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function testUserGet(): void
$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Sharing', ['album_id' => $this->album1->id]);
$this->assertOk($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Sharing::all');
$this->assertOk($response);

$response = $this->actingAs($this->userMayUpload1)->patchJson('Sharing', [
'perm_id' => $this->perm1->id,
'grants_edit' => true,
Expand All @@ -59,5 +62,16 @@ public function testUserGet(): void
'grants_upload' => true,
]);
$this->assertOk($response);

$response = $this->actingAs($this->userMayUpload2)->getJsonWithData('Sharing', ['album_id' => $this->album2->id]);
$this->assertOk($response);
$response->assertJsonCount('1');

Check failure on line 68 in tests/Feature_v2/Album/SharingTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.3 - PHPStan

Parameter #1 $count of method Illuminate\Testing\TestResponse<Illuminate\Http\JsonResponse>::assertJsonCount() expects int, string given.

Check failure on line 68 in tests/Feature_v2/Album/SharingTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.4 - PHPStan

Parameter #1 $count of method Illuminate\Testing\TestResponse<Illuminate\Http\JsonResponse>::assertJsonCount() expects int, string given.

$id = $response->json()[0]['id'];
$response = $this->actingAs($this->userMayUpload1)->deleteJson('Sharing', ['perm_id' => $id]);
$this->assertForbidden($response);

$response = $this->actingAs($this->userMayUpload2)->deleteJson('Sharing', ['perm_id' => $id]);
$this->assertNoContent($response);
}
}
19 changes: 19 additions & 0 deletions tests/Feature_v2/Frame/FrameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,23 @@ public function testGet(): void
'timeout' => 30,
]);
}

public function testException(): void
{
$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Frame', ['album_id' => null]);
$this->assertStatus($response, 500);
$response->assertSee('PhotoCollectionEmptyException');
}

public function testRandom(): void
{
$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::star', [
'photo_ids' => [$this->photo1->id],
'is_starred' => true,
]);
$this->assertNoContent($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Photo::random', ['album_id' => null]);
$this->assertOk($response);
}
}
4 changes: 0 additions & 4 deletions tests/Feature_v2/Oauth/OauthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ public function testGetAnonymous(): void
$response = $this->actingAs($this->userMayUpload1)->deleteJson('Oauth', ['provider' => 'github']);
$this->assertNoContent($response);
}

public function testOauthRegistration(): void
{
}
}
75 changes: 75 additions & 0 deletions tests/Feature_v2/Photo/PhotoCopyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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 PhotoCopyTest extends BaseApiV2Test
{
public function testCopyPhotoUnauthorizedForbidden(): void
{
$response = $this->postJson('Photo::copy', []);
$this->assertUnprocessable($response);

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

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

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

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::copy', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->album2->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)->getJsonWithData('Album', ['album_id' => $this->subAlbum1->id]);
$this->assertOk($response);
$response->assertJsonCount(1, 'resource.photos');

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::copy', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->subAlbum1->id,
]);
$this->assertNoContent($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)->getJsonWithData('Album', ['album_id' => $this->subAlbum1->id]);
$this->assertOk($response);
$response->assertJsonCount(2, 'resource.photos');
}
}
236 changes: 236 additions & 0 deletions tests/Feature_v2/Photo/PhotoEditTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
<?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 PhotoEditTest extends BaseApiV2Test
{
public function testEditPhotoUnauthorizedForbidden(): void
{
$response = $this->patchJson('Photo', []);
$this->assertUnprocessable($response);

$response = $this->patchJson('Photo', [
'photo_id' => $this->photo1->id,
'title' => 'new title',
'description' => 'new description',
'tags' => ['tag1'],
'license' => 'none',
'upload_date' => '2021-01-01',
]);
$this->assertUnauthorized($response);

$response = $this->actingAs($this->userNoUpload)->patchJson('Photo::rename', [
'photo_id' => $this->photo1->id,
'title' => 'new title',
'description' => 'new description',
'tags' => ['tag1'],
'license' => 'none',
'upload_date' => '2021-01-01',
]);
$this->assertForbidden($response);
}

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

$response = $this->actingAs($this->userMayUpload1)->patchJson('Photo', [
'photo_id' => $this->photo1->id,
'title' => 'new title',
'description' => 'new description',
'tags' => ['tag1'],
'license' => 'none',
'upload_date' => '2021-01-01',
]);
$this->assertOk($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [],
'resource' => [
'photos' => [
[
'id' => $this->photo1->id,
'title' => 'new title',
'description' => 'new description',
'tags' => ['tag1'],
'license' => 'none',
'created_at' => '2021-01-01T00:00:00+00:00',
],
],
],
]);
}

public function testSetStarPhotoUnauthorizedForbidden(): void
{
$response = $this->postJson('Photo::star', []);
$this->assertUnprocessable($response);

$response = $this->postJson('Photo::star', [
'photo_ids' => [$this->photo1->id],
'is_starred' => true,
]);
$this->assertUnauthorized($response);

$response = $this->actingAs($this->userNoUpload)->postJson('Photo::star', [
'photo_ids' => [$this->photo1->id],
'is_starred' => true,
]);
$this->assertForbidden($response);
}

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

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::star', [
'photo_ids' => [$this->photo1->id],
'is_starred' => true,
]);
$this->assertNoContent($response);

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [],
'resource' => [
'photos' => [
[
'id' => $this->photo1->id,
'is_starred' => true,
],
],
],
]);
}

public function testMovePhotoUnauthorizedForbidden(): void
{
$response = $this->postJson('Photo::move', []);
$this->assertUnprocessable($response);

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

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

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

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::move', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->album2->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)->postJson('Photo::move', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->subAlbum1->id,
]);
$this->assertNoContent($response);

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

$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->subAlbum1->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [],
'resource' => [
'photos' => [
[
'id' => $this->photo1->id,
],
],
],
]);
}

public function testCopyPhotoUnauthorizedForbidden(): void
{
$response = $this->postJson('Photo::copy', []);
$this->assertUnprocessable($response);

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

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

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

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::copy', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->album2->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)->getJsonWithData('Album', ['album_id' => $this->subAlbum1->id]);
$this->assertOk($response);
$response->assertJsonCount(1, 'resource.photos');

$response = $this->actingAs($this->userMayUpload1)->postJson('Photo::copy', [
'photo_ids' => [$this->photo1->id],
'album_id' => $this->subAlbum1->id,
]);
$this->assertNoContent($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)->getJsonWithData('Album', ['album_id' => $this->subAlbum1->id]);
$this->assertOk($response);
$response->assertJsonCount(2, 'resource.photos');
}
}
Loading

0 comments on commit 3749241

Please sign in to comment.