Files
wordpress-develop/tests/phpunit/tests/canonical/customRules.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

60 lines
1.6 KiB
PHP

<?php
/**
* @group canonical
* @group rewrite
* @group query
*/
class Tests_Canonical_CustomRules extends WP_Canonical_UnitTestCase {
public function set_up() {
parent::set_up();
global $wp_rewrite;
// Add a custom Rewrite rule to test category redirections.
$wp_rewrite->add_rule( 'ccr/(.+?)/sort/(asc|desc)', 'index.php?category_name=$matches[1]&order=$matches[2]', 'top' ); // ccr = Custom_Cat_Rule.
$wp_rewrite->flush_rules();
}
/**
* @dataProvider data
*/
public function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) {
$this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong );
}
public function data() {
/*
* 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
* [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
*/
return array(
// Custom Rewrite rules leading to Categories.
array(
'/ccr/uncategorized/sort/asc/',
array(
'url' => '/ccr/uncategorized/sort/asc/',
'qv' => array(
'category_name' => 'uncategorized',
'order' => 'asc',
),
),
),
array(
'/ccr/uncategorized/sort/desc/',
array(
'url' => '/ccr/uncategorized/sort/desc/',
'qv' => array(
'category_name' => 'uncategorized',
'order' => 'desc',
),
),
),
);
}
}