summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/phpunit/tests/link/wpGetCanonicalUrl.php48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/phpunit/tests/link/wpGetCanonicalUrl.php b/tests/phpunit/tests/link/wpGetCanonicalUrl.php
index 5b7eddaada..fb1f536e3f 100644
--- a/tests/phpunit/tests/link/wpGetCanonicalUrl.php
+++ b/tests/phpunit/tests/link/wpGetCanonicalUrl.php
@@ -1,13 +1,38 @@
<?php
+/**
+ * Tests for the wp_get_canonical_url() function.
+ *
+ * @package WordPress
+ * @subpackage Link
+ */
/**
+ * Class for Testing the wp_get_canonical_url() function.
+ *
* @group link
* @group canonical
* @covers ::wp_get_canonical_url
*/
-class Tests_Link_wpGetCanonicalUrl extends WP_UnitTestCase {
+class Tests_Link_WpGetCanonicalUrl extends WP_UnitTestCase {
+ /**
+ * The ID of the post.
+ *
+ * @var int
+ */
public static $post_id;
+ /**
+ * The ID of the attachment.
+ *
+ * @var int
+ */
+ public static $attachment_id;
+
+ /**
+ * Sets up the test environment before any tests are run.
+ *
+ * @param WP_UnitTest_Factory $factory The factory object.
+ */
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = $factory->post->create(
array(
@@ -15,6 +40,14 @@ class Tests_Link_wpGetCanonicalUrl extends WP_UnitTestCase {
'post_status' => 'publish',
)
);
+
+ self::$attachment_id = $factory->attachment->create_object(
+ array(
+ 'file' => DIR_TESTDATA . '/images/canola.jpg',
+ 'post_parent' => self::$post_id,
+ 'post_status' => 'inherit',
+ )
+ );
}
/**
@@ -141,6 +174,19 @@ class Tests_Link_wpGetCanonicalUrl extends WP_UnitTestCase {
}
/**
+ * This test ensures that attachments with 'inherit' status properly receive a canonical URL.
+ *
+ * @ticket 63041
+ */
+ public function test_attachment_canonical_url() {
+ $this->go_to( get_attachment_link( self::$attachment_id ) );
+ $canonical_url = wp_get_canonical_url( self::$attachment_id );
+
+ $this->assertNotFalse( $canonical_url, 'Attachment should have a canonical URL' );
+ $this->assertSame( get_attachment_link( self::$attachment_id ), $canonical_url, 'Canonical URL should match the attachment permalink' );
+ }
+
+ /**
* Test calling of filter.
*/
public function test_get_canonical_url_filter() {