Add tests for permastruct containing `/%category%/`.

See #36602.

git-svn-id: https://develop.svn.wordpress.org/trunk@37260 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-04-20 14:59:02 +00:00
parent a980543f68
commit ddd88a79b1
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
<?php
/**
* @group canonical
*/
class Tests_Canonical_Category extends WP_Canonical_UnitTestCase {
public $structure = '/%category%/%postname%/';
public static $posts = array();
public static $cats = array();
public static function setUpBeforeClass() {
self::$posts[0] = self::factory()->post->create( array( 'post_name' => 'post0' ) );
self::$posts[1] = self::factory()->post->create( array( 'post_name' => 'post1' ) );
self::$cats[0] = self::factory()->category->create( array( 'slug' => 'cat0' ) );
self::$cats[1] = self::factory()->category->create( array( 'slug' => 'cat1' ) );
self::$cats[2] = self::factory()->category->create( array( 'slug' => 'cat2' ) );
wp_set_post_categories( self::$posts[0], self::$cats[2] );
wp_set_post_categories( self::$posts[0], self::$cats[0] );
wp_set_post_categories( self::$posts[1], self::$cats[1] );
}
public static function tearDownAfterClass() {
foreach ( self::$posts as $post_id ) {
wp_delete_post( $post_id, true );
}
foreach ( self::$cats as $cat ) {
wp_delete_term( $cat, 'category' );
}
}
/**
* @dataProvider data_canonical_category
*/
public function test_canonical_category( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) {
$this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong );
}
public function data_canonical_category() {
/* Data format:
* [0]: Test URL.
* [1]: expected results: Any of the following can be used
* array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
* array( expected query vars to be set, same as 'qv' above )
* (string) expected redirect location
* [2]: (optional) The ticket the test refers to, Can be skipped if unknown.
* [3]: (optional) Array of class/function names expected to throw `_doing_it_wrong()` notices.
*/
return array(
// Valid category.
array( '/cat0/post0/', array( 'url' => '/cat0/post0/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'page' => '' ) ) ),
// Category other than the first one will redirect to first "canonical" category.
array( '/cat2/post0/', array( 'url' => '/cat0/post0/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'page' => '' ) ) ),
// Incorrect category will redirect to correct one.
array( '/cat1/post0/', array( 'url' => '/cat0/post0/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'page' => '' ) ) ),
// Nonexistent category will redirect to correct one.
array( '/foo/post0/', array( 'url' => '/cat0/post0/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'page' => '' ) ) ),
);
}
}