mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Unit Tests: one $factory to rule them all, and it shall be static.
Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`. Replace `$this->factory` with `self::$factory` over 2000 times. Rewrite all of the tests that were hard-coding dynamic values. #YOLOFriday git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -10,13 +10,13 @@ class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase {
|
||||
|
||||
public function setUp(){
|
||||
parent::setUp();
|
||||
$this->cat_id = $this->factory->category->create( array( 'name' => 'other' ) );
|
||||
$this->cat_id = self::$factory->category->create( array( 'name' => 'other' ) );
|
||||
$this->post_ids = array();
|
||||
$this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 05:32:29', 'category_id' => 1 ) );
|
||||
$this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 04:32:29', 'category_id' => $this->cat_id ) );
|
||||
$this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 03:32:29', 'category_id' => 1 ) );
|
||||
$this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 02:32:29', 'category_id' => $this->cat_id ) );
|
||||
$this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 01:32:29', 'category_id' => 1 ) );
|
||||
$this->post_ids[] = self::$factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 05:32:29', 'category_id' => 1 ) );
|
||||
$this->post_ids[] = self::$factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 04:32:29', 'category_id' => $this->cat_id ) );
|
||||
$this->post_ids[] = self::$factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 03:32:29', 'category_id' => 1 ) );
|
||||
$this->post_ids[] = self::$factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 02:32:29', 'category_id' => $this->cat_id ) );
|
||||
$this->post_ids[] = self::$factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 01:32:29', 'category_id' => 1 ) );
|
||||
|
||||
//set current post (has 2 on each end)
|
||||
global $GLOBALS;
|
||||
@@ -25,37 +25,43 @@ class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase {
|
||||
|
||||
public function test_get_next_post_link_default() {
|
||||
$actual = get_next_post_link();
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">Post title 2</a> »';
|
||||
$title = get_post( $this->post_ids[1] )->post_title;
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_get_previous_post_link_default() {
|
||||
$actual = get_previous_post_link();
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">Post title 4</a>';
|
||||
$title = get_post( $this->post_ids[3] )->post_title;
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_get_next_post_link_same_category() {
|
||||
$actual = get_next_post_link( '%link »', '%title', true );
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">Post title 2</a> »';
|
||||
$title = get_post( $this->post_ids[1] )->post_title;
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_get_previous_post_link_same_category() {
|
||||
$actual = get_previous_post_link( '« %link', '%title', true );
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">Post title 4</a>';
|
||||
$title = get_post( $this->post_ids[3] )->post_title;
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_get_next_post_link_exclude_category() {
|
||||
$actual = get_next_post_link( '%link »', '%title', false, $this->cat_id );
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">Post title 2</a> »';
|
||||
$title = get_post( $this->post_ids[1] )->post_title;
|
||||
$expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_get_previous_post_link_exclude_category() {
|
||||
$actual = get_previous_post_link( '« %link', '%title', false, $this->cat_id );
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">Post title 4</a>';
|
||||
$title = get_post( $this->post_ids[3] )->post_title;
|
||||
$expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user