| 308 | |
| 309 | /** |
| 310 | * Test object cache values are the same going in as coing out. |
| 311 | * @ticket 30430 |
| 312 | */ |
| 313 | function test_wp_object_cache() { |
| 314 | // String test |
| 315 | $expected = (string) 'Some simple string'; |
| 316 | |
| 317 | // Verify string set |
| 318 | wp_cache_set( 'string', $expected ); |
| 319 | $this->assertEquals( $expected, wp_cache_get( 'string' ) ); |
| 320 | |
| 321 | // Integer test |
| 322 | $expected = (integer) 1234567; |
| 323 | |
| 324 | // Verify interger set |
| 325 | wp_cache_set( 'integer', $expected ); |
| 326 | $this->assertEquals( $expected, wp_cache_get( 'integer' ) ); |
| 327 | |
| 328 | // Float test |
| 329 | $expected = (float) 123456.78; |
| 330 | |
| 331 | // Verify float set |
| 332 | wp_cache_set( 'float', $expected ); |
| 333 | $this->assertEquals( $expected, wp_cache_get( 'float' ) ); |
| 334 | |
| 335 | // Standard class test |
| 336 | $expected = new StdClass(); |
| 337 | $expected->test = 'the'; |
| 338 | $expected->test2 = 'the'; |
| 339 | $expected->test3 = 'the'; |
| 340 | |
| 341 | // Verify standard class set |
| 342 | wp_cache_set( 'stdclass', $expected ); |
| 343 | $this->assertEquals( $expected, wp_cache_get( 'stdclass' ) ); |
| 344 | |
| 345 | // Array test |
| 346 | $expected = array(); |
| 347 | $expected['test'] = 'the'; |
| 348 | $expected['test2'] = 'the'; |
| 349 | $expected['test3'] = 'the'; |
| 350 | |
| 351 | // Verify array set |
| 352 | wp_cache_set( 'array', $expected ); |
| 353 | $this->assertEquals( $expected, wp_cache_get( 'array' ) ); |
| 354 | |
| 355 | // Array of objects test |
| 356 | $expected = array(); |
| 357 | $expected['test'] = new StdClass(); |
| 358 | $expected['test']->test = 'the'; |
| 359 | $expected['test']->test2 = 'the'; |
| 360 | $expected['test']->test3 = 'the'; |
| 361 | |
| 362 | // Verify array of objects set |
| 363 | wp_cache_set( 'array-of-objects', $expected ); |
| 364 | $this->assertEquals( $expected, wp_cache_get( 'array-of-objects' ) ); |
| 365 | |
| 366 | // Array of array of objects test |
| 367 | $expected = array(); |
| 368 | $expected['test'] = array(); |
| 369 | $expected['test']['leveltwo'] = new StdClass(); |
| 370 | $expected['test']['leveltwo']->test = 'something'; |
| 371 | $expected['test']['leveltwo']->test2 = 'something'; |
| 372 | $expected['test']['leveltwo']->test3 = 'something'; |
| 373 | |
| 374 | $expected['test']['leveltwoa'] = new StdClass(); |
| 375 | $expected['test']['leveltwoa']->test = 'something'; |
| 376 | $expected['test']['leveltwoa']->test2 = 'something'; |
| 377 | $expected['test']['leveltwoa']->test3 = 'something'; |
| 378 | |
| 379 | // Verify array of array of objects set |
| 380 | wp_cache_set( 'array-of-array-of-objects', $expected ); |
| 381 | $this->assertEquals( $expected, wp_cache_get( 'array-of-array-of-objects' ) ); |
| 382 | |
| 383 | // Clean up |
| 384 | wp_cache_flush(); |
| 385 | } |