Changeset 904 in tests for trunk/tests/option/siteOption.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/siteOption.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 } 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 { 6 class Tests_Option_SiteOption extends WP_UnitTestCase { 87 7 function __return_foo() { 88 8 return 'foo'; … … 172 92 } 173 93 } 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.