From 4dfb71c3b5181e4f95717bc02864e7814643fff2 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 2 Nov 2016 19:22:17 +0000 Subject: [PATCH] Query: Add tests for `WP_Query::is_single()` and `get_body_class()` with attachments. See [39052] See #38225. git-svn-id: https://develop.svn.wordpress.org/trunk@39095 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/getBodyClass.php | 19 +++++++++++++++++++ tests/phpunit/tests/query/conditionals.php | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/phpunit/tests/post/getBodyClass.php b/tests/phpunit/tests/post/getBodyClass.php index 771b8e3a02..8501c34574 100644 --- a/tests/phpunit/tests/post/getBodyClass.php +++ b/tests/phpunit/tests/post/getBodyClass.php @@ -158,4 +158,23 @@ class Tests_Post_GetBodyClass extends WP_UnitTestCase { $this->assertContains( 'post-template-cpt', $class ); $this->assertContains( 'post-template-templatescpt-php', $class ); } + + /** + * @ticket 38225 + */ + public function test_attachment_body_classes() { + $post_id = self::factory()->post->create(); + + $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( + 'post_mime_type' => 'image/jpeg', + ) ); + + $this->go_to( get_permalink( $attachment_id ) ); + + $class = get_body_class(); + + $this->assertContains( 'attachment', $class ); + $this->assertContains( "attachmentid-{$attachment_id}", $class ); + $this->assertContains( 'attachment-jpeg', $class ); + } } diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 4a6d2be548..5085052d69 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -818,6 +818,25 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->set_permalink_structure(); } + /** + * @ticket 38225 + */ + function test_is_single_with_attachment() { + $post_id = self::factory()->post->create(); + + $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( + 'post_mime_type' => 'image/jpeg', + ) ); + + $this->go_to( get_permalink( $attachment_id ) ); + + $q = $GLOBALS['wp_query']; + + $this->assertTrue( is_single() ); + $this->assertTrue( $q->is_single ); + $this->assertTrue( $q->is_attachment ); + } + function test_is_page() { $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); $this->go_to( "/?page_id=$post_id" );