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
This commit is contained in:
Drew Jaynes 2015-09-29 05:37:00 +00:00
parent 1ac3ba0828
commit 6f6f62b6e5
2 changed files with 63 additions and 80 deletions

View File

@ -1,77 +0,0 @@
<?php
/**
* A set of unit tests for functions in wp-includes/author-template.php
*
* @group template
*/
class Tests_Author_Template extends WP_UnitTestCase {
private $permalink_structure;
public function setUp() {
parent::setUp();
global $wp_rewrite;
$this->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</a>', $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</a>', $link );
unset( $GLOBALS['authordata'] );
}
}

View File

@ -1,19 +1,25 @@
<?php <?php
/** /**
* Test functions in wp-includes/author.php, author-template.php * Test functions in wp-includes/author-template.php
* *
* @group author * @group author
* @group user * @group user
*/ */
class Tests_User_Author extends WP_UnitTestCase { class Tests_User_Author_Template extends WP_UnitTestCase {
protected $old_post_id = 0;
protected $author_id = 0; protected $author_id = 0;
protected $post_id = 0; protected $post_id = 0;
private $permalink_structure;
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
global $wp_rewrite;
$this->permalink_structure = get_option( 'permalink_structure' );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
$this->author_id = $this->factory->user->create( array( $this->author_id = $this->factory->user->create( array(
'role' => 'author', 'role' => 'author',
'user_login' => 'test_author', 'user_login' => 'test_author',
@ -36,6 +42,10 @@ class Tests_User_Author extends WP_UnitTestCase {
} }
function tearDown() { function tearDown() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( $this->permalink_structure );
$wp_rewrite->flush_rules();
wp_reset_postdata(); wp_reset_postdata();
parent::tearDown(); parent::tearDown();
} }
@ -99,4 +109,54 @@ class Tests_User_Author extends WP_UnitTestCase {
_unregister_post_type( 'wptests_pt' ); _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</a>', $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</a>', $link );
unset( $GLOBALS['authordata'] );
}
} }