Make WordPress Core

Ticket #29663: 29663-tests.diff

File 29663-tests.diff, 3.0 KB (added by MikeHansenMe, 10 years ago)
  • tests/phpunit/tests/link-template.php

     
     1<?php
     2
     3class Tests_Get_Post_Link extends WP_UnitTestCase {
     4       
     5        var $post_ids;
     6        var $cat_id;
     7
     8        function setUp(){
     9                parent::setUp();
     10                $this->cat_id = $this->factory->category->create( array( 'name' => 'other' ) );
     11                $this->post_ids = array();
     12                $this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 05:32:29', 'category_id' => 1 ) );
     13                $this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 04:32:29', 'category_id' => $this->cat_id ) );
     14                $this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 03:32:29', 'category_id' => 1 ) );
     15                $this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 02:32:29', 'category_id' => $this->cat_id ) );
     16                $this->post_ids[] = $this->factory->post->create( array( 'post_type' => 'post', 'post_date' => '2014-10-26 01:32:29', 'category_id' => 1 ) );
     17
     18                //set current post (has 2 on each end)
     19                global $GLOBALS;
     20                $GLOBALS['post'] = get_post( $this->post_ids[2] );
     21        }
     22
     23        function test_get_next_post_link_default() {
     24                $actual = get_next_post_link();
     25                $expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
     26                $this->assertSame( $expected, $actual );
     27        }
     28
     29        function test_get_previous_post_link_default() {
     30                $actual = get_previous_post_link();
     31                $expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
     32                $this->assertSame( $expected, $actual );
     33        }
     34       
     35        function test_get_next_post_link_same_category() {
     36                $actual = get_next_post_link( '%link &raquo;', '%title', true );
     37                $expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
     38                $this->assertSame( $expected, $actual );
     39        }
     40
     41        function test_get_previous_post_link_same_category() {
     42                $actual = get_previous_post_link( '&laquo; %link', '%title', true );
     43                $expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
     44                $this->assertSame( $expected, $actual );
     45        }
     46       
     47        function test_get_next_post_link_exclude_category() {
     48                $actual = get_next_post_link( '%link &raquo;', '%title', false, $this->cat_id );
     49                $expected = '<a href="http://example.org/?p=' . $this->post_ids[1] . '" rel="next">Post title 2</a> &raquo;';
     50                $this->assertSame( $expected, $actual );
     51        }
     52
     53        function test_get_previous_post_link_exclude_category() {
     54                $actual = get_previous_post_link( '&laquo; %link', '%title', false, $this->cat_id );
     55                $expected = '&laquo; <a href="http://example.org/?p=' . $this->post_ids[3] . '" rel="prev">Post title 4</a>';
     56                $this->assertSame( $expected, $actual );
     57        }
     58}
     59 No newline at end of file