wordpress-develop/tests/phpunit/tests/option/wpLoadOptionsByGroup.php
Felix Arntz 51ae4e67d0 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
2023-10-23 21:27:31 +00:00

76 lines
2.3 KiB
PHP

<?php
/**
* Test wp_load_options_by_group().
*
* @group option
*
* @covers ::wp_load_options_by_group
*/
class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
/**
* Tests that wp_load_options_by_group() only loads options in the specified group.
*
* @ticket 58962
*/
public function test_wp_load_options_by_group() {
global $new_allowed_options;
// Create some options to load.
$new_allowed_options = array(
'group1' => array(
'option1',
'option2',
),
'group2' => array(
'option3',
),
);
$options_to_load = array(
'option1',
'option2',
'option3',
);
/*
* Set values for the options,
* clear the cache for the options,
* check options are not in cache initially.
*/
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 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 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 wp_load_options_by_group() with a nonexistent option group.
*
* @ticket 58962
*/
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 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.' );
$this->assertFalse( wp_cache_get( 'option2', 'options' ), 'option2 was not deleted from the cache.' );
}
}