mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-07 22:24:36 +00:00
Options, Meta APIs: Rename prime_options() to wp_load_options().
This clearly separates these functions which are intended to be used by external developers from the existing `_prime_*_caches()` functions which are primarily intended for internal usage. The term "load" is additionally more accessible than "prime". This changeset renames the above function, as well as the wrapper function `prime_options_by_group()` to `wp_load_options_by_group()`. Props peterwilsoncc, joemcgill, hellofromTonya, poran766, flixos90. Fixes #58962. git-svn-id: https://develop.svn.wordpress.org/trunk@56990 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Test prime_options().
|
||||
* Test wp_load_options().
|
||||
*
|
||||
* @group option
|
||||
*
|
||||
* @covers ::prime_options
|
||||
* @covers ::wp_load_options
|
||||
*/
|
||||
class Tests_Option_PrimeOptions extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that prime_options() primes multiple options.
|
||||
* Tests that wp_load_options() loads multiple options.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options() {
|
||||
// Create some options to prime.
|
||||
$options_to_prime = array(
|
||||
public function test_wp_load_options() {
|
||||
// Create some options to load.
|
||||
$options_to_load = array(
|
||||
'option1',
|
||||
'option2',
|
||||
'option3',
|
||||
@@ -26,30 +26,30 @@ class Tests_Option_PrimeOptions extends WP_UnitTestCase {
|
||||
* clear the cache for the options,
|
||||
* check options are not in cache initially.
|
||||
*/
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
update_option( $option, "value_$option", false );
|
||||
wp_cache_delete( $option, 'options' );
|
||||
$this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
|
||||
}
|
||||
|
||||
// Call the prime_options function to prime the options.
|
||||
prime_options( $options_to_prime );
|
||||
// Call the wp_load_options function to load the options.
|
||||
wp_load_options( $options_to_load );
|
||||
|
||||
// Store the initial database query count.
|
||||
$initial_query_count = get_num_queries();
|
||||
|
||||
// Check that options are only in the 'options' cache group.
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
$this->assertSame(
|
||||
wp_cache_get( $option, 'options' ),
|
||||
get_option( $option ),
|
||||
"$option was not primed to the 'options' cache group."
|
||||
"$option was not loaded to the 'options' cache group."
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
wp_cache_get( $option, 'notoptions' ),
|
||||
get_option( $option ),
|
||||
"$option was primed to the 'notoptions' cache group."
|
||||
"$option was loaded to the 'notoptions' cache group."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ class Tests_Option_PrimeOptions extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests prime_options() with options that do not exist in the database.
|
||||
* Tests wp_load_options() with options that do not exist in the database.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options_with_nonexistent_options() {
|
||||
// Create some options to prime.
|
||||
$options_to_prime = array(
|
||||
public function test_wp_load_options_with_nonexistent_options() {
|
||||
// Create some options to load.
|
||||
$options_to_load = array(
|
||||
'option1',
|
||||
'option2',
|
||||
);
|
||||
@@ -78,50 +78,50 @@ class Tests_Option_PrimeOptions extends WP_UnitTestCase {
|
||||
* clear the cache for the options,
|
||||
* check options are not in cache initially.
|
||||
*/
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
$this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
|
||||
}
|
||||
|
||||
// Call the prime_options function to prime the options.
|
||||
prime_options( $options_to_prime );
|
||||
// Call the wp_load_options function to load the options.
|
||||
wp_load_options( $options_to_load );
|
||||
|
||||
// Check that options are not in the cache or database.
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
$this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
|
||||
}
|
||||
|
||||
// Check that options are present in the notoptions cache.
|
||||
$new_notoptions = wp_cache_get( 'notoptions', 'options' );
|
||||
$this->assertIsArray( $new_notoptions, 'The notoptions cache should be an array.' );
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
$this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests prime_options() with an empty array.
|
||||
* Tests wp_load_options() with an empty array.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options_with_empty_array() {
|
||||
public function test_wp_load_options_with_empty_array() {
|
||||
$alloptions = wp_load_alloptions();
|
||||
$notoptions = wp_cache_get( 'notoptions', 'options' );
|
||||
|
||||
prime_options( array() );
|
||||
wp_load_options( array() );
|
||||
|
||||
$this->assertSame( $alloptions, wp_cache_get( 'alloptions', 'options' ), 'The alloptions cache was modified.' );
|
||||
$this->assertSame( $notoptions, wp_cache_get( 'notoptions', 'options' ), 'The notoptions cache was modified.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that prime_options handles an empty "notoptions" cache.
|
||||
* Tests that wp_load_options handles an empty "notoptions" cache.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options_handles_empty_notoptions_cache() {
|
||||
public function test_wp_load_options_handles_empty_notoptions_cache() {
|
||||
wp_cache_delete( 'notoptions', 'options' );
|
||||
|
||||
prime_options( array( 'nonexistent_option' ) );
|
||||
wp_load_options( array( 'nonexistent_option' ) );
|
||||
|
||||
$notoptions = wp_cache_get( 'notoptions', 'options' );
|
||||
$this->assertIsArray( $notoptions, 'The notoptions cache should be an array.' );
|
||||
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Test prime_options_by_group().
|
||||
* Test wp_load_options_by_group().
|
||||
*
|
||||
* @group option
|
||||
*
|
||||
* @covers ::prime_options_by_group
|
||||
* @covers ::wp_load_options_by_group
|
||||
*/
|
||||
class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that prime_options_by_group() only primes options in the specified group.
|
||||
* Tests that wp_load_options_by_group() only loads options in the specified group.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options_by_group() {
|
||||
public function test_wp_load_options_by_group() {
|
||||
global $new_allowed_options;
|
||||
|
||||
// Create some options to prime.
|
||||
// Create some options to load.
|
||||
$new_allowed_options = array(
|
||||
'group1' => array(
|
||||
'option1',
|
||||
@@ -27,7 +27,7 @@ class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
|
||||
),
|
||||
);
|
||||
|
||||
$options_to_prime = array(
|
||||
$options_to_load = array(
|
||||
'option1',
|
||||
'option2',
|
||||
'option3',
|
||||
@@ -38,35 +38,35 @@ class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
|
||||
* clear the cache for the options,
|
||||
* check options are not in cache initially.
|
||||
*/
|
||||
foreach ( $options_to_prime as $option ) {
|
||||
foreach ( $options_to_load as $option ) {
|
||||
update_option( $option, "value_$option", false );
|
||||
wp_cache_delete( $option, 'options' );
|
||||
$this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
|
||||
}
|
||||
|
||||
// Call the prime_options_by_group function to prime the options.
|
||||
prime_options_by_group( 'group1' );
|
||||
// Call the wp_load_options_by_group function to load the options.
|
||||
wp_load_options_by_group( 'group1' );
|
||||
|
||||
// Check that options are now in the cache.
|
||||
$this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1 was not primed.' );
|
||||
$this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2 was not primed.' );
|
||||
$this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1 was not loaded.' );
|
||||
$this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2 was not loaded.' );
|
||||
|
||||
// Make sure option3 is still not in cache.
|
||||
$this->assertFalse( wp_cache_get( 'option3', 'options' ), 'option3 was not deleted from the cache.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests prime_options_by_group() with a nonexistent option group.
|
||||
* Tests wp_load_options_by_group() with a nonexistent option group.
|
||||
*
|
||||
* @ticket 58962
|
||||
*/
|
||||
public function test_prime_options_by_group_with_nonexistent_group() {
|
||||
public function test_wp_load_options_by_group_with_nonexistent_group() {
|
||||
// Make sure options are not in cache or database initially.
|
||||
$this->assertFalse( wp_cache_get( 'option1', 'options' ), 'option1 was not deleted from the cache.' );
|
||||
$this->assertFalse( wp_cache_get( 'option2', 'options' ), 'option2 was not deleted from the cache.' );
|
||||
|
||||
// Call the prime_options_by_group function with a nonexistent group.
|
||||
prime_options_by_group( 'nonexistent_group' );
|
||||
// Call the wp_load_options_by_group function with a nonexistent group.
|
||||
wp_load_options_by_group( 'nonexistent_group' );
|
||||
|
||||
// Check that options are still not in the cache or database.
|
||||
$this->assertFalse( wp_cache_get( 'option1', 'options' ), 'option1 was not deleted from the cache.' );
|
||||
Reference in New Issue
Block a user