Skip to content

Commit f80ca49

Browse files
author
Claude
committed
test: fix child attachment URLs and PHPCS alignment
Child attachment URLs with pretty permalinks take the form /parent-slug/attachment-slug/, not just /attachment-slug/. Fix test URLs to include the parent post slug. Break consecutive self:: assignments with blank lines to avoid PHPCS MultipleStatementAlignment warnings between differently-named properties.
1 parent 4f67753 commit f80ca49

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

tests/phpunit/tests/canonical/attachmentRedirect.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
4545
'post_status' => 'publish',
4646
)
4747
);
48+
4849
self::$attached_to_public = $factory->post->create_and_get(
4950
array(
5051
'post_type' => 'attachment',
@@ -66,6 +67,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
6667
'post_author' => self::$editor_user,
6768
)
6869
);
70+
6971
self::$attached_to_private = $factory->post->create_and_get(
7072
array(
7173
'post_type' => 'attachment',
@@ -87,6 +89,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
8789
'post_author' => self::$editor_user,
8890
)
8991
);
92+
9093
self::$attached_to_draft = $factory->post->create_and_get(
9194
array(
9295
'post_type' => 'attachment',
@@ -140,13 +143,16 @@ public function test_unattached_query_var_url_redirects_when_pages_disabled() {
140143
// -------------------------------------------------------------------------
141144

142145
/**
143-
* Attachment on a public post should redirect via slug URL.
146+
* Attachment on a public post should redirect via its child slug URL.
147+
*
148+
* With pretty permalinks, child attachment URLs take the form
149+
* /parent-slug/attachment-slug/.
144150
*/
145151
public function test_attached_to_public_post_slug_url_redirects() {
146152
update_option( 'wp_attachment_pages_enabled', 0 );
147153
$this->set_permalink_structure( '/%postname%/' );
148154

149-
$this->assertCanonical( '/public-attached-image/', $this->get_expected_path( self::$attached_to_public->ID ) );
155+
$this->assertCanonical( '/public-post/public-attached-image/', $this->get_expected_path( self::$attached_to_public->ID ) );
150156
}
151157

152158
// -------------------------------------------------------------------------
@@ -162,7 +168,7 @@ public function test_attached_to_private_post_no_redirect_for_anonymous() {
162168
$this->set_permalink_structure( '/%postname%/' );
163169
wp_set_current_user( 0 );
164170

165-
$this->assertCanonical( '/private-attached-image/', '/private-attached-image/' );
171+
$this->assertCanonical( '/private-post/private-attached-image/', '/private-post/private-attached-image/' );
166172
}
167173

168174
// -------------------------------------------------------------------------
@@ -177,7 +183,7 @@ public function test_attached_to_private_post_redirects_for_authorized_user() {
177183
$this->set_permalink_structure( '/%postname%/' );
178184
wp_set_current_user( self::$editor_user );
179185

180-
$this->assertCanonical( '/private-attached-image/', $this->get_expected_path( self::$attached_to_private->ID ) );
186+
$this->assertCanonical( '/private-post/private-attached-image/', $this->get_expected_path( self::$attached_to_private->ID ) );
181187
}
182188

183189
// -------------------------------------------------------------------------
@@ -192,7 +198,7 @@ public function test_attached_to_draft_post_no_redirect_for_anonymous() {
192198
$this->set_permalink_structure( '/%postname%/' );
193199
wp_set_current_user( 0 );
194200

195-
$this->assertCanonical( '/draft-attached-image/', '/draft-attached-image/' );
201+
$this->assertCanonical( '/draft-post/draft-attached-image/', '/draft-post/draft-attached-image/' );
196202
}
197203

198204
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)