Changeset 904 in tests for trunk/tests/option/siteTransient.php
- Timestamp:
- 07/18/2012 07:01:41 PM (12 years ago)
- Location:
- trunk/tests/option
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/option/siteTransient.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 { 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 } 6 class Tests_Option_SiteTransient extends WP_UnitTestCase { 228 7 229 8 function test_the_basics() { … … 256 35 } 257 36 } 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.