-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathBaseApiWithDataTest.php
More file actions
186 lines (155 loc) · 6.44 KB
/
BaseApiWithDataTest.php
File metadata and controls
186 lines (155 loc) · 6.44 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?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\Base;
use App\Enum\UserGroupRole;
use App\Models\AccessPermission;
use App\Models\Album;
use App\Models\Configs;
use App\Models\Palette;
use App\Models\Photo;
use App\Models\TagAlbum;
use App\Models\User;
use App\Models\UserGroup;
use Tests\Traits\InteractWithSmartAlbums;
use Tests\Traits\RequiresEmptyAlbums;
use Tests\Traits\RequiresEmptyColourPalettes;
use Tests\Traits\RequiresEmptyGroups;
use Tests\Traits\RequiresEmptyLiveMetrics;
use Tests\Traits\RequiresEmptyPhotos;
use Tests\Traits\RequiresEmptyUsers;
use Tests\Traits\RequiresEmptyWebAuthnCredentials;
abstract class BaseApiWithDataTest extends BaseApiTest
{
use RequiresEmptyUsers;
use RequiresEmptyAlbums;
use RequiresEmptyPhotos;
use RequiresEmptyColourPalettes;
use RequiresEmptyLiveMetrics;
use RequiresEmptyWebAuthnCredentials;
use InteractWithSmartAlbums;
use RequiresEmptyGroups;
protected User $admin;
protected User $userMayUpload1;
protected User $userMayUpload2;
protected User $userNoUpload;
protected User $userLocked;
// album 1 belongs to userMayUpload1
protected Album $album1;
protected Album $subAlbum1;
protected TagAlbum $tagAlbum1;
protected Photo $photo1;
protected Photo $photo1b;
protected Photo $subPhoto1;
protected Photo $photoUnsorted;
protected Palette $palette1;
// album 2 belongs to userMayUpload2
protected Album $album2;
protected Album $subAlbum2;
protected Photo $photo2;
protected Photo $subPhoto2;
// album 3 belongs to userNoUpload
protected Album $album3;
protected Photo $photo3;
// album 4 belongs to userLocked
// album 4 is visible without being logged in
protected Album $album4;
protected Album $subAlbum4;
protected Photo $photo4;
protected Photo $subPhoto4;
// album 5 belongs to admin and is empty
protected Album $album5;
protected AccessPermission $perm1;
protected AccessPermission $perm4;
protected AccessPermission $perm44;
protected AccessPermission $perm11;
protected UserGroup $group1;
protected UserGroup $group2;
protected User $userWithGroupAdmin;
protected User $userWithGroup1;
public function setUp(): void
{
parent::setUp();
$this->setUpRequiresEmptyUsers();
$this->setUpRequiresEmptyAlbums();
$this->setUpRequiresEmptyPhotos();
$this->setUpRequiresEmptyColourPalettes();
$this->setUpRequiresEmptyLiveMetrics();
$this->setUpRequiresEmptyGroups();
$this->admin = User::factory()->may_administrate()->create();
$this->userMayUpload1 = User::factory()->may_upload()->create();
$this->userMayUpload2 = User::factory()->may_upload()->create();
$this->userNoUpload = User::factory()->create();
$this->userLocked = User::factory()->locked()->create();
$this->group1 = UserGroup::factory()->create();
$this->group2 = UserGroup::factory()->create();
$this->userWithGroup1 = User::factory()->with_group($this->group1)->create();
$this->userWithGroupAdmin = User::factory()->with_group($this->group1, UserGroupRole::ADMIN)->create();
$this->album1 = Album::factory()->as_root()->owned_by($this->userMayUpload1)->create();
$this->photo1 = Photo::factory()->owned_by($this->userMayUpload1)->with_GPS_coordinates()->with_tags('test')->with_palette()->in($this->album1)->create();
$this->palette1 = $this->photo1->palette;
$this->photo1b = Photo::factory()->owned_by($this->userMayUpload1)->with_subGPS_coordinates()->in($this->album1)->create();
$this->subAlbum1 = Album::factory()->children_of($this->album1)->owned_by($this->userMayUpload1)->create();
$this->subPhoto1 = Photo::factory()->owned_by($this->userMayUpload1)->with_GPS_coordinates()->in($this->subAlbum1)->create();
$this->tagAlbum1 = TagAlbum::factory()->owned_by($this->userMayUpload1)->of_tags('test')->create();
$this->album2 = Album::factory()->as_root()->owned_by($this->userMayUpload2)->create();
$this->photo2 = Photo::factory()->owned_by($this->userMayUpload2)->with_GPS_coordinates()->in($this->album2)->create();
$this->subAlbum2 = Album::factory()->children_of($this->album2)->owned_by($this->userMayUpload2)->create();
$this->subPhoto2 = Photo::factory()->owned_by($this->userMayUpload2)->with_GPS_coordinates()->in($this->subAlbum2)->create();
$this->photoUnsorted = Photo::factory()->owned_by($this->userMayUpload1)->with_GPS_coordinates()->create();
$this->album3 = Album::factory()->as_root()->owned_by($this->userNoUpload)->create();
$this->photo3 = Photo::factory()->owned_by($this->userNoUpload)->with_GPS_coordinates()->in($this->album3)->create();
$this->album4 = Album::factory()->as_root()->owned_by($this->userLocked)->create();
$this->photo4 = Photo::factory()->owned_by($this->userLocked)->with_GPS_coordinates()->in($this->album4)->create();
$this->subAlbum4 = Album::factory()->children_of($this->album4)->owned_by($this->userLocked)->create();
$this->subPhoto4 = Photo::factory()->owned_by($this->userLocked)->with_GPS_coordinates()->in($this->subAlbum4)->create();
$this->perm4 = AccessPermission::factory()->public()->visible()->for_album($this->album4)->create();
$this->perm44 = AccessPermission::factory()->public()->visible()->for_album($this->subAlbum4)->create();
$this->perm1 = AccessPermission::factory()
->for_user($this->userMayUpload2)
->for_album($this->album1)
->visible()
->grants_edit()
->grants_delete()
->grants_upload()
->grants_download()
->grants_full_photo()
->create();
$this->perm11 = AccessPermission::factory()
->for_user_group($this->group1)
->for_album($this->album1)
->visible()
->grants_edit()
->grants_delete()
->grants_upload()
->grants_download()
->grants_full_photo()
->create();
$this->album5 = Album::factory()->as_root()->owned_by($this->admin)->create();
Configs::set('owner_id', $this->admin->id);
$this->withoutVite();
$this->clearCachedSmartAlbums();
}
public function tearDown(): void
{
$this->tearDownRequiresEmptyLiveMetrics();
$this->tearDownRequiresEmptyColourPalettes();
$this->tearDownRequiresEmptyPhotos();
$this->tearDownRequiresEmptyAlbums();
$this->tearDownRequiresEmptyUsers();
$this->tearDownRequiresEmptyGroups();
parent::tearDown();
}
}