Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105981 additions and 78187 deletions

View File

@@ -21,21 +21,21 @@ class Tests_Cache extends WP_UnitTestCase {
function &init_cache() {
global $wp_object_cache;
$cache_class = get_class( $wp_object_cache );
$cache = new $cache_class();
$cache = new $cache_class();
$cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
return $cache;
}
function test_miss() {
$this->assertEquals( NULL, $this->cache->get( 'test_miss' ) );
$this->assertEquals( null, $this->cache->get( 'test_miss' ) );
}
function test_add_get() {
$key = __FUNCTION__;
$val = 'val';
$this->cache->add($key, $val);
$this->assertEquals($val, $this->cache->get($key));
$this->cache->add( $key, $val );
$this->assertEquals( $val, $this->cache->get( $key ) );
}
function test_add_get_0() {
@@ -43,94 +43,95 @@ class Tests_Cache extends WP_UnitTestCase {
$val = 0;
// you can store zero in the cache
$this->cache->add($key, $val);
$this->assertEquals($val, $this->cache->get($key));
$this->cache->add( $key, $val );
$this->assertEquals( $val, $this->cache->get( $key ) );
}
function test_add_get_null() {
$key = __FUNCTION__;
$val = null;
$this->assertTrue( $this->cache->add($key, $val) );
$this->assertTrue( $this->cache->add( $key, $val ) );
// null is converted to empty string
$this->assertEquals( '', $this->cache->get($key) );
$this->assertEquals( '', $this->cache->get( $key ) );
}
function test_add() {
$key = __FUNCTION__;
$key = __FUNCTION__;
$val1 = 'val1';
$val2 = 'val2';
// add $key to the cache
$this->assertTrue($this->cache->add($key, $val1));
$this->assertEquals($val1, $this->cache->get($key));
$this->assertTrue( $this->cache->add( $key, $val1 ) );
$this->assertEquals( $val1, $this->cache->get( $key ) );
// $key is in the cache, so reject new calls to add()
$this->assertFalse($this->cache->add($key, $val2));
$this->assertEquals($val1, $this->cache->get($key));
$this->assertFalse( $this->cache->add( $key, $val2 ) );
$this->assertEquals( $val1, $this->cache->get( $key ) );
}
function test_replace() {
$key = __FUNCTION__;
$val = 'val1';
$key = __FUNCTION__;
$val = 'val1';
$val2 = 'val2';
// memcached rejects replace() if the key does not exist
$this->assertFalse($this->cache->replace($key, $val));
$this->assertFalse($this->cache->get($key));
$this->assertTrue($this->cache->add($key, $val));
$this->assertEquals($val, $this->cache->get($key));
$this->assertTrue($this->cache->replace($key, $val2));
$this->assertEquals($val2, $this->cache->get($key));
$this->assertFalse( $this->cache->replace( $key, $val ) );
$this->assertFalse( $this->cache->get( $key ) );
$this->assertTrue( $this->cache->add( $key, $val ) );
$this->assertEquals( $val, $this->cache->get( $key ) );
$this->assertTrue( $this->cache->replace( $key, $val2 ) );
$this->assertEquals( $val2, $this->cache->get( $key ) );
}
function test_set() {
$key = __FUNCTION__;
$key = __FUNCTION__;
$val1 = 'val1';
$val2 = 'val2';
// memcached accepts set() if the key does not exist
$this->assertTrue($this->cache->set($key, $val1));
$this->assertEquals($val1, $this->cache->get($key));
$this->assertTrue( $this->cache->set( $key, $val1 ) );
$this->assertEquals( $val1, $this->cache->get( $key ) );
// Second set() with same key should be allowed
$this->assertTrue($this->cache->set($key, $val2));
$this->assertEquals($val2, $this->cache->get($key));
$this->assertTrue( $this->cache->set( $key, $val2 ) );
$this->assertEquals( $val2, $this->cache->get( $key ) );
}
function test_flush() {
global $_wp_using_ext_object_cache;
if ( $_wp_using_ext_object_cache )
if ( $_wp_using_ext_object_cache ) {
return;
}
$key = __FUNCTION__;
$val = 'val';
$this->cache->add($key, $val);
$this->cache->add( $key, $val );
// item is visible to both cache objects
$this->assertEquals($val, $this->cache->get($key));
$this->assertEquals( $val, $this->cache->get( $key ) );
$this->cache->flush();
// If there is no value get returns false.
$this->assertFalse($this->cache->get($key));
$this->assertFalse( $this->cache->get( $key ) );
}
// Make sure objects are cloned going to and from the cache
function test_object_refs() {
$key = __FUNCTION__ . '_1';
$object_a = new stdClass;
$key = __FUNCTION__ . '_1';
$object_a = new stdClass;
$object_a->foo = 'alpha';
$this->cache->set( $key, $object_a );
$object_a->foo = 'bravo';
$object_b = $this->cache->get( $key );
$object_b = $this->cache->get( $key );
$this->assertEquals( 'alpha', $object_b->foo );
$object_b->foo = 'charlie';
$this->assertEquals( 'bravo', $object_a->foo );
$key = __FUNCTION__ . '_2';
$object_a = new stdClass;
$key = __FUNCTION__ . '_2';
$object_a = new stdClass;
$object_a->foo = 'alpha';
$this->cache->add( $key, $object_a );
$object_a->foo = 'bravo';
$object_b = $this->cache->get( $key );
$object_b = $this->cache->get( $key );
$this->assertEquals( 'alpha', $object_b->foo );
$object_b->foo = 'charlie';
$this->assertEquals( 'bravo', $object_a->foo );
@@ -211,7 +212,7 @@ class Tests_Cache extends WP_UnitTestCase {
$this->assertTrue( $this->cache->delete( $key ) );
$this->assertFalse( $this->cache->get( $key ) );
$this->assertFalse( $this->cache->delete( $key, 'default') );
$this->assertFalse( $this->cache->delete( $key, 'default' ) );
}
function test_wp_cache_delete() {
@@ -230,15 +231,16 @@ class Tests_Cache extends WP_UnitTestCase {
// Delete returns (bool) true when key is not set and $force is true
// $this->assertTrue( wp_cache_delete( $key, 'default', true ) );
$this->assertFalse( wp_cache_delete( $key, 'default') );
$this->assertFalse( wp_cache_delete( $key, 'default' ) );
}
function test_switch_to_blog() {
if ( ! method_exists( $this->cache, 'switch_to_blog' ) )
if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) {
return;
}
$key = __FUNCTION__;
$val = 'val1';
$key = __FUNCTION__;
$val = 'val1';
$val2 = 'val2';
if ( ! is_multisite() ) {
@@ -286,7 +288,7 @@ class Tests_Cache extends WP_UnitTestCase {
if ( wp_using_ext_object_cache() ) {
// External caches will contain property values that contain non-matching resource IDs
$this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache );
$this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache );
} else {
$this->assertEquals( $wp_object_cache, $new_blank_cache_object );
}