Make WordPress Core

Changeset 904 in tests for trunk/tests/canonical.php


Ignore:
Timestamp:
07/18/2012 07:01:41 PM (12 years ago)
Author:
nacin
Message:

Rename tests to conform to this standard: the class Tests_A_B_C.php should be found in Tests/A/B/C.php.

One class per file. Tests are now organized by general component, rather than by the core file they are found in.

Work in progress. Some classes need to be renamed, and some files still need to be moved (and split up).

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/canonical.php

    r903 r904  
    99 * @group query
    1010 */
    11 class WP_Test_Canonical extends WP_UnitTestCase {
     11class Tests_Canonical extends WP_UnitTestCase {
    1212
    1313    // This can be defined in a subclass of this class which contains it's own data() method, those tests will be run against the specified permastruct
     
    273273    }
    274274}
    275 
    276 /**
    277  * @group canonical
    278  * @group rewrite
    279  * @group query
    280  */
    281 class WP_Canonical_PageOnFront extends WP_Test_Canonical {
    282     function setUp() {
    283         parent::setUp();
    284         global $wp_rewrite;
    285         update_option( 'show_on_front', 'page' );
    286         update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
    287         update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
    288         $wp_rewrite->init();
    289         flush_rewrite_rules();
    290     }
    291 
    292     function data() {
    293         /* Format:
    294          * [0]: $test_url,
    295          * [1]: expected results: Any of the following can be used
    296          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    297          *      array( expected query vars to be set, same as 'qv' above )
    298          *      (string) expected redirect location
    299          * [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
    300          */
    301          return array(
    302              // Check against an odd redirect
    303              array( '/page/2/', '/page/2/', 20385 ),
    304              // The page designated as the front page should redirect to the front of the site
    305              array( '/front-page/', '/' ),
    306              array( '/blog-page/?paged=2', '/blog-page/page/2/' ),
    307          );
    308     }
    309 }
    310 
    311 /**
    312  * @group canonical
    313  * @group rewrite
    314  * @group query
    315  */
    316 class WP_Canonical_CustomRules extends WP_Test_Canonical {
    317     function setUp() {
    318         parent::setUp();
    319         global $wp_rewrite;
    320         // Add a custom Rewrite rule to test category redirections.
    321         $wp_rewrite->add_rule('ccr/(.+?)/sort/(asc|desc)', 'index.php?category_name=$matches[1]&order=$matches[2]', 'top'); // ccr = Custom_Cat_Rule
    322         $wp_rewrite->flush_rules();
    323     }
    324 
    325     function data() {
    326         /* Format:
    327          * [0]: $test_url,
    328          * [1]: expected results: Any of the following can be used
    329          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    330          *      array( expected query vars to be set, same as 'qv' above )
    331          *      (string) expected redirect location
    332          * [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
    333          */
    334         return array(
    335             // Custom Rewrite rules leading to Categories
    336             array( '/ccr/uncategorized/sort/asc/', array( 'url' => '/ccr/uncategorized/sort/asc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'asc' ) ) ),
    337             array( '/ccr/uncategorized/sort/desc/', array( 'url' => '/ccr/uncategorized/sort/desc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc' ) ) ),
    338             array( '/ccr/uncategorized/sort/desc/?year=2008', array( 'url' => '/ccr/uncategorized/sort/desc/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc', 'year' => '2008' ) ), 17661 ),
    339         );
    340     }
    341 }
    342 
    343 /**
    344  * @group canonical
    345  * @group rewrite
    346  * @group query
    347  */
    348 class WP_Canonical_NoRewrite extends WP_Test_Canonical {
    349 
    350     var $structure = '';
    351 
    352     // These test cases are run against the test handler in WP_Canonical
    353 
    354     function data() {
    355         /* Format:
    356          * [0]: $test_url,
    357          * [1]: expected results: Any of the following can be used
    358          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    359          *      array( expected query vars to be set, same as 'qv' above )
    360          *      (string) expected redirect location
    361          * [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
    362          */
    363         return array(
    364             array( '/?p=123', '/?p=123' ),
    365 
    366             // This post_type arg should be stripped, because p=1 exists, and does not have post_type= in its query string
    367             array( '/?post_type=fake-cpt&p=1', '/?p=1' ),
    368 
    369             // Strip an existing but incorrect post_type arg
    370             array( '/?post_type=page&page_id=1', '/?p=1' ),
    371 
    372             array( '/?p=358 ', array('url' => '/?p=358',  'qv' => array('p' => '358') ) ), // Trailing spaces
    373             array( '/?p=358%20', array('url' => '/?p=358',  'qv' => array('p' => '358') ) ),
    374 
    375             array( '/?page_id=1', '/?p=1' ), // redirect page_id to p (should cover page_id|p|attachment_id to one another
    376             array( '/?page_id=1&post_type=revision', '/?p=1' ),
    377 
    378         );
    379     }
    380 }
Note: See TracChangeset for help on using the changeset viewer.