Make WordPress Core

Changeset 904 in tests for trunk/tests/option/blogOption.php


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

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

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

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

Location:
trunk/tests/option
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.