From ddd88a79b11cd97b6d8876cc36b25af68ed6ee9c Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 20 Apr 2016 14:59:02 +0000 Subject: [PATCH] Add tests for permastruct containing `/%category%/`. See #36602. git-svn-id: https://develop.svn.wordpress.org/trunk@37260 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/canonical/category.php | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/phpunit/tests/canonical/category.php diff --git a/tests/phpunit/tests/canonical/category.php b/tests/phpunit/tests/canonical/category.php new file mode 100644 index 0000000000..cb0363eef2 --- /dev/null +++ b/tests/phpunit/tests/canonical/category.php @@ -0,0 +1,67 @@ +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' => '' ) ) ), + ); + } +}