Add tests for `get_adjacent_post_link()` wrappers.

Props MikeHansenMe.
See #29663.

git-svn-id: https://develop.svn.wordpress.org/trunk@30264 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2014-11-06 20:16:10 +00:00
parent 6f7880bcf4
commit 11843fe460
1 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
/**
* @group link
*/
class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase {
protected $post_ids;
protected $cat_id;
public function setUp(){
parent::setUp();
$this->cat_id = $this->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 ) );
//set current post (has 2 on each end)
global $GLOBALS;
$GLOBALS['post'] = get_post( $this->post_ids[2] );
}
public function test_get_next_post_link_default() {
$actual = get_next_post_link();
$expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
$this->assertSame( $expected, $actual );
}
public function test_get_previous_post_link_default() {
$actual = get_previous_post_link();
$expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
$this->assertSame( $expected, $actual );
}
public function test_get_next_post_link_same_category() {
$actual = get_next_post_link( '%link &raquo;', '%title', true );
$expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
$this->assertSame( $expected, $actual );
}
public function test_get_previous_post_link_same_category() {
$actual = get_previous_post_link( '&laquo; %link', '%title', true );
$expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
$this->assertSame( $expected, $actual );
}
public function test_get_next_post_link_exclude_category() {
$actual = get_next_post_link( '%link &raquo;', '%title', false, $this->cat_id );
$expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
$this->assertSame( $expected, $actual );
}
public function test_get_previous_post_link_exclude_category() {
$actual = get_previous_post_link( '&laquo; %link', '%title', false, $this->cat_id );
$expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
$this->assertSame( $expected, $actual );
}
}