@@ -88,6 +88,100 @@ public function testContentsBlockVisibility() {
8888 $ this ->assertSession ()->responseNotContains ('Guide overview ' );
8989 }
9090
91+ /**
92+ * Test unpublished guide page links in contents block.
93+ */
94+ public function testUnpublishedGuidePageLinks () {
95+ // Create a guide overview.
96+ $ overview = $ this ->createNode ([
97+ 'title ' => 'Guide overview ' ,
98+ 'type ' => 'localgov_guides_overview ' ,
99+ 'status ' => NodeInterface::PUBLISHED ,
100+ ]);
101+
102+ // Create published guide pages.
103+ $ published_page = $ this ->createNode ([
104+ 'title ' => 'Published guide page ' ,
105+ 'type ' => 'localgov_guides_page ' ,
106+ 'status ' => NodeInterface::PUBLISHED ,
107+ 'localgov_guides_parent ' => ['target_id ' => $ overview ->id ()],
108+ ]);
109+
110+ // Create unpublished guide page.
111+ $ unpublished_page = $ this ->createNode ([
112+ 'title ' => 'Unpublished guide page ' ,
113+ 'type ' => 'localgov_guides_page ' ,
114+ 'status ' => NodeInterface::NOT_PUBLISHED ,
115+ 'localgov_guides_parent ' => ['target_id ' => $ overview ->id ()],
116+ ]);
117+
118+ // Test as anonymous user - unpublished pages should not appear.
119+ $ this ->drupalGet ($ overview ->toUrl ()->toString ());
120+ $ this ->assertSession ()->responseContains ('Published guide page ' );
121+ $ this ->assertSession ()->responseNotContains ('Unpublished guide page ' );
122+
123+ // Verify no data-drupal-is-unpublished attribute for anonymous users.
124+ $ this ->assertSession ()->elementNotExists ('css ' , '[data-drupal-is-unpublished] ' );
125+
126+ // Test as authenticated user with content access permissions.
127+ $ content_admin = $ this ->drupalCreateUser ([
128+ 'bypass node access ' ,
129+ 'access content ' ,
130+ ]);
131+ $ this ->drupalLogin ($ content_admin );
132+
133+ // Check overview page - both published and unpublished should appear.
134+ $ this ->drupalGet ($ overview ->toUrl ()->toString ());
135+ $ this ->assertSession ()->responseContains ('Published guide page ' );
136+ $ this ->assertSession ()->responseContains ('Unpublished guide page ' );
137+
138+ // Verify unpublished page has data-drupal-is-unpublished attribute.
139+ $ this ->assertSession ()->elementExists ('css ' , '[data-drupal-is-unpublished] ' );
140+
141+ // Verify published page does not have the unpublished attribute.
142+ $ published_link_xpath = '//a[contains(text(), "Published guide page")]/ancestor::li ' ;
143+ $ published_elements = $ this ->xpath ($ published_link_xpath );
144+ $ this ->assertCount (1 , $ published_elements );
145+ $ this ->assertFalse ($ published_elements [0 ]->hasAttribute ('data-drupal-is-unpublished ' ));
146+
147+ // Verify unpublished page has the unpublished attribute.
148+ $ unpublished_link_xpath = '//li[@data-drupal-is-unpublished] ' ;
149+ $ unpublished_elements = $ this ->xpath ($ unpublished_link_xpath );
150+ $ this ->assertCount (1 , $ unpublished_elements );
151+ $ this ->assertStringContainsString ('Unpublished guide page ' , $ unpublished_elements [0 ]->getText ());
152+
153+ // Test from a guide page view.
154+ $ this ->drupalGet ($ published_page ->toUrl ()->toString ());
155+ $ this ->assertSession ()->responseContains ('Guide overview ' );
156+ $ this ->assertSession ()->responseContains ('Published guide page ' );
157+ $ this ->assertSession ()->responseContains ('Unpublished guide page ' );
158+
159+ // Verify unpublished attribute is present when viewing from guide page.
160+ $ this ->assertSession ()->elementExists ('css ' , '[data-drupal-is-unpublished] ' );
161+
162+ // Test visibility changes when publishing status changes.
163+ $ this ->drupalLogout ();
164+
165+ // Publish the previously unpublished page.
166+ $ unpublished_page ->status = NodeInterface::PUBLISHED ;
167+ $ unpublished_page ->save ();
168+
169+ // Check as anonymous user - should now see the page without unpublished attribute.
170+ $ this ->drupalGet ($ overview ->toUrl ()->toString ());
171+ $ this ->assertSession ()->responseContains ('Published guide page ' );
172+ $ this ->assertSession ()->responseContains ('Unpublished guide page ' );
173+ $ this ->assertSession ()->elementNotExists ('css ' , '[data-drupal-is-unpublished] ' );
174+
175+ // Unpublish the previously published page.
176+ $ published_page ->status = NodeInterface::NOT_PUBLISHED ;
177+ $ published_page ->save ();
178+
179+ // Check as anonymous user - should not see the unpublished page.
180+ $ this ->drupalGet ($ overview ->toUrl ()->toString ());
181+ $ this ->assertSession ()->responseNotContains ('Published guide page ' );
182+ $ this ->assertSession ()->responseContains ('Unpublished guide page ' );
183+ }
184+
91185 /**
92186 * Test the contents list block.
93187 */
0 commit comments