From 6f6f62b6e568b305716985ccb66c4be46ace9abf Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Tue, 29 Sep 2015 05:37:00 +0000 Subject: [PATCH] Tests: Consolidate author-template tests into a single, more logically-placed file, tests/user/author.php. See #34070. git-svn-id: https://develop.svn.wordpress.org/trunk@34687 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/template/author.php | 77 ------------------------- tests/phpunit/tests/user/author.php | 66 ++++++++++++++++++++- 2 files changed, 63 insertions(+), 80 deletions(-) delete mode 100644 tests/phpunit/tests/template/author.php diff --git a/tests/phpunit/tests/template/author.php b/tests/phpunit/tests/template/author.php deleted file mode 100644 index a84e8d8409..0000000000 --- a/tests/phpunit/tests/template/author.php +++ /dev/null @@ -1,77 +0,0 @@ -permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - - } - - public function tearDown() { - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( $this->permalink_structure ); - $wp_rewrite->flush_rules(); - - parent::tearDown(); - } - - /** - * @ticket 30355 - */ - public function test_get_the_author_posts_link_no_permalinks() { - $author = $this->factory->user->create_and_get( array( - 'display_name' => 'Foo', - 'user_nicename' => 'bar' - ) ); - - $GLOBALS['authordata'] = $author->data; - - $link = get_the_author_posts_link(); - - $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID ); - - $this->assertContains( $url, $link ); - $this->assertContains( 'Posts by Foo', $link ); - $this->assertContains( '>Foo', $link ); - - unset( $GLOBALS['authordata'] ); - } - - /** - * @ticket 30355 - */ - public function test_get_the_author_posts_link_with_permalinks() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '/%postname%/' ); - $wp_rewrite->flush_rules(); - - $author = $this->factory->user->create_and_get( array( - 'display_name' => 'Foo', - 'user_nicename' => 'bar' - ) ); - - $GLOBALS['authordata'] = $author; - - $link = get_the_author_posts_link(); - - $url = sprintf( 'http://%1$s/author/%2$s/', WP_TESTS_DOMAIN, $author->user_nicename ); - - $this->assertContains( $url, $link ); - $this->assertContains( 'Posts by Foo', $link ); - $this->assertContains( '>Foo', $link ); - - unset( $GLOBALS['authordata'] ); - } -} diff --git a/tests/phpunit/tests/user/author.php b/tests/phpunit/tests/user/author.php index 71fa99a37e..8a0b8e1f65 100644 --- a/tests/phpunit/tests/user/author.php +++ b/tests/phpunit/tests/user/author.php @@ -1,19 +1,25 @@ permalink_structure = get_option( 'permalink_structure' ); + $wp_rewrite->set_permalink_structure( '' ); + $wp_rewrite->flush_rules(); + $this->author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'test_author', @@ -36,6 +42,10 @@ class Tests_User_Author extends WP_UnitTestCase { } function tearDown() { + global $wp_rewrite; + $wp_rewrite->set_permalink_structure( $this->permalink_structure ); + $wp_rewrite->flush_rules(); + wp_reset_postdata(); parent::tearDown(); } @@ -99,4 +109,54 @@ class Tests_User_Author extends WP_UnitTestCase { _unregister_post_type( 'wptests_pt' ); } + + /** + * @ticket 30355 + */ + public function test_get_the_author_posts_link_no_permalinks() { + $author = $this->factory->user->create_and_get( array( + 'display_name' => 'Foo', + 'user_nicename' => 'bar' + ) ); + + $GLOBALS['authordata'] = $author->data; + + $link = get_the_author_posts_link(); + + $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID ); + + $this->assertContains( $url, $link ); + $this->assertContains( 'Posts by Foo', $link ); + $this->assertContains( '>Foo', $link ); + + unset( $GLOBALS['authordata'] ); + } + + /** + * @ticket 30355 + */ + public function test_get_the_author_posts_link_with_permalinks() { + global $wp_rewrite; + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '/%postname%/' ); + $wp_rewrite->flush_rules(); + + $author = $this->factory->user->create_and_get( array( + 'display_name' => 'Foo', + 'user_nicename' => 'bar' + ) ); + + $GLOBALS['authordata'] = $author; + + $link = get_the_author_posts_link(); + + $url = sprintf( 'http://%1$s/author/%2$s/', WP_TESTS_DOMAIN, $author->user_nicename ); + + $this->assertContains( $url, $link ); + $this->assertContains( 'Posts by Foo', $link ); + $this->assertContains( '>Foo', $link ); + + unset( $GLOBALS['authordata'] ); + } + }