Index: wp-testcase/test_includes_post.php
===================================================================
--- wp-testcase/test_includes_post.php	(revision 745)
+++ wp-testcase/test_includes_post.php	(working copy)
@@ -470,8 +470,19 @@
 }
 
 class WPTestAttachments extends _WPEmptyBlog {
+	function setUp() {
+		parent::setUp();
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
+		create_initial_taxonomies();
+		$wp_rewrite->flush_rules();
+  
 
+	}
+
 	function tearDown() {
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure('');
 		parent::tearDown();
 		// restore system defaults
 		update_option('medium_size_w', '');
@@ -671,6 +682,36 @@
 		$this->assertFalse( is_file($original) );
 	}
 
+	function test_attachment_and_child_page_name_conflict() {
+		// Bug - http://core.trac.wordpress.org/ticket/15665
+		// Page name won't work if the parent page has an attachment with the same name
+		$this->_insert_quick_posts(1, 'page');
+
+		$parent_page_id = $this->post_ids[-1];
+		// Give it an attachment
+		$filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
+		$contents = file_get_contents($filename);
+
+		$upload = wp_upload_bits(basename($filename), null, $contents);
+		$this->assertTrue( empty($upload['error']) );
+
+		$attachment_id = $this->_make_attachment($upload, $parent_page_id);
+
+		$child_page_id = $this->post_ids[] = wp_insert_post(array(
+                                'post_author' => $this->author->ID,
+                                'post_status' => 'publish',
+                                'post_title' => basename($filename),
+                                'post_content' => 'child page content',
+                                'post_excerpt' => 'child page excerpt',
+                                'post_type' => 'page'
+                                ));
+		$this->http(get_permalink($child_page_id));
+		$this->assertTrue(is_page(), 'failed is_page');
+		$this->assertTrue(have_posts(), 'no posts found querying child page id permalink');
+		$this->assertNull(the_post(), 'error loading queried post');
+		$this->assertEquals($child_page_id, get_the_ID(), 'child page id does not equal found post id');
+		$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');
+	}
 }
 
 class WPTestPostMeta extends WPTestCase {
