Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 28623)
+++ src/wp-includes/query.php	(working copy)
@@ -1666,14 +1666,10 @@
 			}
 		}
 
-		if ( '' != $qv['pagename'] ) {
-			$this->queried_object = get_page_by_path($qv['pagename']);
-			if ( !empty($this->queried_object) )
-				$this->queried_object_id = (int) $this->queried_object->ID;
-			else
-				unset($this->queried_object);
-
-			if  ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
+		// we have a slug and need to retrieve the id
+		if  ( '' != $qv['pagename'] ) {
+			$this->get_queried_object();
+			if ( 'page' == get_option( 'show_on_front' ) && isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'page_for_posts' ) ) {
 				$this->is_page = false;
 				$this->is_home = true;
 				$this->is_posts_page = true;
@@ -3707,12 +3703,35 @@
 			$page_for_posts = get_option('page_for_posts');
 			$this->queried_object = get_post( $page_for_posts );
 			$this->queried_object_id = (int) $this->queried_object->ID;
-		} elseif ( $this->is_singular && !is_null($this->post) ) {
-			$this->queried_object = $this->post;
-			$this->queried_object_id = (int) $this->post->ID;
+		} elseif ( $this->is_singular ) {
+			if ( isset( $this->post ) ) {
+				$this->queried_object = $this->post;
+				$this->queried_object_id = (int) $this->post->ID;
+			} elseif ( $this->get( 'p' ) ) {
+				$this->queried_object = get_post( $this->get( 'p' ) );
+				$this->queried_object_id = (int) $this->get( 'p' );
+			} elseif ( $this->get( 'page_id' ) ) {
+				$this->queried_object = get_post( $this->get( 'page_id' ) );
+				$this->queried_object_id = (int) $this->get( 'page_id' );
+			} elseif ( $this->get( 'pagename' ) || $this->get( 'name' ) ) {
+				$name = $this->get( 'pagename', false ) ? $this->get( 'pagename' ) : $this->get( 'name' );
+				$this->queried_object = $this->post = get_page_by_path(
+					$name,
+					OBJECT,
+					$this->get( 'post_type' ) ? $this->get( 'post_type' ) : ( ! empty( $this->is_single ) ? 'post' : 'page' )
+				);
+				if ( $this->post ) {
+					$this->queried_object_id = (int) $this->post->ID;
+				}
+			}
 		} elseif ( $this->is_author ) {
-			$this->queried_object_id = (int) $this->get('author');
-			$this->queried_object = get_userdata( $this->queried_object_id );
+			if ( $this->get( 'author' ) ) {
+				$this->queried_object_id = (int) $this->get( 'author' );
+				$this->queried_object = get_userdata( $this->queried_object_id );
+			} elseif ( $this->get( 'author_name' ) ) {
+				$this->queried_object = get_user_by( 'login', $this->get( 'author_name' ) );
+				$this->queried_object_id = (int) $this->queried_object->ID;
+			}
 		}
 
 		return $this->queried_object;
Index: tests/phpunit/tests/query.php
===================================================================
--- tests/phpunit/tests/query.php	(revision 28617)
+++ tests/phpunit/tests/query.php	(working copy)
@@ -135,4 +135,790 @@
 		$this->assertCount( 1, $query->get( 'tag_slug__in' ) );
 		$this->assertEquals( $query->get_queried_object(), $tag );
 	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_single_default_permalink() {
+		update_option( 'permalink_structure', '' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		// add the filter to parse_query (this is the first point at which ->get_queried_object() will be available)
+		add_filter( 'parse_query', array( $this, '_single_default_parse_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-1' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'p' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_single_default_parse_query_queried_object' ) );
+	}
+
+	function _single_default_parse_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-1', OBJECT, 'post' );
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'p' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_single_day_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_single_day_name_parse_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-2' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'year' ) );
+		$this->assertNotEmpty( get_query_var( 'monthnum' ) );
+		$this->assertNotEmpty( get_query_var( 'day' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_single_day_name_parse_query_queried_object' ) );
+	}
+
+	function _single_day_name_parse_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-2', OBJECT, 'post' );
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'year' ) );
+		$this->assertNotEmpty( $query->get( 'monthnum' ) );
+		$this->assertNotEmpty( $query->get( 'day' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_single_month_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_single_month_name_parse_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-3' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'year' ) );
+		$this->assertNotEmpty( get_query_var( 'monthnum' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_single_month_name_parse_query_queried_object' ) );
+	}
+
+	function _single_month_name_parse_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-3', OBJECT, 'post' );
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( get_query_var( 'year' ) );
+		$this->assertNotEmpty( get_query_var( 'monthnum' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_single_numeric_permalink() {
+		update_option( 'permalink_structure', '/archives/%post_id%' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_single_numeric_parse_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-4' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'p' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_single_numeric_parse_query_queried_object' ) );
+	}
+
+	function _single_numeric_parse_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-4', OBJECT, 'post' );
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'p' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_single_postname_permalink() {
+		update_option( 'permalink_structure', '/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_single_postname_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-5' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_single_postname_query_queried_object' ) );
+	}
+
+	function _single_postname_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-5', OBJECT, 'post' );
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_page_default_permalink() {
+		update_option( 'permalink_structure', '' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_page_default_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-6' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_page_default_query_queried_object' ) );
+	}
+
+	function _page_default_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-6', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_page_day_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_page_day_name_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-7' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'pagename' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_page_day_name_query_queried_object' ) );
+	}
+
+	function _page_day_name_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-7', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'pagename' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 * Tests start failing here and I have no idea why.
+	 */
+	function test_page_month_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_page_month_name_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-8' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'pagename' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_page_month_name_query_queried_object' ) );
+	}
+
+	function _page_month_name_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-8', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'pagename' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_page_numeric_permalink() {
+		update_option( 'permalink_structure', '/archives/%post_id%' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_page_numeric_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-9' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'pagename' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_page_numeric_query_queried_object' ) );
+	}
+
+	function _page_numeric_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-9', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'pagename' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_page_postname_permalink() {
+		update_option( 'permalink_structure', '/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_page_postname_query_queried_object' ) );
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-10' ) );
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertNotEmpty( get_query_var( 'pagename' ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_page_postname_query_queried_object' ) );
+	}
+
+	function _page_postname_query_queried_object( &$query ) {
+		$single = get_page_by_path( 'test-27015-10', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertNotEmpty( $query->get( 'pagename' ) );
+		$this->assertEquals( $query->get_queried_object(), $single );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_front_page_default_permalink() {
+		$front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-1', 'post_type' => 'page' ) );
+
+		update_option( 'show_on_front', 'page' );
+		update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
+		update_option( 'page_on_front', $front_page->ID );
+		update_option( 'permalink_structure', false );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_front_page_default_query' ) );
+
+		$this->go_to( '/' );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertTrue( is_front_page() );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $front_page );
+
+		remove_filter( 'parse_query', array( $this, '_front_page_default_query' ) );
+	}
+
+	function _front_page_default_query( &$query ) {
+		$front_page = get_page_by_path( 'front-page-27015-1', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertTrue( $query->is_front_page() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $front_page );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_front_page_day_name_permalink() {
+		$front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-2', 'post_type' => 'page' ) );
+
+		update_option( 'show_on_front', 'page' );
+		update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
+		update_option( 'page_on_front', $front_page->ID );
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_front_page_day_name_query' ) );
+
+		$this->go_to( '/' );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertTrue( is_front_page() );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $front_page );
+
+		remove_filter( 'parse_query', array( $this, '_front_page_day_name_query' ) );
+	}
+
+	function _front_page_day_name_query( &$query ) {
+		$front_page = get_page_by_path( 'front-page-27015-2', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertTrue( $query->is_front_page() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $front_page );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_front_page_month_name_permalink() {
+		$front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-3', 'post_type' => 'page' ) );
+
+		update_option( 'show_on_front', 'page' );
+		update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
+		update_option( 'page_on_front', $front_page->ID );
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_front_page_month_name_query' ) );
+
+		$this->go_to( '/' );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertTrue( is_front_page() );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $front_page );
+
+		remove_filter( 'parse_query', array( $this, '_front_page_month_name_query' ) );
+	}
+
+	function _front_page_month_name_query( &$query ) {
+		$front_page = get_page_by_path( 'front-page-27015-3', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertTrue( $query->is_front_page() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $front_page );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_front_page_numeric_permalink() {
+		$front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-4', 'post_type' => 'page' ) );
+
+		update_option( 'show_on_front', 'page' );
+		update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
+		update_option( 'page_on_front', $front_page->ID );
+		update_option( 'permalink_structure', '/archives/%post_id%' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_front_page_numeric_query' ) );
+
+		$this->go_to( '/' );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertTrue( is_front_page() );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $front_page );
+
+		remove_filter( 'parse_query', array( $this, '_front_page_numeric_query' ) );
+	}
+
+	function _front_page_numeric_query( &$query ) {
+		$front_page = get_page_by_path( 'front-page-27015-4', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertTrue( $query->is_front_page() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $front_page );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_front_page_postname_permalink() {
+		$front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-5', 'post_type' => 'page' ) );
+
+		update_option( 'show_on_front', 'page' );
+		update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
+		update_option( 'page_on_front', $front_page->ID );
+		update_option( 'permalink_structure', '/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		add_filter( 'parse_query', array( $this, '_front_page_postname_query' ) );
+
+		$this->go_to( '/' );
+
+		$this->assertQueryTrue( 'is_page', 'is_singular' );
+		$this->assertTrue( is_front_page() );
+		$this->assertNotEmpty( get_query_var( 'page_id' ) );
+		$this->assertEquals( get_queried_object(), $front_page );
+
+		remove_filter( 'parse_query', array( $this, '_front_page_postname_query' ) );
+	}
+
+	function _front_page_postname_query( &$query ) {
+		$front_page = get_page_by_path( 'front-page-27015-5', OBJECT, 'page' );
+		$this->assertTrue( $query->is_page() );
+		$this->assertTrue( $query->is_singular() );
+		$this->assertTrue( $query->is_front_page() );
+		$this->assertNotEmpty( $query->get( 'page_id' ) );
+		$this->assertEquals( $query->get_queried_object(), $front_page );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_author_archive_default_permalink() {
+		update_option( 'permalink_structure', false );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) );
+
+		add_filter( 'parse_query', array( $this, '_author_archive_default_query' ) );
+
+		$this->go_to( get_author_posts_url( 1 ) );
+
+		$this->assertQueryTrue( 'is_author', 'is_archive' );
+		$this->assertTrue( is_author() );
+		$this->assertTrue( is_archive() );
+		$this->assertNotEmpty( get_query_var( 'author' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+
+		remove_filter( 'parse_query', array( $this, '_author_archive_default_query' ) );
+	}
+
+	function _author_archive_default_query( &$query ) {
+		$this->assertTrue( $query->is_author() );
+		$this->assertTrue( $query->is_archive() );
+		$this->assertNotEmpty( $query->get( 'author' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_author_archive_day_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) );
+
+		add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+
+		$this->go_to( get_author_posts_url( 1 ) );
+
+		$this->assertQueryTrue( 'is_author', 'is_archive' );
+		$this->assertTrue( is_author() );
+		$this->assertTrue( is_archive() );
+		$this->assertNotEmpty( get_query_var( 'author_name' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+
+		remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_author_archive_month_name_permalink() {
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) );
+
+		add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+
+		$this->go_to( get_author_posts_url( 1 ) );
+
+		$this->assertQueryTrue( 'is_author', 'is_archive' );
+		$this->assertTrue( is_author() );
+		$this->assertTrue( is_archive() );
+		$this->assertNotEmpty( get_query_var( 'author_name' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+
+		remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_author_archive_numeric_permalink() {
+		update_option( 'permalink_structure', '/archives/%post_id%' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) );
+
+		add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+
+		$this->go_to( get_author_posts_url( 1 ) );
+
+		$this->assertQueryTrue( 'is_author', 'is_archive' );
+		$this->assertTrue( is_author() );
+		$this->assertTrue( is_archive() );
+		$this->assertNotEmpty( get_query_var( 'author_name' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+
+		remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_author_archive_postname_permalink() {
+		update_option( 'permalink_structure', '/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) );
+
+		add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+
+		$this->go_to( get_author_posts_url( 1 ) );
+
+		$this->assertQueryTrue( 'is_author', 'is_archive' );
+		$this->assertTrue( is_author() );
+		$this->assertTrue( is_archive() );
+		$this->assertNotEmpty( get_query_var( 'author_name' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+
+		remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) );
+	}
+
+	function _author_archive_not_default_query( &$query ) {
+		$this->assertTrue( $query->is_author() );
+		$this->assertTrue( $query->is_archive() );
+		$this->assertNotEmpty( $query->get( 'author_name' ) );
+		$this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_cpt_default_permalink() {
+		register_post_type( 'test-27015', array(
+			'rewrite'     => true,
+			'has_archive' => true,
+			'public'      => true
+		) );
+		update_option( 'permalink_structure', '' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-1' ) );
+
+		add_filter( 'parse_query', array( $this, '_cpt_default_permalink_query' ) );
+
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertTrue( is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( get_query_var( 'post_type' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_cpt_default_permalink_query' ) );
+		_unregister_post_type( 'test-27015' );
+	}
+
+	function _cpt_default_permalink_query( &$query ) {
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( $query->get( 'post_type' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) );
+		$this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-1', OBJECT, 'test-27015' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_cpt_day_name_permalink() {
+		register_post_type( 'test-27015', array(
+			'rewrite'     => true,
+			'has_archive' => true,
+			'public'      => true
+		) );
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-2' ) );
+
+		add_filter( 'parse_query', array( $this, '_cpt_day_name_permalink_query' ) );
+
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertTrue( is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( get_query_var( 'post_type' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_cpt_day_name_permalink_query' ) );
+		_unregister_post_type( 'test-27015' );
+	}
+
+	function _cpt_day_name_permalink_query( &$query ) {
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( $query->get( 'post_type' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) );
+		$this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-2', OBJECT, 'test-27015' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_cpt_month_name_permalink() {
+		register_post_type( 'test-27015', array(
+			'rewrite'     => true,
+			'has_archive' => true,
+			'public'      => true
+		) );
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-3' ) );
+
+		add_filter( 'parse_query', array( $this, '_cpt_month_name_permalink_query' ) );
+
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertTrue( is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( get_query_var( 'post_type' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_cpt_month_name_permalink_query' ) );
+		_unregister_post_type( 'test-27015' );
+	}
+
+	function _cpt_month_name_permalink_query( &$query ) {
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( $query->get( 'post_type' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) );
+		$this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-3', OBJECT, 'test-27015' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_cpt_numeric_permalink() {
+		register_post_type( 'test-27015', array(
+			'rewrite'     => true,
+			'has_archive' => true,
+			'public'      => true
+		) );
+		update_option( 'permalink_structure', '/archives/%post_id%' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-4' ) );
+
+		add_filter( 'parse_query', array( $this, '_cpt_numeric_permalink_query' ) );
+
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertTrue( is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( get_query_var( 'post_type' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_cpt_numeric_permalink_query' ) );
+		_unregister_post_type( 'test-27015' );
+	}
+
+	function _cpt_numeric_permalink_query( &$query ) {
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( $query->get( 'post_type' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) );
+		$this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-4', OBJECT, 'test-27015' ) );
+	}
+
+	/**
+	 * @ticket 27015
+	 */
+	function test_cpt_postname_permalink() {
+		register_post_type( 'test-27015', array(
+			'rewrite'     => true,
+			'has_archive' => true,
+			'public'      => true
+		) );
+		update_option( 'permalink_structure', '/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		flush_rewrite_rules();
+
+		$post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-5' ) );
+
+		add_filter( 'parse_query', array( $this, '_cpt_postname_permalink_query' ) );
+
+		$this->go_to( get_permalink( $post1->ID ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertTrue( is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( get_query_var( 'post_type' ) );
+		$this->assertNotEmpty( get_query_var( 'name' ) );
+		$this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) );
+		$this->assertEquals( get_queried_object(), $post1 );
+
+		remove_filter( 'parse_query', array( $this, '_cpt_postname_permalink_query' ) );
+		_unregister_post_type( 'test-27015' );
+	}
+
+	function _cpt_postname_permalink_query( &$query ) {
+		$this->assertTrue( $query->is_single() );
+		$this->assertTrue( $query->is_singular( 'test-27015' ) );
+		$this->assertNotEmpty( $query->get( 'post_type' ) );
+		$this->assertNotEmpty( $query->get( 'name' ) );
+		$this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) );
+		$this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-5', OBJECT, 'test-27015' ) );
+	}
 }
\ No newline at end of file
