1919namespace Tests \Feature_v2 ;
2020
2121use App \Models \Configs ;
22+ use App \Models \Photo ;
2223use App \Repositories \ConfigManager ;
2324use Exception ;
2425use Tests \Feature_v2 \Base \BaseApiWithDataTest ;
@@ -66,4 +67,42 @@ public function testRSS1(): void
6667 Configs::set ('rss_enable ' , $ init_config_value );
6768 }
6869 }
70+
71+ /**
72+ * A single photo (one row in `photos`) that belongs to two albums (two rows
73+ * in `photo_album`) must appear exactly once per album in the RSS feed.
74+ */
75+ public function testRSSPhotoInMultipleAlbumsIsNotDuplicated (): void
76+ {
77+ $ config_manager = resolve (ConfigManager::class);
78+ $ init_config_value = $ config_manager ->getValue ('rss_enable ' );
79+
80+ try {
81+ Configs::set ('rss_enable ' , '1 ' );
82+
83+ // One photo, two album memberships.
84+ $ photo = Photo::factory ()
85+ ->owned_by ($ this ->admin )
86+ ->in ($ this ->album1 )
87+ ->create ();
88+ $ photo ->albums ()->attach ($ this ->album2 ->id );
89+
90+ $ response = $ this ->actingAs ($ this ->admin )->get ('/feed ' );
91+ $ this ->assertOk ($ response );
92+ $ content = $ response ->getContent ();
93+
94+ // `<guid>` is rendered exactly once per feed item, so it is a reliable
95+ // per-item marker (the page link itself also appears in `<link>`).
96+ $ guid_album1 = '<guid> ' . route ('gallery ' , ['albumId ' => $ this ->album1 ->id , 'photoId ' => $ photo ->id ]) . '</guid> ' ;
97+ $ guid_album2 = '<guid> ' . route ('gallery ' , ['albumId ' => $ this ->album2 ->id , 'photoId ' => $ photo ->id ]) . '</guid> ' ;
98+
99+ // The photo is in two albums, so it must appear exactly once per album.
100+ $ this ->assertSame (1 , substr_count ($ content , $ guid_album1 ), 'photo should appear once for album1 ' );
101+ $ this ->assertSame (1 , substr_count ($ content , $ guid_album2 ), 'photo should appear once for album2 ' );
102+ } catch (\Exception $ e ) {
103+ $ this ->assertTrue (false , 'Exception occurred: ' . $ e ->getMessage ());
104+ } finally {
105+ Configs::set ('rss_enable ' , $ init_config_value );
106+ }
107+ }
69108}
0 commit comments