| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group canonical |
| | 5 | */ |
| | 6 | class Tests_Canonical_Feeds extends WP_Canonical_UnitTestCase { |
| | 7 | public $structure = '/%postname%/'; |
| | 8 | |
| | 9 | public static $posts = array(); |
| | 10 | |
| | 11 | public static function wpSetUpBeforeClass( $factory ) { |
| | 12 | |
| | 13 | self::$posts[0] = $factory->post->create( array( 'post_name' => 'post0' ) ); |
| | 14 | |
| | 15 | $c1 = self::factory()->tag->create_and_get( array( |
| | 16 | 'name' => 'Comments', |
| | 17 | 'slug' => 'comments', |
| | 18 | ) ); |
| | 19 | |
| | 20 | $c2 = self::factory()->tag->create_and_get( array( |
| | 21 | 'name' => 'Test Tag', |
| | 22 | 'slug' => 'test', |
| | 23 | ) ); |
| | 24 | |
| | 25 | wp_set_object_terms( self::$posts[0], array( $c1->slug, $c2->slug ), 'post_tag' ); |
| | 26 | } |
| | 27 | |
| | 28 | /** |
| | 29 | * @dataProvider data_canonical_feed |
| | 30 | */ |
| | 31 | public function test_canonical_feed( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { |
| | 32 | global $wp; |
| | 33 | if ( $ticket ) |
| | 34 | $this->knownWPBug( $ticket ); |
| | 35 | |
| | 36 | $this->go_to($test_url); |
| | 37 | |
| | 38 | $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars); |
| | 39 | |
| | 40 | $this->assertEquals( $expected, $query_vars ); |
| | 41 | } |
| | 42 | |
| | 43 | public function data_canonical_feed() { |
| | 44 | /* Data format: |
| | 45 | * [0]: Test URL. |
| | 46 | * [1]: array( expected query vars to be set ) |
| | 47 | * [2]: (optional) The ticket the test refers to, Can be skipped if unknown. |
| | 48 | */ |
| | 49 | |
| | 50 | return array( |
| | 51 | // posts feed for tag 'comments' |
| | 52 | array( '/tag/comments/feed/', array('tag'=>'comments','feed'=>'feed' ), 39535), |
| | 53 | |
| | 54 | // posts feed for tag 'test' |
| | 55 | array( '/tag/test/feed/', array('tag'=>'test','feed'=>'feed' ) ), |
| | 56 | |
| | 57 | // comments feed entire site |
| | 58 | array( '/comments/feed/', array('withcomments'=>'1','feed'=>'feed' ) ), |
| | 59 | |
| | 60 | ); |
| | 61 | } |
| | 62 | } |