WordPress.org

Make WordPress Core

Ticket #15665: 15665-unit.patch

File 15665-unit.patch, 2.4 KB (added by devesine, 6 years ago)

Here's a unit test which tests this bug. Comments gratefully accepted - particularly as this is the first WP test I've written.

  • wp-testcase/test_includes_post.php

     
    470470}
    471471
    472472class WPTestAttachments extends _WPEmptyBlog {
     473        function setUp() {
     474                parent::setUp();
     475                global $wp_rewrite;
     476                $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     477                create_initial_taxonomies();
     478                $wp_rewrite->flush_rules();
     479 
    473480
     481        }
     482
    474483        function tearDown() {
     484                global $wp_rewrite;
     485                $wp_rewrite->set_permalink_structure('');
    475486                parent::tearDown();
    476487                // restore system defaults
    477488                update_option('medium_size_w', '');
     
    671682                $this->assertFalse( is_file($original) );
    672683        }
    673684
     685        function test_attachment_and_child_page_name_conflict() {
     686                // Bug - http://core.trac.wordpress.org/ticket/15665
     687                // Page name won't work if the parent page has an attachment with the same name
     688                $this->_insert_quick_posts(1, 'page');
     689
     690                $parent_page_id = $this->post_ids[-1];
     691                // Give it an attachment
     692                $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
     693                $contents = file_get_contents($filename);
     694
     695                $upload = wp_upload_bits(basename($filename), null, $contents);
     696                $this->assertTrue( empty($upload['error']) );
     697
     698                $attachment_id = $this->_make_attachment($upload, $parent_page_id);
     699
     700                $child_page_id = $this->post_ids[] = wp_insert_post(array(
     701                                'post_author' => $this->author->ID,
     702                                'post_status' => 'publish',
     703                                'post_title' => basename($filename),
     704                                'post_content' => 'child page content',
     705                                'post_excerpt' => 'child page excerpt',
     706                                'post_type' => 'page'
     707                                ));
     708                $this->http(get_permalink($child_page_id));
     709                $this->assertTrue(is_page(), 'failed is_page');
     710                $this->assertTrue(have_posts(), 'no posts found querying child page id permalink');
     711                $this->assertNull(the_post(), 'error loading queried post');
     712                $this->assertEquals($child_page_id, get_the_ID(), 'child page id does not equal found post id');
     713                $this->assertEquals('child page excerpt', strip_tags(strip_ws(get_echo('the_excerpt'))), 'the child page excerpt and the queried page excerpt do not match');
     714        }
    674715}
    675716
    676717class WPTestPostMeta extends WPTestCase {