Make WordPress Core

Changeset 904 in tests


Ignore:
Timestamp:
07/18/2012 07:01:41 PM (10 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).

Location:
trunk/tests
Files:
16 added
8 deleted
1 edited
16 copied
67 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/admin/includesPlugin.php

    r903 r904  
    44 * @group admin
    55 */
    6 class TestPluginData extends WP_UnitTestCase {
     6class Tests_Admin_includesPlugin extends WP_UnitTestCase {
    77    function test_get_plugin_data() {
    88        $data = get_plugin_data( DIR_TESTDATA . '/plugins/hello.php' );
     
    2727        }
    2828    }
    29 }
    30 
    31 /**
    32  * @group plugins
    33  * @group admin
    34  */
    35 class TestPluginMenus extends WP_UnitTestCase {
    36 
    37     protected $current_user;
    38 
    39     function setUp() {
    40         parent::setUp();
    41         $this->current_user = get_current_user_id();
    42         // pages require manage_options, ensure we're an administrator
    43         $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    44         wp_set_current_user( $user_id );
    45         update_option( 'siteurl', 'http://example.com' );
    46     }
    47 
    48     function tearDown() {
    49         parent::tearDown();
    50         wp_set_current_user( $this->current_user );
    51     }
    5229
    5330    function test_menu_page_url() {
     31        $current_user = get_current_user_id();
     32        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     33        update_option( 'siteurl', 'http://example.com' );
     34
    5435        // add some pages
    5536        add_options_page( 'Test Settings', 'Test Settings', 'manage_options', 'testsettings', 'mt_settings_page' );
     
    7354            $this->assertEquals( $value, menu_page_url( $name, false ) );
    7455        }
     56
     57        wp_set_current_user( $current_user );
    7558    }
    7659}
  • trunk/tests/adminbar.php

    r903 r904  
    66 * @group admin
    77 */
    8 class TestWPAdminBar extends WP_UnitTestCase {
     8class Tests_AdminBar extends WP_UnitTestCase {
    99
    1010    static function setUpBeforeClass() {
  • trunk/tests/ajax/Autosave.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxSaveDraft extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/CompressionTest.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCompressionTest extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_CompressionTest extends WP_Ajax_UnitTestCase {
    1818   
    1919    /**
  • trunk/tests/ajax/DeleteComment.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCommentsDelete extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/DimComment.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCommentsDim extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/EditComment.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCommentsEdit extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_EditComments extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/GetComments.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCommentsGet extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/ReplytoComment.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxCommentsReply extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/ajax/TagSearch.php

    r903 r904  
    44 * Admin ajax functions to be tested
    55 */
    6 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     6require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
     
    1515 * @runTestsInSeparateProcesses
    1616 */
    17 class TestAjaxTagSearch extends WP_Ajax_UnitTestCase {
     17class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
    1818
    1919    /**
  • trunk/tests/basic.php

    r903 r904  
    66 * @group testsuite
    77 */
    8 class WPTestMeta extends WP_UnitTestCase {
     8class Tests_Basic extends WP_UnitTestCase {
    99    var $val;
    1010
     
    4444    }
    4545
    46 }
    47 
    48 /**
    49  * test helper utility functions
    50  *
    51  * @group testsuite
    52  */
    53 class WPTestUtils extends WP_UnitTestCase {
     46    // test some helper utility functions
    5447
    5548    function test_strip_ws() {
  • 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 }
  • trunk/tests/canonical/customRules.php

    r903 r904  
    11<?php
    2 /**
    3  * Tests Canonical redirections.
    4  *
    5  * In the process of doing so, it also tests WP, WP_Rewrite and WP_Query, A fail here may show a bug in any one of these areas.
    6  *
    7  * @group canonical
    8  * @group rewrite
    9  * @group query
    10  */
    11 class WP_Test_Canonical extends WP_UnitTestCase {
    122
    13     // 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
    14     var $structure = '/%year%/%monthnum%/%day%/%postname%/';
    15 
    16     var $old_current_user;
    17     var $author_id;
    18     var $post_ids;
    19     var $term_ids;
    20 
    21     function setUp() {
    22         parent::setUp();
    23 
    24         update_option( 'comments_per_page', 5 );
    25         update_option( 'posts_per_page', 5 );
    26 
    27         update_option( 'permalink_structure', $this->structure );
    28         create_initial_taxonomies();
    29         $GLOBALS['wp_rewrite']->init();
    30         flush_rewrite_rules();
    31 
    32         $this->old_current_user = get_current_user_id();
    33         $this->author_id = $this->factory->user->create( array( 'user_login' => 'canonical-author' ) );
    34         wp_set_current_user( $this->author_id );
    35 
    36         // Already created by install defaults:
    37         // $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) );
    38 
    39         $this->term_ids = array();
    40 
    41         $this->factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) );
    42         $post_id = $this->factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) );
    43         $this->factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) );
    44 
    45         $this->factory->post->create( array(
    46             'post_title' => 'images-test',
    47             'post_date' => '2008-09-03 00:00:00',
    48             'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3'
    49         ) );
    50 
    51         $post_id = $this->factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) );
    52         $this->factory->comment->create_post_comments( $post_id, 15 );
    53 
    54         $this->factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) );
    55 
    56         $this->factory->post->create( array( 'import_id' => 123 ) );
    57         $this->factory->post->create( array( 'import_id' => 1 ) );
    58         $this->factory->post->create( array( 'import_id' => 358 ) );
    59 
    60         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) );
    61         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) );
    62         $post_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
    63         $this->factory->post->create(
    64             array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id,
    65         ) );
    66 
    67         $this->term_ids['/category/parent/'] = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) );
    68         $this->term_ids['/category/parent/child-1/'] = $this->factory->term->create( array(
    69             'taxonomy' => 'category', 'name' => 'child-1', 'parent' => $this->term_ids['/category/parent/'],
    70         ) );
    71         $this->term_ids['/category/parent/child-1/child-2/'] = $this->factory->term->create( array(
    72             'taxonomy' => 'category', 'name' => 'child-2', 'parent' => $this->term_ids['/category/parent/child-1/'],
    73         ) );
    74 
    75         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) );
    76         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) );
    77 
    78         $this->factory->term->create( array( 'name' => 'post-formats' ) );
    79     }
    80 
    81     function tearDown() {
    82         parent::tearDown();
    83         wp_set_current_user( $this->old_current_user );
    84 
    85         $GLOBALS['wp_rewrite']->init();
    86     }
    87 
    88     // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..
    89     // Return url's are full url's with the prepended home.
    90     function get_canonical($test_url) {
    91         $test_url = home_url( $test_url );
    92 
    93         $can_url = redirect_canonical( $test_url, false );
    94         if ( ! $can_url )
    95             return $test_url; // No redirect will take place for this request
    96 
    97         return $can_url;
    98     }
    99 
    100     /**
    101      * @dataProvider data
    102      */
    103     function test($test_url, $expected, $ticket = 0) {
    104         if ( $ticket )
    105             $this->knownWPBug( $ticket );
    106 
    107         $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null;
    108 
    109         if ( is_string($expected) )
    110             $expected = array('url' => $expected);
    111         elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )
    112             $expected = array( 'qv' => $expected );
    113 
    114         if ( !isset($expected['url']) && !isset($expected['qv']) )
    115             $this->markTestSkipped('No valid expected output was provided');
    116 
    117         if ( false !== strpos( $test_url, '%d' ) ) {
    118             if ( false !== strpos( $test_url, '/?author=%d' ) )
    119                 $test_url = sprintf( $test_url, $this->author_id );
    120             if ( false !== strpos( $test_url, '?cat=%d' ) )
    121                 $test_url = sprintf( $test_url, $this->term_ids[ $expected['url'] ] );
    122         }
    123 
    124         $this->go_to( home_url( $test_url ) );
    125 
    126         // Does the redirect match what's expected?
    127         $can_url = $this->get_canonical( $test_url );
    128         $parsed_can_url = parse_url($can_url);
    129 
    130         // Just test the Path and Query if present
    131         if ( isset($expected['url']) )
    132             $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref );
    133 
    134         if ( ! isset($expected['qv']) )
    135             return;
    136 
    137         // "make" that the request and check the query is correct
    138         $this->go_to( $can_url );
    139 
    140         // Are all query vars accounted for, And correct?
    141         global $wp;
    142 
    143         $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
    144         if ( !empty($parsed_can_url['query']) ) {
    145             parse_str($parsed_can_url['query'], $_qv);
    146 
    147             // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
    148             $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
    149 
    150             $query_vars = array_merge($query_vars, $_qv);
    151         }
    152 
    153         $this->assertEquals( $expected['qv'], $query_vars );
    154     }
    155 
    156     function data() {
    157         /* Data format:
    158          * [0]: $test_url,
    159          * [1]: expected results: Any of the following can be used
    160          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    161          *      array( expected query vars to be set, same as 'qv' above )
    162          *      (string) expected redirect location
    163          * [2]: (optional) The ticket the test refers to, Can be skipped if unknown.
    164          */
    165 
    166         // Please Note: A few test cases are commented out below, Look at the test case following it, in most cases it's simple showing 2 options for the "proper" redirect.
    167         return array(
    168             // Categories
    169 
    170             array( '?cat=%d', '/category/parent/', 15256 ),
    171             array( '?cat=%d', '/category/parent/child-1/', 15256 ),
    172             array( '?cat=%d', '/category/parent/child-1/child-2/' ), // no children
    173             array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
    174             array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    175             array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    176             array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
    177             array( '/category/child-1/', '/category/parent/child-1/', 18734 ),
    178             array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),
    179 
    180             // Categories & Intersections with other vars
    181             array( '/category/uncategorized/?tag=post-formats', array( 'url' => '/category/uncategorized/?tag=post-formats', 'qv' => array('category_name' => 'uncategorized', 'tag' => 'post-formats') ) ),
    182             array( '/?category_name=cat-a,cat-b', array( 'url' => '/?category_name=cat-a,cat-b', 'qv' => array( 'category_name' => 'cat-a,cat-b' ) ) ),
    183 
    184             // Taxonomies with extra Query Vars
    185             array( '/category/cat-a/page/1/?test=one%20two', '/category/cat-a/?test=one%20two', 18086), // Extra query vars should stay encoded
    186 
    187             // Categories with Dates
    188             array( '/category/uncategorized/?paged=2&year=2008', array( 'url' => '/category/uncategorized/page/2/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2, 'year' => 2008) ), 17661 ),
    189 //          array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    190             array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    191 //          array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
    192             array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),
    193 //          array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    194             array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    195 
    196             // Pages
    197             array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
    198             array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    199             array( '/child-page-1/', '/parent-page/child-page-1/'),
    200             array( '/?page_id=144', '/parent-page/child-page-1/'),
    201             array( '/abo', '/about/' ),
    202 
    203             // Posts
    204             array( '?p=587', '/2008/06/02/post-format-test-audio/'),
    205             array( '/?name=images-test', '/2008/09/03/images-test/'),
    206             // Incomplete slug should resolve and remove the ?name= parameter
    207             array( '/?name=images-te', '/2008/09/03/images-test/', 20374),
    208             // Page slug should resolve to post slug and remove the ?pagename= parameter
    209             array( '/?pagename=images-test', '/2008/09/03/images-test/', 20374),
    210 
    211             array( '/2008/06/02/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    212             array( '/2008/06/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    213             array( '/2008/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    214             array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
    215             array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    216 
    217             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 ?!
    218             array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages
    219             array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
    220             array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
    221 
    222             // Comments
    223             array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/', 20388 ),
    224             array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    225             array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    226 
    227             // Attachments
    228             array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    229             array( '/2008/06/10/post-format-test-gallery/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    230 
    231             // Dates
    232             array( '/?m=2008', '/2008/' ),
    233             array( '/?m=200809', '/2008/09/'),
    234             array( '/?m=20080905', '/2008/09/05/'),
    235 
    236             array( '/2008/?day=05', '/2008/?day=05'), // no redirect
    237             array( '/2008/09/?day=05', '/2008/09/05/'),
    238             array( '/2008/?monthnum=9', '/2008/09/'),
    239 
    240             array( '/?year=2008', '/2008/'),
    241 
    242             // Authors
    243             array( '/?author=%d', '/author/canonical-author/' ),
    244 //          array( '/?author=%d&year=2008', '/2008/?author=3'),
    245             array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),
    246 //          array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
    247             array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),
    248 
    249             // Feeds
    250             array( '/?feed=atom', '/feed/atom/' ),
    251             array( '/?feed=rss2', '/feed/' ),
    252             array( '/?feed=comments-rss2', '/comments/feed/'),
    253             array( '/?feed=comments-atom', '/comments/feed/atom/'),
    254 
    255             // Feeds (per-post)
    256             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    257             array( '/?p=149&feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    258             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/' ),
    259 
    260             // Index
    261             array( '/?paged=1', '/' ),
    262             array( '/page/1/', '/' ),
    263             array( '/page1/', '/' ),
    264             array( '/?paged=2', '/page/2/' ),
    265             array( '/page2/', '/page/2/' ),
    266 
    267             // Misc
    268             array( '/2008%20', '/2008' ),
    269             array( '//2008////', '/2008/' ),
    270 
    271             // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
    272         );
    273     }
    274 }
     3require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';
    2754
    2765/**
     
    2798 * @group query
    2809 */
    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 {
     10class Tests_Canonical_CustomRules extends Tests_Canonical {
    31711    function setUp() {
    31812        parent::setUp();
     
    34034    }
    34135}
    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 }
  • trunk/tests/canonical/noRewrite.php

    r903 r904  
    11<?php
    2 /**
    3  * Tests Canonical redirections.
    4  *
    5  * In the process of doing so, it also tests WP, WP_Rewrite and WP_Query, A fail here may show a bug in any one of these areas.
    6  *
    7  * @group canonical
    8  * @group rewrite
    9  * @group query
    10  */
    11 class WP_Test_Canonical extends WP_UnitTestCase {
    122
    13     // 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
    14     var $structure = '/%year%/%monthnum%/%day%/%postname%/';
    15 
    16     var $old_current_user;
    17     var $author_id;
    18     var $post_ids;
    19     var $term_ids;
    20 
    21     function setUp() {
    22         parent::setUp();
    23 
    24         update_option( 'comments_per_page', 5 );
    25         update_option( 'posts_per_page', 5 );
    26 
    27         update_option( 'permalink_structure', $this->structure );
    28         create_initial_taxonomies();
    29         $GLOBALS['wp_rewrite']->init();
    30         flush_rewrite_rules();
    31 
    32         $this->old_current_user = get_current_user_id();
    33         $this->author_id = $this->factory->user->create( array( 'user_login' => 'canonical-author' ) );
    34         wp_set_current_user( $this->author_id );
    35 
    36         // Already created by install defaults:
    37         // $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) );
    38 
    39         $this->term_ids = array();
    40 
    41         $this->factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) );
    42         $post_id = $this->factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) );
    43         $this->factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) );
    44 
    45         $this->factory->post->create( array(
    46             'post_title' => 'images-test',
    47             'post_date' => '2008-09-03 00:00:00',
    48             'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3'
    49         ) );
    50 
    51         $post_id = $this->factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) );
    52         $this->factory->comment->create_post_comments( $post_id, 15 );
    53 
    54         $this->factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) );
    55 
    56         $this->factory->post->create( array( 'import_id' => 123 ) );
    57         $this->factory->post->create( array( 'import_id' => 1 ) );
    58         $this->factory->post->create( array( 'import_id' => 358 ) );
    59 
    60         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) );
    61         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) );
    62         $post_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
    63         $this->factory->post->create(
    64             array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id,
    65         ) );
    66 
    67         $this->term_ids['/category/parent/'] = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) );
    68         $this->term_ids['/category/parent/child-1/'] = $this->factory->term->create( array(
    69             'taxonomy' => 'category', 'name' => 'child-1', 'parent' => $this->term_ids['/category/parent/'],
    70         ) );
    71         $this->term_ids['/category/parent/child-1/child-2/'] = $this->factory->term->create( array(
    72             'taxonomy' => 'category', 'name' => 'child-2', 'parent' => $this->term_ids['/category/parent/child-1/'],
    73         ) );
    74 
    75         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) );
    76         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) );
    77 
    78         $this->factory->term->create( array( 'name' => 'post-formats' ) );
    79     }
    80 
    81     function tearDown() {
    82         parent::tearDown();
    83         wp_set_current_user( $this->old_current_user );
    84 
    85         $GLOBALS['wp_rewrite']->init();
    86     }
    87 
    88     // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..
    89     // Return url's are full url's with the prepended home.
    90     function get_canonical($test_url) {
    91         $test_url = home_url( $test_url );
    92 
    93         $can_url = redirect_canonical( $test_url, false );
    94         if ( ! $can_url )
    95             return $test_url; // No redirect will take place for this request
    96 
    97         return $can_url;
    98     }
    99 
    100     /**
    101      * @dataProvider data
    102      */
    103     function test($test_url, $expected, $ticket = 0) {
    104         if ( $ticket )
    105             $this->knownWPBug( $ticket );
    106 
    107         $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null;
    108 
    109         if ( is_string($expected) )
    110             $expected = array('url' => $expected);
    111         elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )
    112             $expected = array( 'qv' => $expected );
    113 
    114         if ( !isset($expected['url']) && !isset($expected['qv']) )
    115             $this->markTestSkipped('No valid expected output was provided');
    116 
    117         if ( false !== strpos( $test_url, '%d' ) ) {
    118             if ( false !== strpos( $test_url, '/?author=%d' ) )
    119                 $test_url = sprintf( $test_url, $this->author_id );
    120             if ( false !== strpos( $test_url, '?cat=%d' ) )
    121                 $test_url = sprintf( $test_url, $this->term_ids[ $expected['url'] ] );
    122         }
    123 
    124         $this->go_to( home_url( $test_url ) );
    125 
    126         // Does the redirect match what's expected?
    127         $can_url = $this->get_canonical( $test_url );
    128         $parsed_can_url = parse_url($can_url);
    129 
    130         // Just test the Path and Query if present
    131         if ( isset($expected['url']) )
    132             $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref );
    133 
    134         if ( ! isset($expected['qv']) )
    135             return;
    136 
    137         // "make" that the request and check the query is correct
    138         $this->go_to( $can_url );
    139 
    140         // Are all query vars accounted for, And correct?
    141         global $wp;
    142 
    143         $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
    144         if ( !empty($parsed_can_url['query']) ) {
    145             parse_str($parsed_can_url['query'], $_qv);
    146 
    147             // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
    148             $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
    149 
    150             $query_vars = array_merge($query_vars, $_qv);
    151         }
    152 
    153         $this->assertEquals( $expected['qv'], $query_vars );
    154     }
    155 
    156     function data() {
    157         /* Data format:
    158          * [0]: $test_url,
    159          * [1]: expected results: Any of the following can be used
    160          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    161          *      array( expected query vars to be set, same as 'qv' above )
    162          *      (string) expected redirect location
    163          * [2]: (optional) The ticket the test refers to, Can be skipped if unknown.
    164          */
    165 
    166         // Please Note: A few test cases are commented out below, Look at the test case following it, in most cases it's simple showing 2 options for the "proper" redirect.
    167         return array(
    168             // Categories
    169 
    170             array( '?cat=%d', '/category/parent/', 15256 ),
    171             array( '?cat=%d', '/category/parent/child-1/', 15256 ),
    172             array( '?cat=%d', '/category/parent/child-1/child-2/' ), // no children
    173             array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
    174             array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    175             array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    176             array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
    177             array( '/category/child-1/', '/category/parent/child-1/', 18734 ),
    178             array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),
    179 
    180             // Categories & Intersections with other vars
    181             array( '/category/uncategorized/?tag=post-formats', array( 'url' => '/category/uncategorized/?tag=post-formats', 'qv' => array('category_name' => 'uncategorized', 'tag' => 'post-formats') ) ),
    182             array( '/?category_name=cat-a,cat-b', array( 'url' => '/?category_name=cat-a,cat-b', 'qv' => array( 'category_name' => 'cat-a,cat-b' ) ) ),
    183 
    184             // Taxonomies with extra Query Vars
    185             array( '/category/cat-a/page/1/?test=one%20two', '/category/cat-a/?test=one%20two', 18086), // Extra query vars should stay encoded
    186 
    187             // Categories with Dates
    188             array( '/category/uncategorized/?paged=2&year=2008', array( 'url' => '/category/uncategorized/page/2/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2, 'year' => 2008) ), 17661 ),
    189 //          array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    190             array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    191 //          array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
    192             array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),
    193 //          array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    194             array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    195 
    196             // Pages
    197             array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
    198             array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    199             array( '/child-page-1/', '/parent-page/child-page-1/'),
    200             array( '/?page_id=144', '/parent-page/child-page-1/'),
    201             array( '/abo', '/about/' ),
    202 
    203             // Posts
    204             array( '?p=587', '/2008/06/02/post-format-test-audio/'),
    205             array( '/?name=images-test', '/2008/09/03/images-test/'),
    206             // Incomplete slug should resolve and remove the ?name= parameter
    207             array( '/?name=images-te', '/2008/09/03/images-test/', 20374),
    208             // Page slug should resolve to post slug and remove the ?pagename= parameter
    209             array( '/?pagename=images-test', '/2008/09/03/images-test/', 20374),
    210 
    211             array( '/2008/06/02/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    212             array( '/2008/06/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    213             array( '/2008/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    214             array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
    215             array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    216 
    217             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 ?!
    218             array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages
    219             array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
    220             array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
    221 
    222             // Comments
    223             array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/', 20388 ),
    224             array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    225             array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    226 
    227             // Attachments
    228             array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    229             array( '/2008/06/10/post-format-test-gallery/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    230 
    231             // Dates
    232             array( '/?m=2008', '/2008/' ),
    233             array( '/?m=200809', '/2008/09/'),
    234             array( '/?m=20080905', '/2008/09/05/'),
    235 
    236             array( '/2008/?day=05', '/2008/?day=05'), // no redirect
    237             array( '/2008/09/?day=05', '/2008/09/05/'),
    238             array( '/2008/?monthnum=9', '/2008/09/'),
    239 
    240             array( '/?year=2008', '/2008/'),
    241 
    242             // Authors
    243             array( '/?author=%d', '/author/canonical-author/' ),
    244 //          array( '/?author=%d&year=2008', '/2008/?author=3'),
    245             array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),
    246 //          array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
    247             array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),
    248 
    249             // Feeds
    250             array( '/?feed=atom', '/feed/atom/' ),
    251             array( '/?feed=rss2', '/feed/' ),
    252             array( '/?feed=comments-rss2', '/comments/feed/'),
    253             array( '/?feed=comments-atom', '/comments/feed/atom/'),
    254 
    255             // Feeds (per-post)
    256             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    257             array( '/?p=149&feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    258             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/' ),
    259 
    260             // Index
    261             array( '/?paged=1', '/' ),
    262             array( '/page/1/', '/' ),
    263             array( '/page1/', '/' ),
    264             array( '/?paged=2', '/page/2/' ),
    265             array( '/page2/', '/page/2/' ),
    266 
    267             // Misc
    268             array( '/2008%20', '/2008' ),
    269             array( '//2008////', '/2008/' ),
    270 
    271             // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
    272         );
    273     }
    274 }
     3require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';
    2754
    2765/**
     
    2798 * @group query
    2809 */
    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 {
     10class Tests_Canonical_NoRewrite extends Tests_Canonical {
    34911
    35012    var $structure = '';
  • trunk/tests/canonical/pageOnFront.php

    r903 r904  
    11<?php
    2 /**
    3  * Tests Canonical redirections.
    4  *
    5  * In the process of doing so, it also tests WP, WP_Rewrite and WP_Query, A fail here may show a bug in any one of these areas.
    6  *
    7  * @group canonical
    8  * @group rewrite
    9  * @group query
    10  */
    11 class WP_Test_Canonical extends WP_UnitTestCase {
    122
    13     // 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
    14     var $structure = '/%year%/%monthnum%/%day%/%postname%/';
    15 
    16     var $old_current_user;
    17     var $author_id;
    18     var $post_ids;
    19     var $term_ids;
    20 
    21     function setUp() {
    22         parent::setUp();
    23 
    24         update_option( 'comments_per_page', 5 );
    25         update_option( 'posts_per_page', 5 );
    26 
    27         update_option( 'permalink_structure', $this->structure );
    28         create_initial_taxonomies();
    29         $GLOBALS['wp_rewrite']->init();
    30         flush_rewrite_rules();
    31 
    32         $this->old_current_user = get_current_user_id();
    33         $this->author_id = $this->factory->user->create( array( 'user_login' => 'canonical-author' ) );
    34         wp_set_current_user( $this->author_id );
    35 
    36         // Already created by install defaults:
    37         // $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) );
    38 
    39         $this->term_ids = array();
    40 
    41         $this->factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) );
    42         $post_id = $this->factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) );
    43         $this->factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) );
    44 
    45         $this->factory->post->create( array(
    46             'post_title' => 'images-test',
    47             'post_date' => '2008-09-03 00:00:00',
    48             'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3'
    49         ) );
    50 
    51         $post_id = $this->factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) );
    52         $this->factory->comment->create_post_comments( $post_id, 15 );
    53 
    54         $this->factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) );
    55 
    56         $this->factory->post->create( array( 'import_id' => 123 ) );
    57         $this->factory->post->create( array( 'import_id' => 1 ) );
    58         $this->factory->post->create( array( 'import_id' => 358 ) );
    59 
    60         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) );
    61         $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) );
    62         $post_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
    63         $this->factory->post->create(
    64             array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id,
    65         ) );
    66 
    67         $this->term_ids['/category/parent/'] = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) );
    68         $this->term_ids['/category/parent/child-1/'] = $this->factory->term->create( array(
    69             'taxonomy' => 'category', 'name' => 'child-1', 'parent' => $this->term_ids['/category/parent/'],
    70         ) );
    71         $this->term_ids['/category/parent/child-1/child-2/'] = $this->factory->term->create( array(
    72             'taxonomy' => 'category', 'name' => 'child-2', 'parent' => $this->term_ids['/category/parent/child-1/'],
    73         ) );
    74 
    75         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) );
    76         $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) );
    77 
    78         $this->factory->term->create( array( 'name' => 'post-formats' ) );
    79     }
    80 
    81     function tearDown() {
    82         parent::tearDown();
    83         wp_set_current_user( $this->old_current_user );
    84 
    85         $GLOBALS['wp_rewrite']->init();
    86     }
    87 
    88     // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..
    89     // Return url's are full url's with the prepended home.
    90     function get_canonical($test_url) {
    91         $test_url = home_url( $test_url );
    92 
    93         $can_url = redirect_canonical( $test_url, false );
    94         if ( ! $can_url )
    95             return $test_url; // No redirect will take place for this request
    96 
    97         return $can_url;
    98     }
    99 
    100     /**
    101      * @dataProvider data
    102      */
    103     function test($test_url, $expected, $ticket = 0) {
    104         if ( $ticket )
    105             $this->knownWPBug( $ticket );
    106 
    107         $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null;
    108 
    109         if ( is_string($expected) )
    110             $expected = array('url' => $expected);
    111         elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )
    112             $expected = array( 'qv' => $expected );
    113 
    114         if ( !isset($expected['url']) && !isset($expected['qv']) )
    115             $this->markTestSkipped('No valid expected output was provided');
    116 
    117         if ( false !== strpos( $test_url, '%d' ) ) {
    118             if ( false !== strpos( $test_url, '/?author=%d' ) )
    119                 $test_url = sprintf( $test_url, $this->author_id );
    120             if ( false !== strpos( $test_url, '?cat=%d' ) )
    121                 $test_url = sprintf( $test_url, $this->term_ids[ $expected['url'] ] );
    122         }
    123 
    124         $this->go_to( home_url( $test_url ) );
    125 
    126         // Does the redirect match what's expected?
    127         $can_url = $this->get_canonical( $test_url );
    128         $parsed_can_url = parse_url($can_url);
    129 
    130         // Just test the Path and Query if present
    131         if ( isset($expected['url']) )
    132             $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref );
    133 
    134         if ( ! isset($expected['qv']) )
    135             return;
    136 
    137         // "make" that the request and check the query is correct
    138         $this->go_to( $can_url );
    139 
    140         // Are all query vars accounted for, And correct?
    141         global $wp;
    142 
    143         $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
    144         if ( !empty($parsed_can_url['query']) ) {
    145             parse_str($parsed_can_url['query'], $_qv);
    146 
    147             // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
    148             $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
    149 
    150             $query_vars = array_merge($query_vars, $_qv);
    151         }
    152 
    153         $this->assertEquals( $expected['qv'], $query_vars );
    154     }
    155 
    156     function data() {
    157         /* Data format:
    158          * [0]: $test_url,
    159          * [1]: expected results: Any of the following can be used
    160          *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    161          *      array( expected query vars to be set, same as 'qv' above )
    162          *      (string) expected redirect location
    163          * [2]: (optional) The ticket the test refers to, Can be skipped if unknown.
    164          */
    165 
    166         // Please Note: A few test cases are commented out below, Look at the test case following it, in most cases it's simple showing 2 options for the "proper" redirect.
    167         return array(
    168             // Categories
    169 
    170             array( '?cat=%d', '/category/parent/', 15256 ),
    171             array( '?cat=%d', '/category/parent/child-1/', 15256 ),
    172             array( '?cat=%d', '/category/parent/child-1/child-2/' ), // no children
    173             array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
    174             array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    175             array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    176             array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
    177             array( '/category/child-1/', '/category/parent/child-1/', 18734 ),
    178             array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),
    179 
    180             // Categories & Intersections with other vars
    181             array( '/category/uncategorized/?tag=post-formats', array( 'url' => '/category/uncategorized/?tag=post-formats', 'qv' => array('category_name' => 'uncategorized', 'tag' => 'post-formats') ) ),
    182             array( '/?category_name=cat-a,cat-b', array( 'url' => '/?category_name=cat-a,cat-b', 'qv' => array( 'category_name' => 'cat-a,cat-b' ) ) ),
    183 
    184             // Taxonomies with extra Query Vars
    185             array( '/category/cat-a/page/1/?test=one%20two', '/category/cat-a/?test=one%20two', 18086), // Extra query vars should stay encoded
    186 
    187             // Categories with Dates
    188             array( '/category/uncategorized/?paged=2&year=2008', array( 'url' => '/category/uncategorized/page/2/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2, 'year' => 2008) ), 17661 ),
    189 //          array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    190             array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    191 //          array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
    192             array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),
    193 //          array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    194             array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    195 
    196             // Pages
    197             array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
    198             array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    199             array( '/child-page-1/', '/parent-page/child-page-1/'),
    200             array( '/?page_id=144', '/parent-page/child-page-1/'),
    201             array( '/abo', '/about/' ),
    202 
    203             // Posts
    204             array( '?p=587', '/2008/06/02/post-format-test-audio/'),
    205             array( '/?name=images-test', '/2008/09/03/images-test/'),
    206             // Incomplete slug should resolve and remove the ?name= parameter
    207             array( '/?name=images-te', '/2008/09/03/images-test/', 20374),
    208             // Page slug should resolve to post slug and remove the ?pagename= parameter
    209             array( '/?pagename=images-test', '/2008/09/03/images-test/', 20374),
    210 
    211             array( '/2008/06/02/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    212             array( '/2008/06/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    213             array( '/2008/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    214             array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
    215             array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
    216 
    217             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 ?!
    218             array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages
    219             array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
    220             array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
    221 
    222             // Comments
    223             array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/', 20388 ),
    224             array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    225             array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    226 
    227             // Attachments
    228             array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    229             array( '/2008/06/10/post-format-test-gallery/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
    230 
    231             // Dates
    232             array( '/?m=2008', '/2008/' ),
    233             array( '/?m=200809', '/2008/09/'),
    234             array( '/?m=20080905', '/2008/09/05/'),
    235 
    236             array( '/2008/?day=05', '/2008/?day=05'), // no redirect
    237             array( '/2008/09/?day=05', '/2008/09/05/'),
    238             array( '/2008/?monthnum=9', '/2008/09/'),
    239 
    240             array( '/?year=2008', '/2008/'),
    241 
    242             // Authors
    243             array( '/?author=%d', '/author/canonical-author/' ),
    244 //          array( '/?author=%d&year=2008', '/2008/?author=3'),
    245             array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),
    246 //          array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
    247             array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),
    248 
    249             // Feeds
    250             array( '/?feed=atom', '/feed/atom/' ),
    251             array( '/?feed=rss2', '/feed/' ),
    252             array( '/?feed=comments-rss2', '/comments/feed/'),
    253             array( '/?feed=comments-atom', '/comments/feed/atom/'),
    254 
    255             // Feeds (per-post)
    256             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    257             array( '/?p=149&feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
    258             array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/' ),
    259 
    260             // Index
    261             array( '/?paged=1', '/' ),
    262             array( '/page/1/', '/' ),
    263             array( '/page1/', '/' ),
    264             array( '/?paged=2', '/page/2/' ),
    265             array( '/page2/', '/page/2/' ),
    266 
    267             // Misc
    268             array( '/2008%20', '/2008' ),
    269             array( '//2008////', '/2008/' ),
    270 
    271             // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
    272         );
    273     }
    274 }
     3require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';
    2754
    2765/**
     
    2798 * @group query
    2809 */
    281 class WP_Canonical_PageOnFront extends WP_Test_Canonical {
     10class Tests_Canonical_PageOnFront extends Tests_Canonical {
    28211    function setUp() {
    28312        parent::setUp();
     
    30837    }
    30938}
    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 }
  • trunk/tests/compat.php

    r903 r904  
    44 * @group compat
    55 */
    6 class TestMbSubStr extends WP_UnitTestCase {
    7     function test_mb_strcut() {
     6class Tests_Compat extends WP_UnitTestCase {
     7    function test_mb_substr() {
    88        $this->assertEquals('баб', _mb_substr('баба', 0, 3));
    99        $this->assertEquals('баб', _mb_substr('баба', 0, -1));
     
    1111        $this->assertEquals('I am your б', _mb_substr('I am your баба', 0, 11));
    1212    }
    13 }
    1413
    15 /**
    16  * @group compat
    17  */
    18 class TestHashHMAC extends WP_UnitTestCase {
    19     function test_simple() {
     14    function test_hash_hmac_simple() {
    2015        $this->assertEquals('140d1cb79fa12e2a31f32d35ad0a2723', _hash_hmac('md5', 'simple', 'key'));
    2116        $this->assertEquals('993003b95758e0ac2eba451a4c5877eb1bb7b92a', _hash_hmac('sha1', 'simple', 'key'));
    2217    }
    2318
    24     function test_key_padding() {
     19    function test_hash_hmac_padding() {
    2520        $this->assertEquals('3c1399103807cf12ec38228614416a8c', _hash_hmac('md5', 'simple', '65 character key 65 character key 65 character key 65 character k'));
    2621        $this->assertEquals('4428826d20003e309d6c2a6515891370daf184ea', _hash_hmac('sha1', 'simple', '65 character key 65 character key 65 character key 65 character k'));
    2722    }
    2823
    29     function test_raw_output() {
     24    function test_hash_hmac_output() {
    3025        $this->assertEquals(array( 1 => '140d1cb79fa12e2a31f32d35ad0a2723'), unpack('H32', _hash_hmac('md5', 'simple', 'key', true)));
    3126        $this->assertEquals(array( 1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a'), unpack('H40', _hash_hmac('sha1', 'simple', 'key', true)));
  • trunk/tests/cron.php

    r903 r904  
    66 * @group cron
    77 */
    8 class WPTestCronScheduling extends WP_UnitTestCase {
     8class Tests_Cron extends WP_UnitTestCase {
    99    function setUp() {
    1010        parent::setUp();
  • trunk/tests/dependencies.php

    r903 r904  
    44 * @group scripts
    55 */
    6 class TestWP_Dependencies extends WP_UnitTestCase {
     6class Tests_Dependencies extends WP_UnitTestCase {
    77    function test_add() {
    88        // Create a new object
  • trunk/tests/feed/rss2.php

    r903 r904  
    99 * @group feed
    1010 */
    11 class TestFeedRss2 extends WP_UnitTestCase {
     11class Tests_Feed_RSS2 extends WP_UnitTestCase {
    1212
    1313    function setUp() {
  • trunk/tests/file.php

    r903 r904  
    11<?php
    22
    3 class TestIncludesFile extends WP_UnitTestCase {
     3class Tests_File extends WP_UnitTestCase {
    44
    55    function setUp() {
  • trunk/tests/formatting/balanceTags.php

    r903 r904  
    44 * @group formatting
    55 */
    6 class TestBalanceTags extends WP_UnitTestCase {
     6class Tests_Formatting_BalanceTags extends WP_UnitTestCase {
    77
    88    // These are single/self-closing tags that WP has traditionally recognized.
  • trunk/tests/http/base.php

    r903 r904  
    1010 *
    1111 * The WP_HTTP tests require a class-http.php file of r17550 or later.
    12  */
    13 
    14 /**
    15  * @group http
    1612 */
    1713abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
     
    184180    }
    185181}
    186 
    187 // Stubs to test each transport
    188 /**
    189  * @group http
    190  */
    191 class WPHTTP_curl extends WP_HTTP_UnitTestCase {
    192     var $transport = 'curl';
    193 }
    194 /**
    195  * @group http
    196  */
    197 class WPHTTP_streams extends WP_HTTP_UnitTestCase {
    198     var $transport = 'streams';
    199 }
    200 /**
    201  * @group http
    202  */
    203 class WPHTTP_fsockopen extends WP_HTTP_UnitTestCase {
    204     var $transport = 'fsockopen';
    205 }
    206 
    207 /**
    208  * Non-transport-specific WP_HTTP Tests
    209  *
    210  * @group http
    211  */
    212 class WPHTTP extends WP_UnitTestCase {
    213 
    214     /**
    215      * @dataProvider make_absolute_url_testcases
    216      */
    217     function test_make_absolute_url( $relative_url, $absolute_url, $expected ) {
    218         if ( ! is_callable( array( 'WP_HTTP', 'make_absolute_url' ) ) ) {
    219             $this->markTestSkipped( "This version of WP_HTTP doesn't support WP_HTTP::make_absolute_url()" );
    220             return;
    221         }
    222 
    223         $actual = WP_HTTP::make_absolute_url( $relative_url, $absolute_url );
    224         $this->assertEquals( $expected, $actual );
    225     }
    226 
    227     function make_absolute_url_testcases() {
    228         // 0: The Location header, 1: The current url, 3: The expected url
    229         return array(
    230             array( 'http://site.com/', 'http://example.com/', 'http://site.com/' ), // Absolute URL provided
    231             array( '/location', '', '/location' ), // No current url provided
    232 
    233             array( '', 'http://example.com', 'http://example.com/' ), // No location provided
    234 
    235             // Location provided relative to site root
    236             array( '/root-relative-link.ext', 'http://example.com/', 'http://example.com/root-relative-link.ext' ),
    237             array( '/root-relative-link.ext?with=query', 'http://example.com/index.ext?query', 'http://example.com/root-relative-link.ext?with=query' ),
    238 
    239             // Location provided relative to current file/directory
    240             array( 'relative-file.ext', 'http://example.com/', 'http://example.com/relative-file.ext' ),
    241             array( 'relative-file.ext', 'http://example.com/filename', 'http://example.com/relative-file.ext' ),
    242             array( 'relative-file.ext', 'http://example.com/directory/', 'http://example.com/directory/relative-file.ext' ),
    243 
    244             // Location provided relative to current file/directory but in a parent directory
    245             array( '../file-in-parent.ext', 'http://example.com', 'http://example.com/file-in-parent.ext' ),
    246             array( '../file-in-parent.ext', 'http://example.com/filename', 'http://example.com/file-in-parent.ext' ),
    247             array( '../file-in-parent.ext', 'http://example.com/directory/', 'http://example.com/file-in-parent.ext' ),
    248             array( '../file-in-parent.ext', 'http://example.com/directory/filename', 'http://example.com/file-in-parent.ext' ),
    249 
    250             // Location provided in muliple levels higher, including impossible to reach (../ below DOCROOT)
    251             array( '../../file-in-grand-parent.ext', 'http://example.com', 'http://example.com/file-in-grand-parent.ext' ),
    252             array( '../../file-in-grand-parent.ext', 'http://example.com/filename', 'http://example.com/file-in-grand-parent.ext' ),
    253             array( '../../file-in-grand-parent.ext', 'http://example.com/directory/', 'http://example.com/file-in-grand-parent.ext' ),
    254             array( '../../file-in-grand-parent.ext', 'http://example.com/directory/filename/', 'http://example.com/file-in-grand-parent.ext' ),
    255             array( '../../file-in-grand-parent.ext', 'http://example.com/directory1/directory2/filename', 'http://example.com/file-in-grand-parent.ext' ),
    256 
    257             // Query strings should attach, or replace existing query string.
    258             array( '?query=string', 'http://example.com', 'http://example.com/?query=string' ),
    259             array( '?query=string', 'http://example.com/file.ext', 'http://example.com/file.ext?query=string' ),
    260             array( '?query=string', 'http://example.com/file.ext?existing=query-string', 'http://example.com/file.ext?query=string' ),
    261             array( 'otherfile.ext?query=string', 'http://example.com/file.ext?existing=query-string', 'http://example.com/otherfile.ext?query=string' ),
    262 
    263             // A file with a leading dot
    264             array( '.ext', 'http://example.com/', 'http://example.com/.ext' )
    265         );
    266     }
    267 }
  • trunk/tests/http/http.php

    r903 r904  
    11<?php
    2 /**
    3  * Note, When running these tests, remember that some things are done differently
    4  * based on safe_mode. You can run the test in safe_mode like such:
    5  *
    6  *   phpunit -d safe_mode=on --group http
    7  *
    8  * You may also need `-d safe_mode_gid=1` to relax the safe_mode checks to allow
    9  * inclusion of PEAR.
    10  *
    11  * The WP_HTTP tests require a class-http.php file of r17550 or later.
    12  */
    13 
    14 /**
    15  * @group http
    16  */
    17 abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
    18     // You can use your own version of data/WPHTTP-testcase-redirection-script.php here.
    19     var $redirection_script = 'http://api.wordpress.org/core/tests/1.0/redirection.php';
    20 
    21     function setUp() {
    22 
    23         if ( is_callable( array('WP_HTTP', '_getTransport') ) ) {
    24             $this->markTestSkipped('The WP_HTTP tests require a class-http.php file of r17550 or later.');
    25             return;
    26         }
    27 
    28         $class = "WP_HTTP_" . $this->transport;
    29         if ( !call_user_func( array($class, 'test') ) ) {
    30             $this->markTestSkipped( sprintf('The transport %s is not supported on this system', $this->transport) );
    31         }
    32 
    33         // Disable all transports aside from this one.
    34         foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
    35             remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all
    36             if ( $t != $this->transport )
    37                 add_filter( "use_{$t}_transport", '__return_false' ); // and add it back if need be..
    38         }
    39     }
    40 
    41     function tearDown() {
    42         foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
    43             remove_filter( "use_{$t}_transport", '__return_false' );
    44         }
    45     }
    46 
    47     function test_redirect_on_301() {
    48         // 5 : 5 & 301
    49         $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
    50         $this->assertFalse( is_wp_error($res) );
    51         $this->assertEquals(200, (int)$res['response']['code'] );
    52     }
    53 
    54     function test_redirect_on_302() {
    55         // 5 : 5 & 302
    56         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
    57         $this->assertFalse( is_wp_error($res) );
    58         $this->assertEquals(200, (int)$res['response']['code'] );
    59     }
    60 
    61     /**
    62      * @ticket 16855
    63      */
    64     function test_redirect_on_301_no_redirect() {
    65         // 5 > 0 & 301
    66         $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
    67         $this->assertFalse( is_wp_error($res) );
    68         $this->assertEquals(301, (int)$res['response']['code'] );
    69     }
    70 
    71     /**
    72      * @ticket 16855
    73      */
    74     function test_redirect_on_302_no_redirect() {
    75         // 5 > 0 & 302
    76         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
    77         $this->assertFalse( is_wp_error($res) );
    78         $this->assertEquals(302, (int)$res['response']['code'] );
    79     }
    80 
    81     function test_redirections_equal() {
    82         // 5 - 5
    83         $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
    84         $this->assertFalse( is_wp_error($res) );
    85         $this->assertEquals(200, (int)$res['response']['code'] );
    86     }
    87 
    88     function test_no_head_redirections() {
    89         // No redirections on HEAD request:
    90         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
    91         $this->assertFalse( is_wp_error($res) );
    92         $this->assertEquals( 302, (int)$res['response']['code'] );
    93     }
    94 
    95     /**
    96      * @ticket 16855
    97      */
    98     function test_redirect_on_head() {
    99         // Redirections on HEAD request when Requested
    100         $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
    101         $this->assertFalse( is_wp_error($res) );
    102         $this->assertEquals( 200, (int)$res['response']['code'] );
    103     }
    104 
    105     function test_redirections_greater() {
    106         // 10 > 5
    107         $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
    108         $this->assertTrue( is_wp_error($res), print_r($res, true) );
    109     }
    110 
    111     function test_redirections_greater_edgecase() {
    112         // 6 > 5 (close edgecase)
    113         $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
    114         $this->assertTrue( is_wp_error($res) );
    115     }
    116 
    117     function test_redirections_less_edgecase() {
    118         // 4 < 5 (close edgecase)
    119         $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
    120         $this->assertFalse( is_wp_error($res) );
    121     }
    122 
    123     /**
    124      * @ticket 16855
    125      */
    126     function test_redirections_zero_redirections_specified() {
    127         // 0 redirections asked for, Should return the document?
    128         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
    129         $this->assertFalse( is_wp_error($res) );
    130         $this->assertEquals( 302, (int)$res['response']['code'] );
    131     }
    132 
    133     /**
    134      * Do not redirect on non 3xx status codes
    135      *
    136      * @ticket 16889
    137      *
    138      * Is this valid? Streams, cURL and therefore PHP Extension (ie. all PHP Internal) follow redirects
    139      * on all status codes, currently all of WP_HTTP follows this template.
    140      */
    141     function test_location_header_on_200() {
    142         // Prints PASS on initial load, FAIL if the client follows the specified redirection
    143         $res = wp_remote_request( $this->redirection_script . '?200-location=true' );
    144         $this->assertEquals( 'PASS', $res['body']);
    145     }
    146 
    147     /**
    148      * @ticket 11888
    149      */
    150     function test_send_headers() {
    151         // Test that the headers sent are recieved by the server
    152         $headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
    153         $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
    154 
    155         $this->assertFalse( is_wp_error($res) );
    156 
    157         $headers = array();
    158         foreach ( explode("\n", $res['body']) as $key => $value ) {
    159             if ( empty($value) )
    160                 continue;
    161             $parts = explode(':', $value,2);
    162             unset($heaers[$key]);
    163             $headers[ $parts[0] ] = $parts[1];
    164         }
    165 
    166         $this->assertTrue( isset($headers['test1']) && 'test' == $headers['test1'] );
    167         $this->assertTrue( isset($headers['test2']) && '0' === $headers['test2'] );
    168         // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value.
    169         // Should it be that empty headers with empty values are NOT sent?
    170         //$this->assertTrue( isset($headers['test3']) && '' === $headers['test3'] );
    171     }
    172 
    173     function test_file_stream() {
    174         $url = 'http://unit-tests.svn.wordpress.org/trunk/data/images/2004-07-22-DSC_0007.jpg'; // we'll test against a file in the unit test data
    175         $size = 87348;
    176         $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30 ) ); //Auto generate the filename.
    177 
    178         $this->assertFalse( is_wp_error( $res ) );
    179         $this->assertEquals( '', $res['body'] ); // The body should be empty.
    180         $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..)
    181         $this->assertEquals( $size, filesize($res['filename']) ); // Check that the file is written to disk correctly without any extra characters
    182 
    183         unlink($res['filename']); // Remove the temporary file
    184     }
    185 }
    186 
    187 // Stubs to test each transport
    188 /**
    189  * @group http
    190  */
    191 class WPHTTP_curl extends WP_HTTP_UnitTestCase {
    192     var $transport = 'curl';
    193 }
    194 /**
    195  * @group http
    196  */
    197 class WPHTTP_streams extends WP_HTTP_UnitTestCase {
    198     var $transport = 'streams';
    199 }
    200 /**
    201  * @group http
    202  */
    203 class WPHTTP_fsockopen extends WP_HTTP_UnitTestCase {
    204     var $transport = 'fsockopen';
    205 }
    206 
    2072/**
    2083 * Non-transport-specific WP_HTTP Tests
     
    2105 * @group http
    2116 */
    212 class WPHTTP extends WP_UnitTestCase {
     7class Tests_HTTP_HTTP extends WP_UnitTestCase {
    2138
    2149    /**
  • trunk/tests/kses.php

    r903 r904  
    66 * @group kses
    77 */
    8 class Test_wp_filter_post_kses extends WP_UnitTestCase {
     8class Tests_Kses extends WP_UnitTestCase {
    99
    1010    /**
  • trunk/tests/media.php

    r903 r904  
    11<?php
    22
    3 class TestIncludesMedia extends WP_UnitTestCase {
     3/**
     4 * @group media
     5 * @group shortcode
     6 */
     7class Tests_Media extends WP_UnitTestCase {
    48
    59  function setUp() {
  • trunk/tests/meta.php

    r903 r904  
    44 * @group meta
    55 */
    6 class WPTestIncludesMeta extends WP_UnitTestCase {
     6class Tests_Meta extends WP_UnitTestCase {
    77    function setUp() {
    88        parent::setUp();
  • trunk/tests/ms.php

    r903 r904  
    88 * @group multisite
    99 */
    10 class WPTestMS extends WP_UnitTestCase {
     10class Tests_MS extends WP_UnitTestCase {
    1111
    1212    protected $plugin_hook_count = 0;
  • trunk/tests/option/blogOption.php

    r903 r904  
    11<?php
    2 
    3 /**
    4  * @group options
    5  */
    6 class TestOption extends WP_UnitTestCase {
    7     function setUp() {
    8         parent::setUp();
    9     }
    10 
    11     function tearDown() {
    12         parent::tearDown();
    13     }
    14 
    15     function __return_foo() {
    16         return 'foo';
    17     }
    18 
    19     function test_the_basics() {
    20         $key = rand_str();
    21         $key2 = rand_str();
    22         $value = rand_str();
    23         $value2 = rand_str();
    24 
    25         $this->assertFalse( get_option( 'doesnotexist' ) );
    26         $this->assertTrue( add_option( $key, $value ) );
    27         $this->assertEquals( $value, get_option( $key ) );
    28         $this->assertFalse( add_option( $key, $value ) );  // Already exists
    29         $this->assertFalse( update_option( $key, $value ) );  // Value is the same
    30         $this->assertTrue( update_option( $key, $value2 ) );
    31         $this->assertEquals( $value2, get_option( $key ) );
    32         $this->assertFalse( add_option( $key, $value ) );
    33         $this->assertEquals( $value2, get_option( $key ) );
    34         $this->assertTrue( delete_option( $key ) );
    35         $this->assertFalse( get_option( $key ) );
    36         $this->assertFalse( delete_option( $key ) );
    37 
    38         $this->assertTrue( update_option( $key2, $value2 ) );
    39         $this->assertEquals( $value2, get_option( $key2 ) );
    40         $this->assertTrue( delete_option( $key2 ) );
    41         $this->assertFalse( get_option( $key2 ) );
    42     }
    43 
    44     function test_default_filter() {
    45         $random = rand_str();
    46 
    47         $this->assertFalse( get_option( 'doesnotexist' ) );
    48 
    49         // Default filter overrides $default arg.
    50         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    51         $this->assertEquals( 'foo', get_option( 'doesnotexist', 'bar' ) );
    52 
    53         // Remove the filter and the $default arg is honored.
    54         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    55         $this->assertEquals( 'bar', get_option( 'doesnotexist', 'bar' ) );
    56 
    57         // Once the option exists, the $default arg and the default filter are ignored.
    58         add_option( 'doesnotexist', $random );
    59         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    60         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    61         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    62         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    63 
    64         // Cleanup
    65         $this->assertTrue( delete_option( 'doesnotexist' ) );
    66         $this->assertFalse( get_option( 'doesnotexist' ) );
    67     }
    68 
    69     function test_serialized_data() {
    70         $key = rand_str();
    71         $value = array( 'foo' => true, 'bar' => true );
    72 
    73         $this->assertTrue( add_option( $key, $value ) );
    74         $this->assertEquals( $value, get_option( $key ) );
    75 
    76         $value = (object) $value;
    77         $this->assertTrue( update_option( $key, $value ) );
    78         $this->assertEquals( $value, get_option( $key ) );
    79         $this->assertTrue( delete_option( $key ) );
    80     }
    81 }
    82 
    83 /**
    84  * @group options
    85  */
    86 class TestSiteOption extends WP_UnitTestCase {
    87     function __return_foo() {
    88         return 'foo';
    89     }
    90 
    91     function test_the_basics() {
    92         $key = rand_str();
    93         $key2 = rand_str();
    94         $value = rand_str();
    95         $value2 = rand_str();
    96 
    97         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    98         $this->assertTrue( add_site_option( $key, $value ) );
    99         $this->assertEquals( $value, get_site_option( $key ) );
    100         $this->assertFalse( add_site_option( $key, $value ) );  // Already exists
    101         $this->assertFalse( update_site_option( $key, $value ) );  // Value is the same
    102         $this->assertTrue( update_site_option( $key, $value2 ) );
    103         $this->assertEquals( $value2, get_site_option( $key ) );
    104         $this->assertFalse( add_site_option( $key, $value ) );
    105         $this->assertEquals( $value2, get_site_option( $key ) );
    106         $this->assertTrue( delete_site_option( $key ) );
    107         $this->assertFalse( get_site_option( $key ) );
    108         $this->assertFalse( delete_site_option( $key ) );
    109 
    110         $this->assertTrue( update_site_option( $key2, $value2 ) );
    111         $this->assertEquals( $value2, get_site_option( $key2 ) );
    112         $this->assertTrue( delete_site_option( $key2 ) );
    113         $this->assertFalse( get_site_option( $key2 ) );
    114     }
    115 
    116     function test_default_filter() {
    117         $random = rand_str();
    118 
    119         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    120 
    121         // Default filter overrides $default arg.
    122         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    123         $this->assertEquals( 'foo', get_site_option( 'doesnotexist', 'bar' ) );
    124 
    125         // Remove the filter and the $default arg is honored.
    126         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    127         $this->assertEquals( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
    128 
    129         // Once the option exists, the $default arg and the default filter are ignored.
    130         add_site_option( 'doesnotexist', $random );
    131         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    132         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    133         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    134         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    135 
    136         // Cleanup
    137         $this->assertTrue( delete_site_option( 'doesnotexist' ) );
    138         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    139     }
    140 
    141     function test_serialized_data() {
    142         $key = rand_str();
    143         $value = array( 'foo' => true, 'bar' => true );
    144 
    145         $this->assertTrue( add_site_option( $key, $value ) );
    146         $this->assertEquals( $value, get_site_option( $key ) );
    147 
    148         $value = (object) $value;
    149         $this->assertTrue( update_site_option( $key, $value ) );
    150         $this->assertEquals( $value, get_site_option( $key ) );
    151         $this->assertTrue( delete_site_option( $key ) );
    152     }
    153 
    154     // #15497 - ensure update_site_option will add options with false-y values
    155     function test_update_adds_falsey_value() {
    156         $key = rand_str();
    157         $value = 0;
    158 
    159         delete_site_option( $key );
    160         $this->assertTrue( update_site_option( $key, $value ) );
    161         wp_cache_flush(); // ensure we're getting the value from the DB
    162         $this->assertEquals( $value, get_site_option( $key ) );
    163     }
    164 
    165     // #18955 - ensure get_site_option doesn't cache the default value for non-existent options
    166     function test_get_doesnt_cache_default_value() {
    167         $option = rand_str();
    168         $default = 'a default';
    169 
    170         $this->assertEquals( get_site_option( $option, $default ), $default );
    171         $this->assertFalse( get_site_option( $option ) );
    172     }
    173 }
    174 
    175 /**
    176  * @group options
    177  */
    178 class TestTransient extends WP_UnitTestCase {
    179     function setUp() {
    180         parent::setUp();
    181     }
    182 
    183     function tearDown() {
    184         parent::tearDown();
    185     }
    186 
    187     function test_the_basics() {
    188         $key = rand_str();
    189         $value = rand_str();
    190         $value2 = rand_str();
    191 
    192         $this->assertFalse( get_transient( 'doesnotexist' ) );
    193         $this->assertTrue( set_transient( $key, $value ) );
    194         $this->assertEquals( $value, get_transient( $key ) );
    195         $this->assertFalse( set_transient( $key, $value ) );
    196         $this->assertTrue( set_transient( $key, $value2 ) );
    197         $this->assertEquals( $value2, get_transient( $key ) );
    198         $this->assertTrue( delete_transient( $key ) );
    199         $this->assertFalse( get_transient( $key ) );
    200         $this->assertFalse( delete_transient( $key ) );
    201     }
    202 
    203     function test_serialized_data() {
    204         $key = rand_str();
    205         $value = array( 'foo' => true, 'bar' => true );
    206 
    207         $this->assertTrue( set_transient( $key, $value ) );
    208         $this->assertEquals( $value, get_transient( $key ) );
    209 
    210         $value = (object) $value;
    211         $this->assertTrue( set_transient( $key, $value ) );
    212         $this->assertEquals( $value, get_transient( $key ) );
    213         $this->assertTrue( delete_transient( $key ) );
    214     }
    215 }
    216 
    217 /**
    218  * @group options
    219  */
    220 class TestSiteTransient extends WP_UnitTestCase {
    221     function setUp() {
    222         parent::setUp();
    223     }
    224 
    225     function tearDown() {
    226         parent::tearDown();
    227     }
    228 
    229     function test_the_basics() {
    230         $key = rand_str();
    231         $value = rand_str();
    232         $value2 = rand_str();
    233 
    234         $this->assertFalse( get_site_transient( 'doesnotexist' ) );
    235         $this->assertTrue( set_site_transient( $key, $value ) );
    236         $this->assertEquals( $value, get_site_transient( $key ) );
    237         $this->assertFalse( set_site_transient( $key, $value ) );
    238         $this->assertTrue( set_site_transient( $key, $value2 ) );
    239         $this->assertEquals( $value2, get_site_transient( $key ) );
    240         $this->assertTrue( delete_site_transient( $key ) );
    241         $this->assertFalse( get_site_transient( $key ) );
    242         $this->assertFalse( delete_site_transient( $key ) );
    243     }
    244 
    245     function test_serialized_data() {
    246         $key = rand_str();
    247         $value = array( 'foo' => true, 'bar' => true );
    248 
    249         $this->assertTrue( set_site_transient( $key, $value ) );
    250         $this->assertEquals( $value, get_site_transient( $key ) );
    251 
    252         $value = (object) $value;
    253         $this->assertTrue( set_site_transient( $key, $value ) );
    254         $this->assertEquals( $value, get_site_transient( $key ) );
    255         $this->assertTrue( delete_site_transient( $key ) );
    256     }
    257 }
    2582
    2593if ( is_multisite() ) :
    2604/**
    261  * @group options
     5 * @group option
    2626 */
    263 class TestBlogOption extends WP_UnitTestCase {
     7class Tests_Option_BlogOption extends WP_UnitTestCase {
    2648    function test_from_same_site() {
    2659        $key = rand_str();
  • trunk/tests/option/option.php

    r903 r904  
    22
    33/**
    4  * @group options
     4 * @group option
    55 */
    6 class TestOption extends WP_UnitTestCase {
    7     function setUp() {
    8         parent::setUp();
    9     }
    10 
    11     function tearDown() {
    12         parent::tearDown();
    13     }
     6class Tests_Option_Option extends WP_UnitTestCase {
    147
    158    function __return_foo() {
     
    8073    }
    8174}
    82 
    83 /**
    84  * @group options
    85  */
    86 class TestSiteOption extends WP_UnitTestCase {
    87     function __return_foo() {
    88         return 'foo';
    89     }
    90 
    91     function test_the_basics() {
    92         $key = rand_str();
    93         $key2 = rand_str();
    94         $value = rand_str();
    95         $value2 = rand_str();
    96 
    97         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    98         $this->assertTrue( add_site_option( $key, $value ) );
    99         $this->assertEquals( $value, get_site_option( $key ) );
    100         $this->assertFalse( add_site_option( $key, $value ) );  // Already exists
    101         $this->assertFalse( update_site_option( $key, $value ) );  // Value is the same
    102         $this->assertTrue( update_site_option( $key, $value2 ) );
    103         $this->assertEquals( $value2, get_site_option( $key ) );
    104         $this->assertFalse( add_site_option( $key, $value ) );
    105         $this->assertEquals( $value2, get_site_option( $key ) );
    106         $this->assertTrue( delete_site_option( $key ) );
    107         $this->assertFalse( get_site_option( $key ) );
    108         $this->assertFalse( delete_site_option( $key ) );
    109 
    110         $this->assertTrue( update_site_option( $key2, $value2 ) );
    111         $this->assertEquals( $value2, get_site_option( $key2 ) );
    112         $this->assertTrue( delete_site_option( $key2 ) );
    113         $this->assertFalse( get_site_option( $key2 ) );
    114     }
    115 
    116     function test_default_filter() {
    117         $random = rand_str();
    118 
    119         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    120 
    121         // Default filter overrides $default arg.
    122         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    123         $this->assertEquals( 'foo', get_site_option( 'doesnotexist', 'bar' ) );
    124 
    125         // Remove the filter and the $default arg is honored.
    126         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    127         $this->assertEquals( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
    128 
    129         // Once the option exists, the $default arg and the default filter are ignored.
    130         add_site_option( 'doesnotexist', $random );
    131         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    132         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    133         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    134         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    135 
    136         // Cleanup
    137         $this->assertTrue( delete_site_option( 'doesnotexist' ) );
    138         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    139     }
    140 
    141     function test_serialized_data() {
    142         $key = rand_str();
    143         $value = array( 'foo' => true, 'bar' => true );
    144 
    145         $this->assertTrue( add_site_option( $key, $value ) );
    146         $this->assertEquals( $value, get_site_option( $key ) );
    147 
    148         $value = (object) $value;
    149         $this->assertTrue( update_site_option( $key, $value ) );
    150         $this->assertEquals( $value, get_site_option( $key ) );
    151         $this->assertTrue( delete_site_option( $key ) );
    152     }
    153 
    154     // #15497 - ensure update_site_option will add options with false-y values
    155     function test_update_adds_falsey_value() {
    156         $key = rand_str();
    157         $value = 0;
    158 
    159         delete_site_option( $key );
    160         $this->assertTrue( update_site_option( $key, $value ) );
    161         wp_cache_flush(); // ensure we're getting the value from the DB
    162         $this->assertEquals( $value, get_site_option( $key ) );
    163     }
    164 
    165     // #18955 - ensure get_site_option doesn't cache the default value for non-existent options
    166     function test_get_doesnt_cache_default_value() {
    167         $option = rand_str();
    168         $default = 'a default';
    169 
    170         $this->assertEquals( get_site_option( $option, $default ), $default );
    171         $this->assertFalse( get_site_option( $option ) );
    172     }
    173 }
    174 
    175 /**
    176  * @group options
    177  */
    178 class TestTransient extends WP_UnitTestCase {
    179     function setUp() {
    180         parent::setUp();
    181     }
    182 
    183     function tearDown() {
    184         parent::tearDown();
    185     }
    186 
    187     function test_the_basics() {
    188         $key = rand_str();
    189         $value = rand_str();
    190         $value2 = rand_str();
    191 
    192         $this->assertFalse( get_transient( 'doesnotexist' ) );
    193         $this->assertTrue( set_transient( $key, $value ) );
    194         $this->assertEquals( $value, get_transient( $key ) );
    195         $this->assertFalse( set_transient( $key, $value ) );
    196         $this->assertTrue( set_transient( $key, $value2 ) );
    197         $this->assertEquals( $value2, get_transient( $key ) );
    198         $this->assertTrue( delete_transient( $key ) );
    199         $this->assertFalse( get_transient( $key ) );
    200         $this->assertFalse( delete_transient( $key ) );
    201     }
    202 
    203     function test_serialized_data() {
    204         $key = rand_str();
    205         $value = array( 'foo' => true, 'bar' => true );
    206 
    207         $this->assertTrue( set_transient( $key, $value ) );
    208         $this->assertEquals( $value, get_transient( $key ) );
    209 
    210         $value = (object) $value;
    211         $this->assertTrue( set_transient( $key, $value ) );
    212         $this->assertEquals( $value, get_transient( $key ) );
    213         $this->assertTrue( delete_transient( $key ) );
    214     }
    215 }
    216 
    217 /**
    218  * @group options
    219  */
    220 class TestSiteTransient extends WP_UnitTestCase {
    221     function setUp() {
    222         parent::setUp();
    223     }
    224 
    225     function tearDown() {
    226         parent::tearDown();
    227     }
    228 
    229     function test_the_basics() {
    230         $key = rand_str();
    231         $value = rand_str();
    232         $value2 = rand_str();
    233 
    234         $this->assertFalse( get_site_transient( 'doesnotexist' ) );
    235         $this->assertTrue( set_site_transient( $key, $value ) );
    236         $this->assertEquals( $value, get_site_transient( $key ) );
    237         $this->assertFalse( set_site_transient( $key, $value ) );
    238         $this->assertTrue( set_site_transient( $key, $value2 ) );
    239         $this->assertEquals( $value2, get_site_transient( $key ) );
    240         $this->assertTrue( delete_site_transient( $key ) );
    241         $this->assertFalse( get_site_transient( $key ) );
    242         $this->assertFalse( delete_site_transient( $key ) );
    243     }
    244 
    245     function test_serialized_data() {
    246         $key = rand_str();
    247         $value = array( 'foo' => true, 'bar' => true );
    248 
    249         $this->assertTrue( set_site_transient( $key, $value ) );
    250         $this->assertEquals( $value, get_site_transient( $key ) );
    251 
    252         $value = (object) $value;
    253         $this->assertTrue( set_site_transient( $key, $value ) );
    254         $this->assertEquals( $value, get_site_transient( $key ) );
    255         $this->assertTrue( delete_site_transient( $key ) );
    256     }
    257 }
    258 
    259 if ( is_multisite() ) :
    260 /**
    261  * @group options
    262  */
    263 class TestBlogOption extends WP_UnitTestCase {
    264     function test_from_same_site() {
    265         $key = rand_str();
    266         $key2 = rand_str();
    267         $value = rand_str();
    268         $value2 = rand_str();
    269 
    270         $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
    271         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    272 
    273         $this->assertTrue( add_blog_option( 1, $key, $value ) );
    274         // Assert all values of $blog_id that means the current or main blog (the same here).
    275         $this->assertEquals( $value, get_blog_option( 1, $key ) );
    276         $this->assertEquals( $value, get_blog_option( null, $key ) );
    277         $this->assertEquals( $value, get_blog_option( '1', $key ) );
    278         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    279 
    280         $this->assertFalse( add_blog_option( 1, $key, $value ) );  // Already exists
    281         $this->assertFalse( update_blog_option( 1, $key, $value ) );  // Value is the same
    282         $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
    283         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    284         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    285         $this->assertFalse( add_blog_option( 1, $key, $value ) );
    286         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    287         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    288 
    289         $this->assertTrue( delete_blog_option( 1, $key ) );
    290         $this->assertFalse( get_blog_option( 1, $key ) );
    291         $this->assertFalse( get_option( $key ) ); // check get_option()
    292         $this->assertFalse( delete_blog_option( 1, $key ) );
    293         $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
    294         $this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
    295         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    296         $this->assertTrue( delete_blog_option( 1, $key2 ) );
    297         $this->assertFalse( get_blog_option( 1, $key2 ) );
    298         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    299     }
    300 }
    301 endif;
  • trunk/tests/option/siteOption.php

    r903 r904  
    22
    33/**
    4  * @group options
     4 * @group option
    55 */
    6 class TestOption extends WP_UnitTestCase {
    7     function setUp() {
    8         parent::setUp();
    9     }
    10 
    11     function tearDown() {
    12         parent::tearDown();
    13     }
    14 
    15     function __return_foo() {
    16         return 'foo';
    17     }
    18 
    19     function test_the_basics() {
    20         $key = rand_str();
    21         $key2 = rand_str();
    22         $value = rand_str();
    23         $value2 = rand_str();
    24 
    25         $this->assertFalse( get_option( 'doesnotexist' ) );
    26         $this->assertTrue( add_option( $key, $value ) );
    27         $this->assertEquals( $value, get_option( $key ) );
    28         $this->assertFalse( add_option( $key, $value ) );  // Already exists
    29         $this->assertFalse( update_option( $key, $value ) );  // Value is the same
    30         $this->assertTrue( update_option( $key, $value2 ) );
    31         $this->assertEquals( $value2, get_option( $key ) );
    32         $this->assertFalse( add_option( $key, $value ) );
    33         $this->assertEquals( $value2, get_option( $key ) );
    34         $this->assertTrue( delete_option( $key ) );
    35         $this->assertFalse( get_option( $key ) );
    36         $this->assertFalse( delete_option( $key ) );
    37 
    38         $this->assertTrue( update_option( $key2, $value2 ) );
    39         $this->assertEquals( $value2, get_option( $key2 ) );
    40         $this->assertTrue( delete_option( $key2 ) );
    41         $this->assertFalse( get_option( $key2 ) );
    42     }
    43 
    44     function test_default_filter() {
    45         $random = rand_str();
    46 
    47         $this->assertFalse( get_option( 'doesnotexist' ) );
    48 
    49         // Default filter overrides $default arg.
    50         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    51         $this->assertEquals( 'foo', get_option( 'doesnotexist', 'bar' ) );
    52 
    53         // Remove the filter and the $default arg is honored.
    54         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    55         $this->assertEquals( 'bar', get_option( 'doesnotexist', 'bar' ) );
    56 
    57         // Once the option exists, the $default arg and the default filter are ignored.
    58         add_option( 'doesnotexist', $random );
    59         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    60         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    61         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    62         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    63 
    64         // Cleanup
    65         $this->assertTrue( delete_option( 'doesnotexist' ) );
    66         $this->assertFalse( get_option( 'doesnotexist' ) );
    67     }
    68 
    69     function test_serialized_data() {
    70         $key = rand_str();
    71         $value = array( 'foo' => true, 'bar' => true );
    72 
    73         $this->assertTrue( add_option( $key, $value ) );
    74         $this->assertEquals( $value, get_option( $key ) );
    75 
    76         $value = (object) $value;
    77         $this->assertTrue( update_option( $key, $value ) );
    78         $this->assertEquals( $value, get_option( $key ) );
    79         $this->assertTrue( delete_option( $key ) );
    80     }
    81 }
    82 
    83 /**
    84  * @group options
    85  */
    86 class TestSiteOption extends WP_UnitTestCase {
     6class Tests_Option_SiteOption extends WP_UnitTestCase {
    877    function __return_foo() {
    888        return 'foo';
     
    17292    }
    17393}
    174 
    175 /**
    176  * @group options
    177  */
    178 class TestTransient extends WP_UnitTestCase {
    179     function setUp() {
    180         parent::setUp();
    181     }
    182 
    183     function tearDown() {
    184         parent::tearDown();
    185     }
    186 
    187     function test_the_basics() {
    188         $key = rand_str();
    189         $value = rand_str();
    190         $value2 = rand_str();
    191 
    192         $this->assertFalse( get_transient( 'doesnotexist' ) );
    193         $this->assertTrue( set_transient( $key, $value ) );
    194         $this->assertEquals( $value, get_transient( $key ) );
    195         $this->assertFalse( set_transient( $key, $value ) );
    196         $this->assertTrue( set_transient( $key, $value2 ) );
    197         $this->assertEquals( $value2, get_transient( $key ) );
    198         $this->assertTrue( delete_transient( $key ) );
    199         $this->assertFalse( get_transient( $key ) );
    200         $this->assertFalse( delete_transient( $key ) );
    201     }
    202 
    203     function test_serialized_data() {
    204         $key = rand_str();
    205         $value = array( 'foo' => true, 'bar' => true );
    206 
    207         $this->assertTrue( set_transient( $key, $value ) );
    208         $this->assertEquals( $value, get_transient( $key ) );
    209 
    210         $value = (object) $value;
    211         $this->assertTrue( set_transient( $key, $value ) );
    212         $this->assertEquals( $value, get_transient( $key ) );
    213         $this->assertTrue( delete_transient( $key ) );
    214     }
    215 }
    216 
    217 /**
    218  * @group options
    219  */
    220 class TestSiteTransient extends WP_UnitTestCase {
    221     function setUp() {
    222         parent::setUp();
    223     }
    224 
    225     function tearDown() {
    226         parent::tearDown();
    227     }
    228 
    229     function test_the_basics() {
    230         $key = rand_str();
    231         $value = rand_str();
    232         $value2 = rand_str();
    233 
    234         $this->assertFalse( get_site_transient( 'doesnotexist' ) );
    235         $this->assertTrue( set_site_transient( $key, $value ) );
    236         $this->assertEquals( $value, get_site_transient( $key ) );
    237         $this->assertFalse( set_site_transient( $key, $value ) );
    238         $this->assertTrue( set_site_transient( $key, $value2 ) );
    239         $this->assertEquals( $value2, get_site_transient( $key ) );
    240         $this->assertTrue( delete_site_transient( $key ) );
    241         $this->assertFalse( get_site_transient( $key ) );
    242         $this->assertFalse( delete_site_transient( $key ) );
    243     }
    244 
    245     function test_serialized_data() {
    246         $key = rand_str();
    247         $value = array( 'foo' => true, 'bar' => true );
    248 
    249         $this->assertTrue( set_site_transient( $key, $value ) );
    250         $this->assertEquals( $value, get_site_transient( $key ) );
    251 
    252         $value = (object) $value;
    253         $this->assertTrue( set_site_transient( $key, $value ) );
    254         $this->assertEquals( $value, get_site_transient( $key ) );
    255         $this->assertTrue( delete_site_transient( $key ) );
    256     }
    257 }
    258 
    259 if ( is_multisite() ) :
    260 /**
    261  * @group options
    262  */
    263 class TestBlogOption extends WP_UnitTestCase {
    264     function test_from_same_site() {
    265         $key = rand_str();
    266         $key2 = rand_str();
    267         $value = rand_str();
    268         $value2 = rand_str();
    269 
    270         $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
    271         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    272 
    273         $this->assertTrue( add_blog_option( 1, $key, $value ) );
    274         // Assert all values of $blog_id that means the current or main blog (the same here).
    275         $this->assertEquals( $value, get_blog_option( 1, $key ) );
    276         $this->assertEquals( $value, get_blog_option( null, $key ) );
    277         $this->assertEquals( $value, get_blog_option( '1', $key ) );
    278         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    279 
    280         $this->assertFalse( add_blog_option( 1, $key, $value ) );  // Already exists
    281         $this->assertFalse( update_blog_option( 1, $key, $value ) );  // Value is the same
    282         $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
    283         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    284         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    285         $this->assertFalse( add_blog_option( 1, $key, $value ) );
    286         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    287         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    288 
    289         $this->assertTrue( delete_blog_option( 1, $key ) );
    290         $this->assertFalse( get_blog_option( 1, $key ) );
    291         $this->assertFalse( get_option( $key ) ); // check get_option()
    292         $this->assertFalse( delete_blog_option( 1, $key ) );
    293         $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
    294         $this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
    295         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    296         $this->assertTrue( delete_blog_option( 1, $key2 ) );
    297         $this->assertFalse( get_blog_option( 1, $key2 ) );
    298         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    299     }
    300 }
    301 endif;
  • trunk/tests/option/siteTransient.php

    r903 r904  
    22
    33/**
    4  * @group options
     4 * @group option
    55 */
    6 class TestOption extends WP_UnitTestCase {
    7     function setUp() {
    8         parent::setUp();
    9     }
    10 
    11     function tearDown() {
    12         parent::tearDown();
    13     }
    14 
    15     function __return_foo() {
    16         return 'foo';
    17     }
    18 
    19     function test_the_basics() {
    20         $key = rand_str();
    21         $key2 = rand_str();
    22         $value = rand_str();
    23         $value2 = rand_str();
    24 
    25         $this->assertFalse( get_option( 'doesnotexist' ) );
    26         $this->assertTrue( add_option( $key, $value ) );
    27         $this->assertEquals( $value, get_option( $key ) );
    28         $this->assertFalse( add_option( $key, $value ) );  // Already exists
    29         $this->assertFalse( update_option( $key, $value ) );  // Value is the same
    30         $this->assertTrue( update_option( $key, $value2 ) );
    31         $this->assertEquals( $value2, get_option( $key ) );
    32         $this->assertFalse( add_option( $key, $value ) );
    33         $this->assertEquals( $value2, get_option( $key ) );
    34         $this->assertTrue( delete_option( $key ) );
    35         $this->assertFalse( get_option( $key ) );
    36         $this->assertFalse( delete_option( $key ) );
    37 
    38         $this->assertTrue( update_option( $key2, $value2 ) );
    39         $this->assertEquals( $value2, get_option( $key2 ) );
    40         $this->assertTrue( delete_option( $key2 ) );
    41         $this->assertFalse( get_option( $key2 ) );
    42     }
    43 
    44     function test_default_filter() {
    45         $random = rand_str();
    46 
    47         $this->assertFalse( get_option( 'doesnotexist' ) );
    48 
    49         // Default filter overrides $default arg.
    50         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    51         $this->assertEquals( 'foo', get_option( 'doesnotexist', 'bar' ) );
    52 
    53         // Remove the filter and the $default arg is honored.
    54         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    55         $this->assertEquals( 'bar', get_option( 'doesnotexist', 'bar' ) );
    56 
    57         // Once the option exists, the $default arg and the default filter are ignored.
    58         add_option( 'doesnotexist', $random );
    59         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    60         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    61         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    62         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    63 
    64         // Cleanup
    65         $this->assertTrue( delete_option( 'doesnotexist' ) );
    66         $this->assertFalse( get_option( 'doesnotexist' ) );
    67     }
    68 
    69     function test_serialized_data() {
    70         $key = rand_str();
    71         $value = array( 'foo' => true, 'bar' => true );
    72 
    73         $this->assertTrue( add_option( $key, $value ) );
    74         $this->assertEquals( $value, get_option( $key ) );
    75 
    76         $value = (object) $value;
    77         $this->assertTrue( update_option( $key, $value ) );
    78         $this->assertEquals( $value, get_option( $key ) );
    79         $this->assertTrue( delete_option( $key ) );
    80     }
    81 }
    82 
    83 /**
    84  * @group options
    85  */
    86 class TestSiteOption extends WP_UnitTestCase {
    87     function __return_foo() {
    88         return 'foo';
    89     }
    90 
    91     function test_the_basics() {
    92         $key = rand_str();
    93         $key2 = rand_str();
    94         $value = rand_str();
    95         $value2 = rand_str();
    96 
    97         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    98         $this->assertTrue( add_site_option( $key, $value ) );
    99         $this->assertEquals( $value, get_site_option( $key ) );
    100         $this->assertFalse( add_site_option( $key, $value ) );  // Already exists
    101         $this->assertFalse( update_site_option( $key, $value ) );  // Value is the same
    102         $this->assertTrue( update_site_option( $key, $value2 ) );
    103         $this->assertEquals( $value2, get_site_option( $key ) );
    104         $this->assertFalse( add_site_option( $key, $value ) );
    105         $this->assertEquals( $value2, get_site_option( $key ) );
    106         $this->assertTrue( delete_site_option( $key ) );
    107         $this->assertFalse( get_site_option( $key ) );
    108         $this->assertFalse( delete_site_option( $key ) );
    109 
    110         $this->assertTrue( update_site_option( $key2, $value2 ) );
    111         $this->assertEquals( $value2, get_site_option( $key2 ) );
    112         $this->assertTrue( delete_site_option( $key2 ) );
    113         $this->assertFalse( get_site_option( $key2 ) );
    114     }
    115 
    116     function test_default_filter() {
    117         $random = rand_str();
    118 
    119         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    120 
    121         // Default filter overrides $default arg.
    122         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    123         $this->assertEquals( 'foo', get_site_option( 'doesnotexist', 'bar' ) );
    124 
    125         // Remove the filter and the $default arg is honored.
    126         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    127         $this->assertEquals( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
    128 
    129         // Once the option exists, the $default arg and the default filter are ignored.
    130         add_site_option( 'doesnotexist', $random );
    131         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    132         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    133         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    134         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    135 
    136         // Cleanup
    137         $this->assertTrue( delete_site_option( 'doesnotexist' ) );
    138         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    139     }
    140 
    141     function test_serialized_data() {
    142         $key = rand_str();
    143         $value = array( 'foo' => true, 'bar' => true );
    144 
    145         $this->assertTrue( add_site_option( $key, $value ) );
    146         $this->assertEquals( $value, get_site_option( $key ) );
    147 
    148         $value = (object) $value;
    149         $this->assertTrue( update_site_option( $key, $value ) );
    150         $this->assertEquals( $value, get_site_option( $key ) );
    151         $this->assertTrue( delete_site_option( $key ) );
    152     }
    153 
    154     // #15497 - ensure update_site_option will add options with false-y values
    155     function test_update_adds_falsey_value() {
    156         $key = rand_str();
    157         $value = 0;
    158 
    159         delete_site_option( $key );
    160         $this->assertTrue( update_site_option( $key, $value ) );
    161         wp_cache_flush(); // ensure we're getting the value from the DB
    162         $this->assertEquals( $value, get_site_option( $key ) );
    163     }
    164 
    165     // #18955 - ensure get_site_option doesn't cache the default value for non-existent options
    166     function test_get_doesnt_cache_default_value() {
    167         $option = rand_str();
    168         $default = 'a default';
    169 
    170         $this->assertEquals( get_site_option( $option, $default ), $default );
    171         $this->assertFalse( get_site_option( $option ) );
    172     }
    173 }
    174 
    175 /**
    176  * @group options
    177  */
    178 class TestTransient extends WP_UnitTestCase {
    179     function setUp() {
    180         parent::setUp();
    181     }
    182 
    183     function tearDown() {
    184         parent::tearDown();
    185     }
    186 
    187     function test_the_basics() {
    188         $key = rand_str();
    189         $value = rand_str();
    190         $value2 = rand_str();
    191 
    192         $this->assertFalse( get_transient( 'doesnotexist' ) );
    193         $this->assertTrue( set_transient( $key, $value ) );
    194         $this->assertEquals( $value, get_transient( $key ) );
    195         $this->assertFalse( set_transient( $key, $value ) );
    196         $this->assertTrue( set_transient( $key, $value2 ) );
    197         $this->assertEquals( $value2, get_transient( $key ) );
    198         $this->assertTrue( delete_transient( $key ) );
    199         $this->assertFalse( get_transient( $key ) );
    200         $this->assertFalse( delete_transient( $key ) );
    201     }
    202 
    203     function test_serialized_data() {
    204         $key = rand_str();
    205         $value = array( 'foo' => true, 'bar' => true );
    206 
    207         $this->assertTrue( set_transient( $key, $value ) );
    208         $this->assertEquals( $value, get_transient( $key ) );
    209 
    210         $value = (object) $value;
    211         $this->assertTrue( set_transient( $key, $value ) );
    212         $this->assertEquals( $value, get_transient( $key ) );
    213         $this->assertTrue( delete_transient( $key ) );
    214     }
    215 }
    216 
    217 /**
    218  * @group options
    219  */
    220 class TestSiteTransient extends WP_UnitTestCase {
    221     function setUp() {
    222         parent::setUp();
    223     }
    224 
    225     function tearDown() {
    226         parent::tearDown();
    227     }
     6class Tests_Option_SiteTransient extends WP_UnitTestCase {
    2287
    2298    function test_the_basics() {
     
    25635    }
    25736}
    258 
    259 if ( is_multisite() ) :
    260 /**
    261  * @group options
    262  */
    263 class TestBlogOption extends WP_UnitTestCase {
    264     function test_from_same_site() {
    265         $key = rand_str();
    266         $key2 = rand_str();
    267         $value = rand_str();
    268         $value2 = rand_str();
    269 
    270         $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
    271         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    272 
    273         $this->assertTrue( add_blog_option( 1, $key, $value ) );
    274         // Assert all values of $blog_id that means the current or main blog (the same here).
    275         $this->assertEquals( $value, get_blog_option( 1, $key ) );
    276         $this->assertEquals( $value, get_blog_option( null, $key ) );
    277         $this->assertEquals( $value, get_blog_option( '1', $key ) );
    278         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    279 
    280         $this->assertFalse( add_blog_option( 1, $key, $value ) );  // Already exists
    281         $this->assertFalse( update_blog_option( 1, $key, $value ) );  // Value is the same
    282         $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
    283         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    284         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    285         $this->assertFalse( add_blog_option( 1, $key, $value ) );
    286         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    287         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    288 
    289         $this->assertTrue( delete_blog_option( 1, $key ) );
    290         $this->assertFalse( get_blog_option( 1, $key ) );
    291         $this->assertFalse( get_option( $key ) ); // check get_option()
    292         $this->assertFalse( delete_blog_option( 1, $key ) );
    293         $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
    294         $this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
    295         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    296         $this->assertTrue( delete_blog_option( 1, $key2 ) );
    297         $this->assertFalse( get_blog_option( 1, $key2 ) );
    298         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    299     }
    300 }
    301 endif;
  • trunk/tests/option/transient.php

    r903 r904  
    22
    33/**
    4  * @group options
     4 * @group option
    55 */
    6 class TestOption extends WP_UnitTestCase {
    7     function setUp() {
    8         parent::setUp();
    9     }
    10 
    11     function tearDown() {
    12         parent::tearDown();
    13     }
    14 
    15     function __return_foo() {
    16         return 'foo';
    17     }
    18 
    19     function test_the_basics() {
    20         $key = rand_str();
    21         $key2 = rand_str();
    22         $value = rand_str();
    23         $value2 = rand_str();
    24 
    25         $this->assertFalse( get_option( 'doesnotexist' ) );
    26         $this->assertTrue( add_option( $key, $value ) );
    27         $this->assertEquals( $value, get_option( $key ) );
    28         $this->assertFalse( add_option( $key, $value ) );  // Already exists
    29         $this->assertFalse( update_option( $key, $value ) );  // Value is the same
    30         $this->assertTrue( update_option( $key, $value2 ) );
    31         $this->assertEquals( $value2, get_option( $key ) );
    32         $this->assertFalse( add_option( $key, $value ) );
    33         $this->assertEquals( $value2, get_option( $key ) );
    34         $this->assertTrue( delete_option( $key ) );
    35         $this->assertFalse( get_option( $key ) );
    36         $this->assertFalse( delete_option( $key ) );
    37 
    38         $this->assertTrue( update_option( $key2, $value2 ) );
    39         $this->assertEquals( $value2, get_option( $key2 ) );
    40         $this->assertTrue( delete_option( $key2 ) );
    41         $this->assertFalse( get_option( $key2 ) );
    42     }
    43 
    44     function test_default_filter() {
    45         $random = rand_str();
    46 
    47         $this->assertFalse( get_option( 'doesnotexist' ) );
    48 
    49         // Default filter overrides $default arg.
    50         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    51         $this->assertEquals( 'foo', get_option( 'doesnotexist', 'bar' ) );
    52 
    53         // Remove the filter and the $default arg is honored.
    54         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    55         $this->assertEquals( 'bar', get_option( 'doesnotexist', 'bar' ) );
    56 
    57         // Once the option exists, the $default arg and the default filter are ignored.
    58         add_option( 'doesnotexist', $random );
    59         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    60         add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    61         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
    62         remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    63 
    64         // Cleanup
    65         $this->assertTrue( delete_option( 'doesnotexist' ) );
    66         $this->assertFalse( get_option( 'doesnotexist' ) );
    67     }
    68 
    69     function test_serialized_data() {
    70         $key = rand_str();
    71         $value = array( 'foo' => true, 'bar' => true );
    72 
    73         $this->assertTrue( add_option( $key, $value ) );
    74         $this->assertEquals( $value, get_option( $key ) );
    75 
    76         $value = (object) $value;
    77         $this->assertTrue( update_option( $key, $value ) );
    78         $this->assertEquals( $value, get_option( $key ) );
    79         $this->assertTrue( delete_option( $key ) );
    80     }
    81 }
    82 
    83 /**
    84  * @group options
    85  */
    86 class TestSiteOption extends WP_UnitTestCase {
    87     function __return_foo() {
    88         return 'foo';
    89     }
    90 
    91     function test_the_basics() {
    92         $key = rand_str();
    93         $key2 = rand_str();
    94         $value = rand_str();
    95         $value2 = rand_str();
    96 
    97         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    98         $this->assertTrue( add_site_option( $key, $value ) );
    99         $this->assertEquals( $value, get_site_option( $key ) );
    100         $this->assertFalse( add_site_option( $key, $value ) );  // Already exists
    101         $this->assertFalse( update_site_option( $key, $value ) );  // Value is the same
    102         $this->assertTrue( update_site_option( $key, $value2 ) );
    103         $this->assertEquals( $value2, get_site_option( $key ) );
    104         $this->assertFalse( add_site_option( $key, $value ) );
    105         $this->assertEquals( $value2, get_site_option( $key ) );
    106         $this->assertTrue( delete_site_option( $key ) );
    107         $this->assertFalse( get_site_option( $key ) );
    108         $this->assertFalse( delete_site_option( $key ) );
    109 
    110         $this->assertTrue( update_site_option( $key2, $value2 ) );
    111         $this->assertEquals( $value2, get_site_option( $key2 ) );
    112         $this->assertTrue( delete_site_option( $key2 ) );
    113         $this->assertFalse( get_site_option( $key2 ) );
    114     }
    115 
    116     function test_default_filter() {
    117         $random = rand_str();
    118 
    119         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    120 
    121         // Default filter overrides $default arg.
    122         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    123         $this->assertEquals( 'foo', get_site_option( 'doesnotexist', 'bar' ) );
    124 
    125         // Remove the filter and the $default arg is honored.
    126         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    127         $this->assertEquals( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
    128 
    129         // Once the option exists, the $default arg and the default filter are ignored.
    130         add_site_option( 'doesnotexist', $random );
    131         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    132         add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    133         $this->assertEquals( $random, get_site_option( 'doesnotexist', 'foo' ) );
    134         remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    135 
    136         // Cleanup
    137         $this->assertTrue( delete_site_option( 'doesnotexist' ) );
    138         $this->assertFalse( get_site_option( 'doesnotexist' ) );
    139     }
    140 
    141     function test_serialized_data() {
    142         $key = rand_str();
    143         $value = array( 'foo' => true, 'bar' => true );
    144 
    145         $this->assertTrue( add_site_option( $key, $value ) );
    146         $this->assertEquals( $value, get_site_option( $key ) );
    147 
    148         $value = (object) $value;
    149         $this->assertTrue( update_site_option( $key, $value ) );
    150         $this->assertEquals( $value, get_site_option( $key ) );
    151         $this->assertTrue( delete_site_option( $key ) );
    152     }
    153 
    154     // #15497 - ensure update_site_option will add options with false-y values
    155     function test_update_adds_falsey_value() {
    156         $key = rand_str();
    157         $value = 0;
    158 
    159         delete_site_option( $key );
    160         $this->assertTrue( update_site_option( $key, $value ) );
    161         wp_cache_flush(); // ensure we're getting the value from the DB
    162         $this->assertEquals( $value, get_site_option( $key ) );
    163     }
    164 
    165     // #18955 - ensure get_site_option doesn't cache the default value for non-existent options
    166     function test_get_doesnt_cache_default_value() {
    167         $option = rand_str();
    168         $default = 'a default';
    169 
    170         $this->assertEquals( get_site_option( $option, $default ), $default );
    171         $this->assertFalse( get_site_option( $option ) );
    172     }
    173 }
    174 
    175 /**
    176  * @group options
    177  */
    178 class TestTransient extends WP_UnitTestCase {
    179     function setUp() {
    180         parent::setUp();
    181     }
    182 
    183     function tearDown() {
    184         parent::tearDown();
    185     }
     6class Tests_Option_Transient extends WP_UnitTestCase {
    1867
    1878    function test_the_basics() {
     
    21435    }
    21536}
    216 
    217 /**
    218  * @group options
    219  */
    220 class TestSiteTransient extends WP_UnitTestCase {
    221     function setUp() {
    222         parent::setUp();
    223     }
    224 
    225     function tearDown() {
    226         parent::tearDown();
    227     }
    228 
    229     function test_the_basics() {
    230         $key = rand_str();
    231         $value = rand_str();
    232         $value2 = rand_str();
    233 
    234         $this->assertFalse( get_site_transient( 'doesnotexist' ) );
    235         $this->assertTrue( set_site_transient( $key, $value ) );
    236         $this->assertEquals( $value, get_site_transient( $key ) );
    237         $this->assertFalse( set_site_transient( $key, $value ) );
    238         $this->assertTrue( set_site_transient( $key, $value2 ) );
    239         $this->assertEquals( $value2, get_site_transient( $key ) );
    240         $this->assertTrue( delete_site_transient( $key ) );
    241         $this->assertFalse( get_site_transient( $key ) );
    242         $this->assertFalse( delete_site_transient( $key ) );
    243     }
    244 
    245     function test_serialized_data() {
    246         $key = rand_str();
    247         $value = array( 'foo' => true, 'bar' => true );
    248 
    249         $this->assertTrue( set_site_transient( $key, $value ) );
    250         $this->assertEquals( $value, get_site_transient( $key ) );
    251 
    252         $value = (object) $value;
    253         $this->assertTrue( set_site_transient( $key, $value ) );
    254         $this->assertEquals( $value, get_site_transient( $key ) );
    255         $this->assertTrue( delete_site_transient( $key ) );
    256     }
    257 }
    258 
    259 if ( is_multisite() ) :
    260 /**
    261  * @group options
    262  */
    263 class TestBlogOption extends WP_UnitTestCase {
    264     function test_from_same_site() {
    265         $key = rand_str();
    266         $key2 = rand_str();
    267         $value = rand_str();
    268         $value2 = rand_str();
    269 
    270         $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
    271         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    272 
    273         $this->assertTrue( add_blog_option( 1, $key, $value ) );
    274         // Assert all values of $blog_id that means the current or main blog (the same here).
    275         $this->assertEquals( $value, get_blog_option( 1, $key ) );
    276         $this->assertEquals( $value, get_blog_option( null, $key ) );
    277         $this->assertEquals( $value, get_blog_option( '1', $key ) );
    278         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    279 
    280         $this->assertFalse( add_blog_option( 1, $key, $value ) );  // Already exists
    281         $this->assertFalse( update_blog_option( 1, $key, $value ) );  // Value is the same
    282         $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
    283         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    284         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    285         $this->assertFalse( add_blog_option( 1, $key, $value ) );
    286         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    287         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    288 
    289         $this->assertTrue( delete_blog_option( 1, $key ) );
    290         $this->assertFalse( get_blog_option( 1, $key ) );
    291         $this->assertFalse( get_option( $key ) ); // check get_option()
    292         $this->assertFalse( delete_blog_option( 1, $key ) );
    293         $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
    294         $this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
    295         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    296         $this->assertTrue( delete_blog_option( 1, $key2 ) );
    297         $this->assertFalse( get_blog_option( 1, $key2 ) );
    298         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    299     }
    300 }
    301 endif;
  • trunk/tests/post/filtering.php

    r903 r904  
    66/**
    77 * @group post
     8 * @group formatting
    89 */
    9 class TestPostFiltering extends WP_UnitTestCase {
     10class Tests_Post_Filtering extends WP_UnitTestCase {
    1011    function setUp() {
    1112        parent::setUp();
  • trunk/tests/query.php

    r903 r904  
    1010 * @group rewrite
    1111 */
    12 class TestWPQueryVars extends WP_UnitTestCase {
     12class Tests_Query extends WP_UnitTestCase {
    1313
    1414    protected $page_ids;
     
    631631    // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    632632}
    633 
    634 /**
    635  * @group query
    636  * @group rewrite
    637  */
    638 class TestWPQueryVerbosePageRules extends TestWPQueryVars {
    639     function setUp() {
    640         parent::setUp();
    641         global $wp_rewrite;
    642         update_option( 'permalink_structure', '/%category%/%year%/%postname%/' );
    643         create_initial_taxonomies();
    644         $GLOBALS['wp_rewrite']->init();
    645         flush_rewrite_rules();
    646     }
    647 }
  • trunk/tests/query/results.php

    r903 r904  
    88 * @group query
    99 */
    10 class TestWPQueryPosts extends WP_UnitTestCase {
     10class Tests_Query_Results extends WP_UnitTestCase {
    1111    protected $q;
    1212
  • trunk/tests/shortcode.php

    r903 r904  
    11<?php
    22/**
    3  * @group shortcodes
     3 * @group shortcode
    44 */
    5 class TestShortcode extends WP_UnitTestCase {
     5class Tests_Shortcode extends WP_UnitTestCase {
    66
    77    protected $shortcodes = array( 'footag', 'bartag', 'baztag', 'dumptag' );
  • trunk/tests/test_includes_pluggable.php

    r902 r904  
    270270    }
    271271}
    272 
    273 /**
    274  * @group pluggable
    275  * @group user
    276  */
    277 class TestUserFunction extends WP_UnitTestCase {
    278     /**
    279      * @ticket 13317
    280      */
    281     function test_get_userdata() {
    282         $id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    283         $this->assertFalse( get_userdata( 0 ) );
    284         $this->assertFalse( get_userdata( '0' ) );
    285         $this->assertFalse( get_userdata( 'string' ) );
    286         $this->assertFalse( get_userdata( array( 'array' ) ) );
    287     }
    288 }
  • trunk/tests/theme/WPTheme.php

    r903 r904  
    33 * @group themes
    44 */
    5 class Test_WP_Theme extends WP_UnitTestCase {
     5class Tests_Theme_WPTheme extends WP_UnitTestCase {
    66    function setUp() {
    77        parent::setUp();
  • trunk/tests/upload.php

    r903 r904  
    66 * @group media
    77 */
    8 class TestUploadFunctions extends WP_UnitTestCase {
     8class Tests_Upload extends WP_UnitTestCase {
    99
    1010    var $siteurl;
  • trunk/tests/url.php

    r903 r904  
    22
    33// tests for link-template.php and related URL functions
    4 class TestSSLLinks extends WP_UnitTestCase {
     4class Tests_URL extends WP_UnitTestCase {
    55    var $_old_server;
    66    function setUp() {
  • trunk/tests/user.php

    r903 r904  
    55 * @group user
    66 */
    7 class TestWPUser extends WP_UnitTestCase {
     7class Tests_User_User extends WP_UnitTestCase {
    88
    99    protected $_deprecated_errors = array();
     
    506506        $this->assertNull( get_post( $post_id ) );
    507507    }
     508
     509    /**
     510     * @ticket 13317
     511     */
     512    function test_get_userdata() {
     513        $this->assertFalse( get_userdata( 0 ) );
     514        $this->assertFalse( get_userdata( '0' ) );
     515        $this->assertFalse( get_userdata( 'string' ) );
     516        $this->assertFalse( get_userdata( array( 'array' ) ) );
     517    }
    508518}
  • trunk/tests/user/author.php

    r903 r904  
    77 * @group user
    88 */
    9 class TestWPAuthor extends WP_UnitTestCase {
     9class Tests_User_Author extends WP_UnitTestCase {
    1010    protected $old_post_id = 0;
    1111    protected $author_id = 0;
  • trunk/tests/user/capabilities.php

    r903 r904  
    77 * @group capabilities
    88 */
    9 class WPTestUserCapabilities extends WP_UnitTestCase {
     9class Tests_User_Capabilities extends WP_UnitTestCase {
    1010    var $user_ids = array();
    1111
  • trunk/tests/user/mapMetaCap.php

    r903 r904  
    55 * @group capabilities
    66 */
    7 class TestMapMetaCap extends WP_UnitTestCase {
     7class Tests_User_MapMetaCap extends WP_UnitTestCase {
    88    var $super_admins = null;
    99
  • trunk/tests/xmlrpc/Disabled.php

    r903 r904  
    11<?php
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php');
    3 include_once(ABSPATH . WPINC . '/class-IXR.php');
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php');
     2
     3require_once ABSPATH . 'wp-admin/includes/admin.php';
     4require_once ABSPATH . WPINC . '/class-IXR.php';
     5require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
    56
    67/**
    78 * @group xmlrpc
    89 */
    9 class TestXMLRPCServer_Disabled extends WP_UnitTestCase {
     10class Tests_XMLRPC_Disabled extends WP_UnitTestCase {
    1011    function test_disabled() {
    1112        $myxmlrpcserver = new wp_xmlrpc_server();
  • trunk/tests/xmlrpc/mt/getRecentPostTitles.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_mt_getRecentPostTitles extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_mt_getRecentPostTitles extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/mw/editPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_mw_editPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/mw/getPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_mw_getPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/mw/getRecentPosts.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/mw/newPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_mw_newPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_mw_newPost extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/deletePost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_deletePost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_deletePost extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/deleteTerm.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_deleteTerm extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_deleteTerm extends WP_XMLRPC_UnitTestCase {
    77    var $term;
    88
  • trunk/tests/xmlrpc/wp/editPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_editPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/editTerm.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_editTerm extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_editTerm extends WP_XMLRPC_UnitTestCase {
    77    var $parent_term;
    88    var $child_term;
  • trunk/tests/xmlrpc/wp/getComment.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getComment extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
    77    var $post_id;
    88    var $parent_comment_id;
  • trunk/tests/xmlrpc/wp/getComments.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getComments extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getComments extends WP_XMLRPC_UnitTestCase {
    77    var $post_id;
    88
  • trunk/tests/xmlrpc/wp/getMediaItem.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
    77    var $post_id;
    88    var $attachment_data;
  • trunk/tests/xmlrpc/wp/getOptions.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getOptions extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/getPage.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPage extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/wp/getPageList.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPageList extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPageList extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/wp/getPages.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPages extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/wp/getPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPost extends WP_XMLRPC_UnitTestCase {
    77    var $post_data;
    88    var $post_id;
  • trunk/tests/xmlrpc/wp/getPostType.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPostType extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase {
    77    var $cpt_name;
    88    var $cpt_args;
  • trunk/tests/xmlrpc/wp/getPostTypes.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPostTypes extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPostTypes extends WP_XMLRPC_UnitTestCase {
    77    function test_invalid_username_password() {
    88        $result = $this->myxmlrpcserver->wp_getPostTypes( array( 1, 'username', 'password', 'post' ) );
  • trunk/tests/xmlrpc/wp/getPosts.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getPosts extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/getTaxonomies.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getTaxonomies extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getTaxonomies extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/getTaxonomy.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getTaxonomy extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getTaxonomy extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/getTerm.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getTerm extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getTerm extends WP_XMLRPC_UnitTestCase {
    77    var $term;
    88
  • trunk/tests/xmlrpc/wp/getTerms.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_getTerms extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/newPost.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_newPost extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase {
    77
    88    function test_invalid_username_password() {
  • trunk/tests/xmlrpc/wp/newTerm.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_newTerm extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_newTerm extends WP_XMLRPC_UnitTestCase {
    77    var $parent_term;
    88
  • trunk/tests/xmlrpc/wp/uploadFile.php

    r903 r904  
    44 * @group xmlrpc
    55 */
    6 class TestXMLRPCServer_wp_uploadFile extends WP_XMLRPC_UnitTestCase {
     6class Tests_XMLRPC_wp_uploadFile extends WP_XMLRPC_UnitTestCase {
    77    function test_valid_attachment() {
    88        $this->make_user_by_role( 'editor' );
Note: See TracChangeset for help on using the changeset viewer.