Changeset 904 in tests for trunk/tests/option/option.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/option.php
r903 r904 2 2 3 3 /** 4 * @group option s4 * @group option 5 5 */ 6 class TestOption extends WP_UnitTestCase { 7 function setUp() { 8 parent::setUp(); 9 } 10 11 function tearDown() { 12 parent::tearDown(); 13 } 6 class Tests_Option_Option extends WP_UnitTestCase { 14 7 15 8 function __return_foo() { … … 80 73 } 81 74 } 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 259 if ( is_multisite() ) :260 /**261 * @group options262 */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 exists281 $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same282 $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;
Note: See TracChangeset
for help on using the changeset viewer.