-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathAlbumTest.php
More file actions
133 lines (122 loc) · 3.18 KB
/
AlbumTest.php
File metadata and controls
133 lines (122 loc) · 3.18 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?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\Album;
use Tests\Feature_v2\Base\BaseApiWithDataTest;
class AlbumTest extends BaseApiWithDataTest
{
public function testGet(): void
{
$response = $this->getJson('Album');
$this->assertUnprocessable($response);
$response->assertJson([
'message' => 'The album id field is required.',
]);
}
public function testGetAnon(): void
{
$response = $this->getJsonWithData('Album', ['album_id' => $this->album4->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [
'is_base_album' => true,
'is_model_album' => true,
'is_accessible' => true,
'is_password_protected' => false,
'is_search_accessible' => false,
],
'resource' => [
'id' => $this->album4->id,
'title' => $this->album4->title,
'albums' => [
[
'id' => $this->subAlbum4->id,
'title' => $this->subAlbum4->title,
'is_public' => true,
'thumb' => [
'id' => $this->subPhoto4->id,
],
],
],
'photos' => [
[
'id' => $this->photo4->id,
],
],
],
]);
}
public function testGetAsGroup(): void
{
$response = $this->actingAs($this->userWithGroup1)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [
'is_base_album' => true,
'is_model_album' => true,
'is_accessible' => true,
'is_password_protected' => false,
'is_search_accessible' => true,
],
'resource' => [
'id' => $this->album1->id,
'title' => $this->album1->title,
'albums' => [],
'photos' => [
[
'id' => $this->photo1->id,
],
[
'id' => $this->photo1b->id,
],
],
],
]);
$response->assertJsonCount(0, 'resource.albums');
$response->assertJsonCount(2, 'resource.photos');
}
public function testGetAsOwner(): void
{
$response = $this->actingAs($this->userMayUpload1)->getJsonWithData('Album', ['album_id' => $this->tagAlbum1->id]);
$this->assertOk($response);
$response->assertJson([
'config' => [
'is_base_album' => true,
'is_model_album' => false,
'is_accessible' => true,
'is_password_protected' => false,
'is_search_accessible' => true,
],
'resource' => [
'id' => $this->tagAlbum1->id,
'title' => $this->tagAlbum1->title,
'photos' => [
[
'id' => $this->photo1->id,
],
],
],
]);
}
public function testGetUnauthorizedOrForbidden(): void
{
// Unauthorized if not logged in.
$response = $this->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertUnauthorized($response);
// Forbidden if logged in.
$response = $this->actingAs($this->userLocked)->getJsonWithData('Album', ['album_id' => $this->album1->id]);
$this->assertForbidden($response);
}
}