WordPress.org

Make WordPress Core

Changeset 364 in tests


Ignore:
Timestamp:
06/03/2011 04:28:49 AM (7 years ago)
Author:
dd32
Message:

2nd wave of Canonical test cases. Expand test harness to handle more compact $expected values for simple redirect tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_canonical.php

    r362 r364  
    5050            $this->knownWPBug($ticket);
    5151
     52        $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null;
     53
     54        if ( is_string($expected) )
     55            $expected = array('url' => $expected);
     56        elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )
     57            $expected = array( 'qv' => $expected );
     58
     59        if ( !isset($expected['url']) && !isset($expected['qv']) )
     60            $this->markTestSkipped('No valid expected output was provided');
     61
    5262        $this->http( get_option('home') . $test_url );
    5363
     
    5767
    5868        // Just test the Path and Query if present
    59         $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : '') );
     69        if ( isset($expected['url']) )
     70            $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref );
    6071       
    6172        // request url is correct, Next, "make" that the request and check the query is correct
    6273        $this->http( $can_url );
    63        
    64         // Are all query vars accounted for, And correct?
    65         global $wp;
    66 
    67         $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
    68         if ( !empty($parsed_can_url['query']) ) {
    69             parse_str($parsed_can_url['query'], $_qv);
    70 
    71             // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
    72             $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET' );
    73            
    74             $query_vars = array_merge($query_vars, $_qv);
    75         }
    76 
    77         $this->assertEquals( $expected['qv'], $query_vars );
     74   
     75        if ( isset($expected['qv']) ) {
     76            // Are all query vars accounted for, And correct?
     77            global $wp;
     78   
     79            $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
     80            if ( !empty($parsed_can_url['query']) ) {
     81                parse_str($parsed_can_url['query'], $_qv);
     82   
     83                // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
     84                $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
     85               
     86                $query_vars = array_merge($query_vars, $_qv);
     87            }
     88   
     89            $this->assertEquals( $expected['qv'], $query_vars );
     90        } //isset $expected['qv']
    7891
    7992    }
    8093
    8194    function data() {
    82         return array( /* Format: [0]: $test_url, [1]: expected results: array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite OR $_GET ); */
     95        return array( /*
     96                        Format: [0]: $test_url,
     97                                [1]: expected results: Any of the following can be used
     98                                        array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite OR $_GET );
     99                                        array( expected query vars to be hit )
     100                                        (string) 'expected redirect url'
     101                                [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
     102                                        */
    83103                // Categories
    84104                array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
     
    95115                array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    96116                array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 17661 ),
     117                array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    97118               
    98119                // Pages
    99                 array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page' ) ), 17653 ),
    100                 array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page' ) ), 14773 ),
     120                array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
     121                array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
     122                array( '/child-page-1/', '/parent-page/child-page-1/'),
     123                array( '/?page_id=144', '/parent-page/child-page-1/'),
     124                array( '/abo', '/about/' ),
    101125               
     126               
     127                // Posts
     128                array( '?p=587', '/2008/06/02/post-format-test-audio/'),
     129                array( '/?name=images-test', '/2008/09/03/images-test/'),
     130                array( '/?pagename=images-test', '/2008/09/03/images-test/'),
     131
     132                array( '/2008/06/02/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
     133                array( '/2008/06/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
     134                array( '/2008/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
     135                array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
     136                array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
     137               
     138                array( '/2008/09/03/images-test/3/', array( 'url' => '/2008/09/03/images-test/3/', 'qv' => array( 'name' => 'images-test', 'year' => '2008', 'monthnum' => '09', 'day' => '03', 'page' => '/3' ) ) ), // page = /3 ?!
     139                array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/' ), // post with 4 pages
     140
     141                // Attachments
     142                array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
     143                array( '/2008/09/03/images-test/canola2/', '/2008/06/10/post-format-test-gallery/canola2/' ), // Image accessed via incorrect parent
     144                array( '/2008/06/10/post-format-test-gallery/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
     145               
     146                // Dates
     147                array( '/?m=2008', '/2008/' ),
     148                array( '/?m=200809', '/2008/09/'),
     149                array( '/?m=20080905', '/2008/09/05/'),
     150                array( '/?m=2008095', '/2008/09/'), // Invalid date, /09/ or /09/05/ perhaps?
     151               
     152                array( '/2008/?day=05', '/2008/?day=05'), // no redirect
     153                array( '/2008/09/?day=05', '/2008/09/05/'),
     154                array( '/2008/?monthnum=9', '/2008/09/'),
     155               
     156                array( '/?year=2008', '/2008/'),
     157               
     158                // Authors
     159                array( '/?author=3', '/author/chip-bennett/' ),
     160                array( '/?author=3&year=2008', '/2008/?author=3'),
     161                array( '/author/chip-bennett/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
     162               
     163
    102164                );
    103165    }
Note: See TracChangeset for help on using the changeset viewer.