Changeset 904 in tests for trunk/tests/option/blogOption.php
- Timestamp:
- 07/18/2012 07:01:41 PM (12 years ago)
- Location:
- trunk/tests/option
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/option/blogOption.php
r903 r904 1 1 <?php 2 3 /**4 * @group options5 */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 exists29 $this->assertFalse( update_option( $key, $value ) ); // Value is the same30 $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 // Cleanup65 $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 options85 */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 exists101 $this->assertFalse( update_site_option( $key, $value ) ); // Value is the same102 $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 // Cleanup137 $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 values155 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 DB162 $this->assertEquals( $value, get_site_option( $key ) );163 }164 165 // #18955 - ensure get_site_option doesn't cache the default value for non-existent options166 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 options177 */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 options219 */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 2 259 3 if ( is_multisite() ) : 260 4 /** 261 * @group option s5 * @group option 262 6 */ 263 class Test BlogOption extends WP_UnitTestCase {7 class Tests_Option_BlogOption extends WP_UnitTestCase { 264 8 function test_from_same_site() { 265 9 $key = rand_str();
Note: See TracChangeset
for help on using the changeset viewer.