diff --git a/app/SmartAlbums/OnThisDayAlbum.php b/app/SmartAlbums/OnThisDayAlbum.php index ebb3339e9a8..4cb10e6e51d 100644 --- a/app/SmartAlbums/OnThisDayAlbum.php +++ b/app/SmartAlbums/OnThisDayAlbum.php @@ -5,6 +5,7 @@ use App\Exceptions\ConfigurationKeyMissingException; use App\Exceptions\Internal\FrameworkException; use App\Facades\Lang; +use App\Models\Configs; use Carbon\Exceptions\InvalidFormatException; use Carbon\Exceptions\InvalidTimeZoneException; use Illuminate\Database\Eloquent\Builder; @@ -28,7 +29,7 @@ protected function __construct() parent::__construct( self::ID, Lang::get('ON_THIS_DAY'), - false, + Configs::getValueAsBool('public_on_this_day'), function (Builder $query) use ($today) { $query->where(fn (Builder $q) => $q ->whereMonth('photos.taken_at', '=', $today->month) diff --git a/database/migrations/2023_01_09_133603_public_on_this_day.php b/database/migrations/2023_01_09_133603_public_on_this_day.php new file mode 100644 index 00000000000..d6f7a13490b --- /dev/null +++ b/database/migrations/2023_01_09_133603_public_on_this_day.php @@ -0,0 +1,35 @@ +insert([ + [ + 'key' => 'public_on_this_day', + 'value' => '0', + 'cat' => 'Smart Albums', + 'type_range' => '0|1', + 'confidentiality' => '0', + 'description' => 'Make "On This Day" smart album accessible to anonymous users', + ], + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + DB::table('configs')->where('key', '=', 'public_on_this_day')->delete(); + } +}; diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index edbf5037b54..df802cb966c 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -110,6 +110,7 @@ abstract class AbstractTestCase extends BaseTestCase public const CONFIG_PUBLIC_RECENT = 'public_recent'; public const CONFIG_PUBLIC_SEARCH = 'public_search'; public const CONFIG_PUBLIC_STARRED = 'public_starred'; + public const CONFIG_PUBLIC_ON_THIS_DAY = 'public_on_this_day'; public const CONFIG_RAW_FORMATS = 'raw_formats'; /** diff --git a/tests/Feature/Base/BaseSharingTest.php b/tests/Feature/Base/BaseSharingTest.php index 0addcdd15c4..0dcffaa0acf 100644 --- a/tests/Feature/Base/BaseSharingTest.php +++ b/tests/Feature/Base/BaseSharingTest.php @@ -13,6 +13,8 @@ namespace Tests\Feature\Base; use App\Models\Configs; +use Carbon\Carbon; +use Illuminate\Support\Facades\DB; use Tests\AbstractTestCase; use Tests\Feature\Lib\RootAlbumUnitTest; use Tests\Feature\Lib\SharingUnitTest; @@ -138,6 +140,9 @@ abstract class BaseSharingTest extends BasePhotoTest /** @var bool the previously configured public visibility for "Starred" */ private bool $isStarredAlbumPublic; + /** @var bool the previously configured public visibility for "On This Day" */ + private bool $isOnThisDayAlbumPublic; + public function setUp(): void { parent::setUp(); @@ -166,6 +171,8 @@ public function setUp(): void Configs::set(AbstractTestCase::CONFIG_PUBLIC_RECENT, true); $this->isStarredAlbumPublic = Configs::getValueAsBool(AbstractTestCase::CONFIG_PUBLIC_STARRED); Configs::set(AbstractTestCase::CONFIG_PUBLIC_STARRED, true); + $this->isOnThisDayAlbumPublic = Configs::getValueAsBool(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY); + Configs::set(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY, true); $this->clearCachedSmartAlbums(); } @@ -178,6 +185,7 @@ public function tearDown(): void Configs::set(AbstractTestCase::CONFIG_PUBLIC_RECENT, $this->isRecentAlbumPublic); Configs::set(AbstractTestCase::CONFIG_PUBLIC_STARRED, $this->isStarredAlbumPublic); + Configs::set(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY, $this->isOnThisDayAlbumPublic); $this->clearCachedSmartAlbums(); $this->tearDownRequiresEmptyPhotos(); @@ -238,4 +246,18 @@ protected function generateExpectedSmartAlbumJson( 'policy' => ['is_public' => $isPublic], ]; } + + protected function ensurePhotosWereTakenOnThisDay(string ...$photoIds): void + { + DB::table('photos') + ->whereIn('id', $photoIds) + ->update(['taken_at' => (Carbon::today())->subYear()->format('Y-m-d H:i:s.u')]); + } + + protected function ensurePhotosWereNotTakenOnThisDay(string ...$photoIds): void + { + DB::table('photos') + ->whereIn('id', $photoIds) + ->update(['taken_at' => (Carbon::today())->subMonth()->format('Y-m-d H:i:s.u')]); + } } diff --git a/tests/Feature/Base/BaseSharingTestScenarios.php b/tests/Feature/Base/BaseSharingTestScenarios.php index f97a6d6a81d..86adfd52439 100644 --- a/tests/Feature/Base/BaseSharingTestScenarios.php +++ b/tests/Feature/Base/BaseSharingTestScenarios.php @@ -18,6 +18,7 @@ namespace Tests\Feature\Base; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; use Illuminate\Support\Facades\Auth; @@ -108,6 +109,7 @@ abstract protected function generateExpectedRootJson( ?string $starredAlbumThumbID = null, ?string $publicAlbumThumbID = null, ?string $recentAlbumThumbID = null, + ?string $onThisDayAlbumThumbID = null, array $expectedAlbumJson = [] ): array; @@ -151,6 +153,10 @@ public function testUnsortedPrivatePhoto(): void $responseForStarred->assertJson($this->generateExpectedSmartAlbumJson(true)); $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $this->photos_tests->get($this->photoID1, $this->getExpectedInaccessibleHttpStatusCode()); } @@ -235,16 +241,19 @@ public function testTwoPhotosInPublicAlbum(): void { $this->prepareTwoPhotosInPublicAlbum(); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID1); + $this->ensurePhotosWereTakenOnThisDay($this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, $this->photoID1, null, - $this->photoID1, [ + $this->photoID1, + $this->photoID2, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), // photo 1 is thumb, because starred photo are always picked first ]) ); - $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); $responseForRecent = $this->albums_tests->get(RecentAlbum::ID); $responseForRecent->assertJson($this->generateExpectedSmartAlbumJson( @@ -264,6 +273,15 @@ public function testTwoPhotosInPublicAlbum(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID2, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), // photo 1 is thumb, because starred photo are always picked first @@ -333,11 +351,14 @@ public function testPublicAlbumAndPasswordProtectedAlbum(): void { $this->preparePublicAlbumAndPasswordProtectedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID2, $this->photoID2, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1), // album 1 is in password protected, still locked album $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), @@ -354,6 +375,15 @@ public function testPublicAlbumAndPasswordProtectedAlbum(): void )); $responseForRecent->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForStarred = $this->albums_tests->get(StarredAlbum::ID); $responseForStarred->assertJson($this->generateExpectedSmartAlbumJson(true)); $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); @@ -385,6 +415,10 @@ public function testPublicAlbumAndPasswordProtectedAlbum(): void public function testPublicAlbumAndPasswordProtectedUnlockedAlbum(): void { $this->preparePublicAlbumAndPasswordProtectedAlbum(); + + $this->ensurePhotosWereTakenOnThisDay($this->photoID2); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID1); + $this->albums_tests->unlock($this->albumID1, self::ALBUM_PWD_1); $responseForRoot = $this->root_album_tests->get(); @@ -392,7 +426,8 @@ public function testPublicAlbumAndPasswordProtectedUnlockedAlbum(): void null, null, null, - $this->photoID1, [ // album 1 is unlocked, and photo 1 is alphabetically first + $this->photoID1, + $this->photoID2, [ // album 1 is unlocked, and photo 1 is alphabetically first $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), ] @@ -407,6 +442,15 @@ public function testPublicAlbumAndPasswordProtectedUnlockedAlbum(): void ] )); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ // photo 2 was taken on this day + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForStarred = $this->albums_tests->get(StarredAlbum::ID); $responseForStarred->assertJson($this->generateExpectedSmartAlbumJson(true)); $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); @@ -468,11 +512,14 @@ public function testPublicAlbumAndPasswordProtectedAlbumWithStarredPhoto(): void { $this->preparePublicAlbumAndPasswordProtectedAlbumWithStarredPhoto(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID2, $this->photoID2, [ // album 1 is password protected, hence photo 2 is the thumb $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1), // album 1 is in password protected, still locked album $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), @@ -494,6 +541,15 @@ public function testPublicAlbumAndPasswordProtectedAlbumWithStarredPhoto(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $this->albums_tests->get($this->albumID1, $this->getExpectedInaccessibleHttpStatusCode(), self::EXPECTED_PASSWORD_REQUIRED_MSG, $this->getExpectedDefaultInaccessibleMessage()); $this->photos_tests->get($this->photoID1, $this->getExpectedInaccessibleHttpStatusCode()); @@ -522,12 +578,15 @@ public function testPublicAlbumAndPasswordProtectedUnlockedAlbumWithStarredPhoto $this->preparePublicAlbumAndPasswordProtectedAlbumWithStarredPhoto(); $this->albums_tests->unlock($this->albumID1, self::ALBUM_PWD_1); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, $this->photoID1, // album 1 is unlocked, and photo 1 is alphabetically first null, - $this->photoID1, [ // album 1 is unlocked, and photo 1 is alphabetically first + $this->photoID1, + null, [ // album 1 is unlocked, and photo 1 is alphabetically first $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), ] @@ -551,6 +610,11 @@ public function testPublicAlbumAndPasswordProtectedUnlockedAlbumWithStarredPhoto )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForAlbum1 = $this->albums_tests->get($this->albumID1); $responseForAlbum1->assertJson([ 'id' => $this->albumID1, @@ -608,11 +672,14 @@ public function testPublicAlbumAndHiddenAlbum(): void { $this->preparePublicAlbumAndHiddenAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID1, $this->photoID1, [ // album 2 is hidden $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), ] @@ -634,6 +701,14 @@ public function testPublicAlbumAndHiddenAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ])); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForAlbum1 = $this->albums_tests->get($this->albumID1); $responseForAlbum1->assertJson([ 'id' => $this->albumID1, @@ -690,11 +765,14 @@ public function testPublicAlbumAndHiddenPasswordProtectedAlbum(): void { $this->preparePublicAlbumAndHiddenPasswordProtectedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID1, $this->photoID1, [ // album 2 is hidden $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), ] @@ -716,6 +794,15 @@ public function testPublicAlbumAndHiddenPasswordProtectedAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForAlbum1 = $this->albums_tests->get($this->albumID1); $responseForAlbum1->assertJson([ 'id' => $this->albumID1, @@ -741,6 +828,9 @@ public function testPublicAlbumAndHiddenPasswordProtectedAlbum(): void public function testPublicAlbumAndHiddenPasswordProtectedUnlockedAlbum(): void { $this->preparePublicAlbumAndHiddenPasswordProtectedAlbum(); + + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $this->albums_tests->unlock($this->albumID2, self::ALBUM_PWD_2); $responseForRoot = $this->root_album_tests->get(); @@ -748,6 +838,7 @@ public function testPublicAlbumAndHiddenPasswordProtectedUnlockedAlbum(): void null, null, null, + $this->photoID1, $this->photoID1, [ // album 2 is hidden $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), ] @@ -769,6 +860,15 @@ public function testPublicAlbumAndHiddenPasswordProtectedUnlockedAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForAlbum1 = $this->albums_tests->get($this->albumID1); $responseForAlbum1->assertJson([ 'id' => $this->albumID1, @@ -852,11 +952,14 @@ public function testPhotoInSharedPublicPasswordProtectedUnlockedAlbum(): void $this->preparePhotoInSharedPublicPasswordProtectedAlbum(); $this->albums_tests->unlock($this->albumID1, self::ALBUM_PWD_1); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID1, $this->photoID1, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), ] @@ -875,6 +978,14 @@ public function testPhotoInSharedPublicPasswordProtectedUnlockedAlbum(): void ] )); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), diff --git a/tests/Feature/Base/BaseSharingWithAnonUser.php b/tests/Feature/Base/BaseSharingWithAnonUser.php index 3382d5fbb18..94ee7eca6f4 100644 --- a/tests/Feature/Base/BaseSharingWithAnonUser.php +++ b/tests/Feature/Base/BaseSharingWithAnonUser.php @@ -12,6 +12,7 @@ namespace Tests\Feature\Base; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\PublicAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; @@ -28,6 +29,8 @@ public function testPhotosInSharedAndPrivateAlbum(): void { $this->preparePhotosInSharedAndPrivateAndRequireLinkAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2, $this->photoID3); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->albumID1]); @@ -55,6 +58,12 @@ public function testPhotosInSharedAndPrivateAlbum(): void $responseForRecent->assertJsonMissing(['id' => $this->albumID3]); $responseForRecent->assertJsonMissing(['id' => $this->photoID3]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -74,11 +83,14 @@ public function testPhotoInSharedPublicPasswordProtectedAlbum(): void { $this->preparePhotoInSharedPublicPasswordProtectedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + null, null, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1), ] @@ -95,6 +107,10 @@ public function testPhotoInSharedPublicPasswordProtectedAlbum(): void $responseForRecent->assertJsonMissing(['id' => $this->albumID1]); $responseForRecent->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -108,11 +124,14 @@ public function testThreeAlbumsWithMixedSharingAndPasswordProtection(): void { $this->prepareThreeAlbumsWithMixedSharingAndPasswordProtection(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2, $this->photoID3); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + null, null, [ $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2), $this->generateExpectedAlbumJson($this->albumID3, self::ALBUM_TITLE_3), @@ -141,6 +160,12 @@ public function testThreeAlbumsWithMixedSharingAndPasswordProtection(): void $responseForRecent->assertJsonMissing(['id' => $this->albumID3]); $responseForRecent->assertJsonMissing(['id' => $this->photoID3]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + // TODO: Should public and password-protected albums appear in tree? Regression? $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); @@ -164,15 +189,20 @@ public function testThreeUnlockedAlbumsWithMixedSharingAndPasswordProtection(): $this->prepareThreeAlbumsWithMixedSharingAndPasswordProtection(); $this->albums_tests->unlock($this->albumID3, self::ALBUM_PWD_1); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID3); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, - $this->photoID3, [ // photo 3 is alphabetically first + $this->photoID3, + $this->photoID2, + [ // photo 3 is alphabetically first $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), $this->generateExpectedAlbumJson($this->albumID3, self::ALBUM_TITLE_3, null, $this->photoID3), - ] + ], )); $responseForRoot->assertJsonMissing(['id' => $this->albumID1]); $responseForRoot->assertJsonMissing(['id' => $this->photoID1]); @@ -197,6 +227,16 @@ public function testThreeUnlockedAlbumsWithMixedSharingAndPasswordProtection(): $responseForRecent->assertJsonMissing(['id' => $this->albumID1]); $responseForRecent->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ // photo 2 was taken on this day + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), @@ -224,6 +264,7 @@ protected function generateExpectedRootJson( ?string $starredAlbumThumbID = null, ?string $publicAlbumThumbID = null, ?string $recentAlbumThumbID = null, + ?string $onThisDayAlbumThumbID = null, array $expectedAlbumJson = [] ): array { if ($unsortedAlbumThumbID !== null) { @@ -239,6 +280,7 @@ protected function generateExpectedRootJson( StarredAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($starredAlbumThumbID)], PublicAlbum::ID => null, RecentAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($recentAlbumThumbID)], + OnThisDayAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($onThisDayAlbumThumbID)], ], 'tag_albums' => [], 'albums' => $expectedAlbumJson, diff --git a/tests/Feature/Base/BaseSharingWithNonAdminUser.php b/tests/Feature/Base/BaseSharingWithNonAdminUser.php index 82a81c997d6..1722c702421 100644 --- a/tests/Feature/Base/BaseSharingWithNonAdminUser.php +++ b/tests/Feature/Base/BaseSharingWithNonAdminUser.php @@ -12,6 +12,7 @@ namespace Tests\Feature\Base; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\PublicAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; @@ -54,12 +55,16 @@ public function testPhotosInSharedAndPrivateAlbum(): void { $this->preparePhotosInSharedAndPrivateAndRequireLinkAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID3); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, - $this->photoID3, [ + $this->photoID3, + $this->photoID1, [ self::generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), self::generateExpectedAlbumJson($this->albumID3, self::ALBUM_TITLE_3, null, $this->photoID3), ] @@ -85,6 +90,16 @@ public function testPhotosInSharedAndPrivateAlbum(): void $responseForRecent->assertJsonMissing(['id' => $this->albumID2]); $responseForRecent->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ self::generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), @@ -113,11 +128,14 @@ public function testPhotoInSharedPublicPasswordProtectedAlbum(): void { $this->preparePhotoInSharedPublicPasswordProtectedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, + $this->photoID1, $this->photoID1, [ self::generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), ] @@ -136,6 +154,14 @@ public function testPhotoInSharedPublicPasswordProtectedAlbum(): void ] )); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ self::generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), @@ -152,12 +178,16 @@ public function testThreeAlbumsWithMixedSharingAndPasswordProtection(): void { $this->prepareThreeAlbumsWithMixedSharingAndPasswordProtection(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID2, $this->photoID3); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID1); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, $this->photoID1, // photo 1 is alphabetically first, as photo 3 is locked + $this->photoID2, // photo 1 was not taken on this day and photo 3 is locked [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), @@ -186,6 +216,16 @@ public function testThreeAlbumsWithMixedSharingAndPasswordProtection(): void $responseForRecent->assertJsonMissing(['id' => $this->albumID3]); $responseForRecent->assertJsonMissing(['id' => $this->photoID3]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + // TODO: Should public and password-protected albums appear in tree? Regression? $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ @@ -214,12 +254,17 @@ public function testThreeUnlockedAlbumsWithMixedSharingAndPasswordProtection(): $this->prepareThreeAlbumsWithMixedSharingAndPasswordProtection(); $this->albums_tests->unlock($this->albumID3, self::ALBUM_PWD_1); + $this->ensurePhotosWereTakenOnThisDay($this->photoID2); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID1, $this->photoID3); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, null, null, - $this->photoID3, [ // photo 3 is alphabetically first + $this->photoID3, // photo 3 is alphabetically first + $this->photoID2, // photo 2 was taken on this day + [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), $this->generateExpectedAlbumJson($this->albumID2, self::ALBUM_TITLE_2, null, $this->photoID2), $this->generateExpectedAlbumJson($this->albumID3, self::ALBUM_TITLE_3, null, $this->photoID3), @@ -245,6 +290,16 @@ public function testThreeUnlockedAlbumsWithMixedSharingAndPasswordProtection(): ] )); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID2, $this->albumID2), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID3]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID1), @@ -274,6 +329,7 @@ protected function generateExpectedRootJson( ?string $starredAlbumThumbID = null, ?string $publicAlbumThumbID = null, ?string $recentAlbumThumbID = null, + ?string $onThisDayAlbumThumbID = null, array $expectedAlbumJson = [] ): array { return [ @@ -282,6 +338,7 @@ protected function generateExpectedRootJson( StarredAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($starredAlbumThumbID)], PublicAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($publicAlbumThumbID)], RecentAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($recentAlbumThumbID)], + OnThisDayAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($onThisDayAlbumThumbID)], ], 'tag_albums' => [], 'albums' => [], diff --git a/tests/Feature/SharingSpecialTest.php b/tests/Feature/SharingSpecialTest.php index b72c9432f81..e290d931f17 100644 --- a/tests/Feature/SharingSpecialTest.php +++ b/tests/Feature/SharingSpecialTest.php @@ -13,6 +13,7 @@ namespace Tests\Feature; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\PublicAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; @@ -111,6 +112,9 @@ protected function prepareSixAlbumsWithDifferentProtectionSettings(): void $this->photos_tests->set_title($this->photoID5, 'Abenddämmerung'); // we rename the duplicated images, such that we can ensure $this->photos_tests->set_title($this->photoID6, 'Zug'); // a deterministic, alphabetic order which makes testing easier + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID5); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID2, $this->photoID3, $this->photoID4, $this->photoID6); + $this->albums_tests->set_protection_policy(id: $this->albumID1, password: self::ALBUM_PWD_1); $this->albums_tests->set_protection_policy(id: $this->albumID2); $this->albums_tests->set_protection_policy(id: $this->albumID3, password: self::ALBUM_PWD_1); @@ -132,7 +136,7 @@ protected function prepareSixAlbumsWithDifferentProtectionSettings(): void * * - The root album shows album 1 but without a cover as album 1 is still * locked. - * - The smart album Recent is empty + * - The smart albums "Recent" and "On This Day" are empty * - The album tree does is empty * (TODO: Check if we want it this way) * - Album 2 and photo 2 are accessible; album 2 is public and behaves @@ -150,7 +154,9 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllLocked(): void $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - null, [ + null, + null, + [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1), // no thumb as album 1 is still locked ] )); @@ -170,7 +176,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllLocked(): void $responseForRoot->assertJsonMissing(['id' => $id]); } - // 2. Check Recent album + // 2. Check "Recent" and "On This Day" albums $responseForRecent = $this->albums_tests->get(RecentAlbum::ID); $responseForRecent->assertJson($this->generateExpectedSmartAlbumJson(true)); @@ -191,6 +197,19 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllLocked(): void $responseForRecent->assertJsonMissing(['id' => $id]); } + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + foreach ([ + $this->photoID1, + $this->photoID2, + $this->photoID3, + $this->photoID4, + $this->photoID5, + $this->photoID6, + ] as $id) { + $responseForOnThisDay->assertJsonMissing(['id' => $id]); + } + // 3. Check tree $responseForTree = $this->root_album_tests->getTree(); @@ -255,6 +274,8 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllLocked(): void * - The smart album Recent shows photos 1-3; in particular photo 4 * is not shown although it has been unlocked, too, but it is part of a * hidden album + * - The smart album "On This Day" shows photo 1, since only photo 1 is + * accessible and taken on this day * - The album tree shows album 1-3; it does not show album 5 as it is * password-protected and still locked * (TODO: Check if we want it this way) @@ -272,12 +293,12 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndSomeUnlocked(): v $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - $this->photoID3, [ // albums 1-3 are accessible, photo 3 is alphabetically first + $this->photoID3, + $this->photoID1, [ // albums 1-3 are accessible, photo 3 is alphabetically first $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID3), // thumb available as album 1 has been unlocked ] )); foreach ([ - $this->photoID1, $this->albumID2, $this->photoID2, $this->albumID3, @@ -291,7 +312,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndSomeUnlocked(): v $responseForRoot->assertJsonMissing(['id' => $id]); } - // 2. Check Recent album + // 2. Check "Recent" and "On This Day" albums $responseForRecent = $this->albums_tests->get(RecentAlbum::ID); $responseForRecent->assertJson($this->generateExpectedSmartAlbumJson( @@ -306,6 +327,17 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndSomeUnlocked(): v $responseForRecent->assertJsonMissing(['id' => $id]); } + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_NIGHT_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + foreach ([$this->photoID2, $this->photoID3, $this->photoID4, $this->photoID5, $this->photoID6] as $id) { + $responseForOnThisDay->assertJsonMissing(['id' => $id]); + } + // 3. Check tree $responseForTree = $this->root_album_tests->getTree(); @@ -374,6 +406,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndSomeUnlocked(): v * - The smart album Recent shows photos 1-3+5; in particular photo 4+6 * are not shown, although they have been unlocked, too, but they are * part of hidden albums + * - Smart album "On This Day" shows photos 1 and 5 that were taken on this day * - The album tree shows album 1-3+5 * - Albums 1-6 and photos 1-6 are accessible * @@ -389,6 +422,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllUnlocked(): vo $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( + $this->photoID5, $this->photoID5, [ // albums 1-6 are accessible, photo 5 is alphabetically first $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID5), // thumb available as album 1 has been unlocked ] @@ -397,7 +431,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllUnlocked(): vo $responseForRoot->assertJsonMissing(['id' => $id]); } - // 2. Check Recent album + // 2. Check "Recent" and "On This Day" albums $responseForRecent = $this->albums_tests->get(RecentAlbum::ID); $responseForRecent->assertJson($this->generateExpectedSmartAlbumJson( @@ -413,6 +447,18 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllUnlocked(): vo $responseForRecent->assertJsonMissing(['id' => $id]); } + $responseForOnThisDayAlbum = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDayAlbum->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID5, [ // photos 1 and 5 were taken on this day and accessible, photo 5 is alphabetically first + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_SUNSET_IMAGE, $this->photoID5, $this->albumID5, ['title' => 'Abenddämmerung']), + $this->generateExpectedPhotoJson(self::SAMPLE_FILE_NIGHT_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + foreach ([$this->photoID2, $this->photoID3, $this->photoID4, $this->photoID6] as $id) { + $responseForOnThisDayAlbum->assertJsonMissing(['id' => $id]); + } + // 3. Check tree $responseForTree = $this->root_album_tests->getTree(); @@ -470,6 +516,7 @@ public function testSixAlbumsWithDifferentProtectionSettingsAndAllUnlocked(): vo protected function generateExpectedRootJson( ?string $recentAlbumThumbID = null, + ?string $onThisDayAlbumThumbID = null, array $expectedAlbumJson = [] ): array { return [ @@ -478,6 +525,7 @@ protected function generateExpectedRootJson( StarredAlbum::ID => ['thumb' => null], PublicAlbum::ID => null, RecentAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($recentAlbumThumbID)], + OnThisDayAlbum::ID => ['thumb' => $this->generateExpectedThumbJson($onThisDayAlbumThumbID)], ], 'tag_albums' => [], 'albums' => $expectedAlbumJson, diff --git a/tests/Feature/SharingWithAnonUserAndNoPublicSearchTest.php b/tests/Feature/SharingWithAnonUserAndNoPublicSearchTest.php index daeaafa886f..44ec5eb3991 100644 --- a/tests/Feature/SharingWithAnonUserAndNoPublicSearchTest.php +++ b/tests/Feature/SharingWithAnonUserAndNoPublicSearchTest.php @@ -13,6 +13,7 @@ namespace Tests\Feature; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; use Tests\AbstractTestCase; @@ -28,7 +29,7 @@ public function setUp(): void /** * Ensures that the user does not see the unsorted public photos as covers nor - * inside "Recent" and "Favorites" (as public search is disabled). + * inside "Recent", "On This Day" and "Favorites" (as public search is disabled). * The user can access the public photo nonetheless, but gets * "401 - Unauthenticated" for the other. * @@ -42,6 +43,8 @@ public function testUnsortedPublicAndPrivatePhoto(): void { $this->prepareUnsortedPublicAndPrivatePhoto(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->photoID1]); @@ -57,6 +60,11 @@ public function testUnsortedPublicAndPrivatePhoto(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + // Even though the public photo is not searchable and hence does not // show up in the smart albums, it can be fetched directly $this->photos_tests->get($this->photoID1); @@ -77,6 +85,8 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void { $this->preparePublicAndPrivatePhotoInPrivateAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->photoID1]); @@ -92,6 +102,11 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -110,6 +125,8 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void { $this->preparePublicUnsortedPhotoAndPhotoInSharedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->albumID1]); @@ -126,6 +143,11 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->photoID2]); diff --git a/tests/Feature/SharingWithAnonUserAndPublicSearchTest.php b/tests/Feature/SharingWithAnonUserAndPublicSearchTest.php index 4a90799b9ad..3da6c7436f7 100644 --- a/tests/Feature/SharingWithAnonUserAndPublicSearchTest.php +++ b/tests/Feature/SharingWithAnonUserAndPublicSearchTest.php @@ -13,6 +13,7 @@ namespace Tests\Feature; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; use Tests\AbstractTestCase; @@ -28,7 +29,7 @@ public function setUp(): void /** * Ensures that the user sees the unsorted public photos as the - * cover and inside "Recent" and "Favorites" (as public search is + * cover and inside "Recent", "On This Day" and "Favorites" (as public search is * enabled), but not the other photo. * The user can access the public photo, but gets * "401 - Unauthenticated" for the other. @@ -42,9 +43,11 @@ public function testUnsortedPublicAndPrivatePhoto(): void { $this->prepareUnsortedPublicAndPrivatePhoto(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - null, $this->photoID1, null, $this->photoID1 + null, $this->photoID1, null, $this->photoID1, $this->photoID1 )); $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); @@ -66,6 +69,15 @@ public function testUnsortedPublicAndPrivatePhoto(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, null), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $this->photos_tests->get($this->photoID1); $this->photos_tests->get($this->photoID2, $this->getExpectedInaccessibleHttpStatusCode()); } @@ -83,9 +95,11 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void { $this->preparePublicAndPrivatePhotoInPrivateAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - null, $this->photoID1, null, $this->photoID1 + null, $this->photoID1, null, $this->photoID1, $this->photoID1 )); $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); @@ -107,6 +121,15 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -122,9 +145,11 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void { $this->preparePublicUnsortedPhotoAndPhotoInSharedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - null, $this->photoID1, null, $this->photoID1 + null, $this->photoID1, null, $this->photoID1, $this->photoID1 )); $responseForRoot->assertJsonMissing(['id' => $this->albumID1]); $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); @@ -147,6 +172,15 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, null), + ], + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->photoID2]); diff --git a/tests/Feature/SharingWithNonAdminUserAndNoPublicSearchTest.php b/tests/Feature/SharingWithNonAdminUserAndNoPublicSearchTest.php index 4288f17a185..41a4a337479 100644 --- a/tests/Feature/SharingWithNonAdminUserAndNoPublicSearchTest.php +++ b/tests/Feature/SharingWithNonAdminUserAndNoPublicSearchTest.php @@ -13,6 +13,7 @@ namespace Tests\Feature; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; use App\SmartAlbums\UnsortedAlbum; @@ -29,7 +30,7 @@ public function setUp(): void /** * Ensures that the user does not the unsorted public photos as covers nor - * inside "Recent" and "Favorites" (as public search is disabled). + * inside "Recent", "On This Day" and "Favorites" (as public search is disabled). * The user can access the public photo nonetheless, but gets * "403 - Forbidden" for the other. * @@ -42,6 +43,8 @@ public function testUnsortedPublicAndPrivatePhoto(): void { $this->prepareUnsortedPublicAndPrivatePhoto(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->photoID1]); @@ -62,6 +65,11 @@ public function testUnsortedPublicAndPrivatePhoto(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + // Even though the public photo is not searchable and hence does not // show up in the smart albums, it can be fetched directly $this->photos_tests->get($this->photoID1); @@ -82,6 +90,8 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void { $this->preparePublicAndPrivatePhotoInPrivateAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson()); $responseForRoot->assertJsonMissing(['id' => $this->photoID1]); @@ -102,6 +112,11 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true)); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -119,11 +134,14 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void { $this->preparePublicUnsortedPhotoAndPhotoInSharedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( null, $this->photoID2, null, + $this->photoID2, $this->photoID2, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID2), ] @@ -142,7 +160,7 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void $this->generateExpectedPhotoJson(static::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID2, $this->albumID1), ] )); - $responseForUnsorted->assertJsonMissing(['id' => $this->photoID2]); + $responseForRecent->assertJsonMissing(['id' => $this->photoID1]); $responseForStarred = $this->albums_tests->get(StarredAlbum::ID); $responseForStarred->assertJson($this->generateExpectedSmartAlbumJson( @@ -153,6 +171,14 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID1]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson(true, + $this->photoID2, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_MONGOLIA_IMAGE, $this->photoID2, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID1]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID2), diff --git a/tests/Feature/SharingWithNonAdminUserAndPublicSearchTest.php b/tests/Feature/SharingWithNonAdminUserAndPublicSearchTest.php index 8273b34e384..3f107de6833 100644 --- a/tests/Feature/SharingWithNonAdminUserAndPublicSearchTest.php +++ b/tests/Feature/SharingWithNonAdminUserAndPublicSearchTest.php @@ -13,6 +13,7 @@ namespace Tests\Feature; use App\Models\Configs; +use App\SmartAlbums\OnThisDayAlbum; use App\SmartAlbums\RecentAlbum; use App\SmartAlbums\StarredAlbum; use App\SmartAlbums\UnsortedAlbum; @@ -29,7 +30,7 @@ public function setUp(): void /** * Ensures that the user sees the unsorted public photos as the - * cover and inside "Recent" and "Favorites" (as public search is + * cover and inside "Recent", "On This Day" and "Favorites" (as public search is * enabled), but not the other photo. * The user can access the public photo, but gets * "403 - Forbidden" for the other. @@ -43,9 +44,11 @@ public function testUnsortedPublicAndPrivatePhoto(): void { $this->prepareUnsortedPublicAndPrivatePhoto(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - $this->photoID1, $this->photoID1, $this->photoID1, $this->photoID1 + $this->photoID1, $this->photoID1, $this->photoID1, $this->photoID1, $this->photoID1 )); $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); @@ -79,6 +82,16 @@ public function testUnsortedPublicAndPrivatePhoto(): void $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); $responseForStarred->assertJsonMissing(['title' => self::PHOTO_MONGOLIA_TITLE]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, null), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay->assertJsonMissing(['title' => self::PHOTO_MONGOLIA_TITLE]); + $this->photos_tests->get($this->photoID1); $this->photos_tests->get($this->photoID2, $this->getExpectedInaccessibleHttpStatusCode()); } @@ -96,9 +109,11 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void { $this->preparePublicAndPrivatePhotoInPrivateAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1, $this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( - null, $this->photoID1, $this->photoID1, $this->photoID1 + null, $this->photoID1, $this->photoID1, $this->photoID1, $this->photoID1 )); $responseForRoot->assertJsonMissing(['id' => $this->photoID2]); @@ -120,6 +135,15 @@ public function testPublicAndPrivatePhotoInPrivateAlbum(): void )); $responseForStarred->assertJsonMissing(['id' => $this->photoID2]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson($this->generateExpectedSmartAlbumJson( + true, + $this->photoID1, [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, $this->albumID1), + ] + )); + $responseForOnThisDay->assertJsonMissing(['id' => $this->photoID2]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson()); $responseForTree->assertJsonMissing(['id' => $this->albumID1]); @@ -135,12 +159,16 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void { $this->preparePublicUnsortedPhotoAndPhotoInSharedAlbum(); + $this->ensurePhotosWereTakenOnThisDay($this->photoID1); + $this->ensurePhotosWereNotTakenOnThisDay($this->photoID2); + $responseForRoot = $this->root_album_tests->get(); $responseForRoot->assertJson($this->generateExpectedRootJson( $this->photoID1, $this->photoID2, $this->photoID1, - $this->photoID2, [ + $this->photoID2, + $this->photoID1, [ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID2), ] )); @@ -173,6 +201,15 @@ public function testPublicUnsortedPhotoAndPhotoInSharedAlbum(): void ], ]); + $responseForOnThisDay = $this->albums_tests->get(OnThisDayAlbum::ID); + $responseForOnThisDay->assertJson([ + 'policy' => ['is_public' => true], + 'thumb' => $this->generateExpectedThumbJson($this->photoID1), + 'photos' => [ + $this->generateExpectedPhotoJson(static::SAMPLE_FILE_TRAIN_IMAGE, $this->photoID1, null), + ], + ]); + $responseForTree = $this->root_album_tests->getTree(); $responseForTree->assertJson($this->generateExpectedTreeJson([ $this->generateExpectedAlbumJson($this->albumID1, self::ALBUM_TITLE_1, null, $this->photoID2),