<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[57004] branches/6.4/tests/phpunit/tests/option: Options, Meta APIs: Rename `prime_options()` to `wp_load_options()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/57004">57004</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/57004","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>flixos90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-10-24 14:34:43 +0000 (Tue, 24 Oct 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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.
Merges <a href="https://core.trac.wordpress.org/changeset/56990">[56990]</a> to the 6.4 branch.
Fixes <a href="https://core.trac.wordpress.org/ticket/58962">#58962</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches64srcwpincludesoptionphp">branches/6.4/src/wp-includes/option.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branches64testsphpunittestsoptionwpLoadOptionsphp">branches/6.4/tests/phpunit/tests/option/wpLoadOptions.php</a></li>
<li><a href="#branches64testsphpunittestsoptionwpLoadOptionsByGroupphp">branches/6.4/tests/phpunit/tests/option/wpLoadOptionsByGroup.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#branches64testsphpunittestsoptionprimeOptionsphp">branches/6.4/tests/phpunit/tests/option/primeOptions.php</a></li>
<li><a href="#branches64testsphpunittestsoptionprimeOptionsByGroupphp">branches/6.4/tests/phpunit/tests/option/primeOptionsByGroup.php</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#branches64">branches/6.4/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/6.4
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/6.4 2023-10-24 14:33:23 UTC (rev 57003)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/6.4 2023-10-24 14:34:43 UTC (rev 57004)
</ins><a id="branches64"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/6.4</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43747,43751-43754,43758,43760-43765,43767-43770,43772,43774-43781,43783,43785,43790-43806,43808-43821,43825,43828,43830-43834,43836-43843,43846-43863,43867-43889,43891-43894,43897-43905,43908-43909,43911-43929,43931-43942,43946-43947,43949-43956,43959-43964,43967-43969,43988,43994,44014,44017,44047,44183,44185,44187-44206,44208-44213,44231-44232,44235,44248,44284,44287-44288
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.5:49373-49379,49381
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.8:51889
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:56974,56978,56984,56987,56991-56992,56996
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:56974,56978,56984,56987,56990-56992,56996
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches64srcwpincludesoptionphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.4/src/wp-includes/option.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.4/src/wp-includes/option.php 2023-10-24 14:33:23 UTC (rev 57003)
+++ branches/6.4/src/wp-includes/option.php 2023-10-24 14:34:43 UTC (rev 57004)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -248,17 +248,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Primes specific options into the cache with a single database query.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Loads specific options into the cache with a single database query.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Only options that do not already exist in cache will be primed.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Only options that do not already exist in cache will be loaded.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb WordPress database abstraction object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $options An array of option names to be primed.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $options An array of option names to be loaded.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function prime_options( $options ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_load_options( $options ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $alloptions = wp_load_alloptions();
</span><span class="cx" style="display: block; padding: 0 10px"> $cached_options = wp_cache_get_multiple( $options, 'options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -270,7 +270,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Bail early if there are no options to be primed.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Bail early if there are no options to be loaded.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $options_to_prime ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -321,19 +321,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Primes all options registered with a specific option group.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Loads all options registered with a specific option group.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global array $new_allowed_options
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option_group The option group to prime options for.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option_group The option group to load options for.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function prime_options_by_group( $option_group ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_load_options_by_group( $option_group ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $new_allowed_options;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $new_allowed_options[ $option_group ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- prime_options( $new_allowed_options[ $option_group ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_load_options( $new_allowed_options[ $option_group ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -340,7 +340,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Retrieves multiple options.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Options are primed as necessary first in order to use a single database query at most.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Options are loaded as necessary first in order to use a single database query at most.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -348,7 +348,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array An array of key-value pairs for the requested options.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_options( $options ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- prime_options( $options );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_load_options( $options );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $result = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $options as $option ) {
</span></span></pre></div>
<a id="branches64testsphpunittestsoptionprimeOptionsphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: branches/6.4/tests/phpunit/tests/option/primeOptions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.4/tests/phpunit/tests/option/primeOptions.php 2023-10-24 14:33:23 UTC (rev 57003)
+++ branches/6.4/tests/phpunit/tests/option/primeOptions.php 2023-10-24 14:34:43 UTC (rev 57004)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,130 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Test prime_options().
- *
- * @group option
- *
- * @covers ::prime_options
- */
-class Tests_Option_PrimeOptions extends WP_UnitTestCase {
-
- /**
- * Tests that prime_options() primes multiple options.
- *
- * @ticket 58962
- */
- public function test_prime_options() {
- // Create some options to prime.
- $options_to_prime = 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_prime 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 );
-
- // 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 ) {
- $this->assertSame(
- wp_cache_get( $option, 'options' ),
- get_option( $option ),
- "$option was not primed to the 'options' cache group."
- );
-
- $this->assertFalse(
- wp_cache_get( $option, 'notoptions' ),
- get_option( $option ),
- "$option was primed to the 'notoptions' cache group."
- );
- }
-
- // Ensure no additional database queries were made.
- $this->assertSame(
- $initial_query_count,
- get_num_queries(),
- 'Additional database queries were made.'
- );
- }
-
- /**
- * Tests prime_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(
- 'option1',
- 'option2',
- );
-
- /*
- * Set values for the options,
- * clear the cache for the options,
- * check options are not in cache initially.
- */
- foreach ( $options_to_prime 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 );
-
- // Check that options are not in the cache or database.
- foreach ( $options_to_prime 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 ) {
- $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." );
- }
- }
-
- /**
- * Tests prime_options() with an empty array.
- *
- * @ticket 58962
- */
- public function test_prime_options_with_empty_array() {
- $alloptions = wp_load_alloptions();
- $notoptions = wp_cache_get( 'notoptions', 'options' );
-
- prime_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.
- *
- * @ticket 58962
- */
- public function test_prime_options_handles_empty_notoptions_cache() {
- wp_cache_delete( 'notoptions', 'options' );
-
- prime_options( array( 'nonexistent_option' ) );
-
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- $this->assertIsArray( $notoptions, 'The notoptions cache should be an array.' );
- $this->assertArrayHasKey( 'nonexistent_option', $notoptions, 'nonexistent_option was not added to notoptions.' );
- }
-}
</del></span></pre></div>
<a id="branches64testsphpunittestsoptionprimeOptionsByGroupphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: branches/6.4/tests/phpunit/tests/option/primeOptionsByGroup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.4/tests/phpunit/tests/option/primeOptionsByGroup.php 2023-10-24 14:33:23 UTC (rev 57003)
+++ branches/6.4/tests/phpunit/tests/option/primeOptionsByGroup.php 2023-10-24 14:34:43 UTC (rev 57004)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,75 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Test prime_options_by_group().
- *
- * @group option
- *
- * @covers ::prime_options_by_group
- */
-class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
-
- /**
- * Tests that prime_options_by_group() only primes options in the specified group.
- *
- * @ticket 58962
- */
- public function test_prime_options_by_group() {
- global $new_allowed_options;
-
- // Create some options to prime.
- $new_allowed_options = array(
- 'group1' => array(
- 'option1',
- 'option2',
- ),
- 'group2' => array(
- 'option3',
- ),
- );
-
- $options_to_prime = 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_prime 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' );
-
- // 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.' );
-
- // 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.
- *
- * @ticket 58962
- */
- public function test_prime_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' );
-
- // 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.' );
- }
-}
</del></span></pre></div>
<a id="branches64testsphpunittestsoptionwpLoadOptionsphpfromrev56990trunktestsphpunittestsoptionwpLoadOptionsphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: branches/6.4/tests/phpunit/tests/option/wpLoadOptions.php (from rev 56990, trunk/tests/phpunit/tests/option/wpLoadOptions.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.4/tests/phpunit/tests/option/wpLoadOptions.php (rev 0)
+++ branches/6.4/tests/phpunit/tests/option/wpLoadOptions.php 2023-10-24 14:34:43 UTC (rev 57004)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,130 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Test wp_load_options().
+ *
+ * @group option
+ *
+ * @covers ::wp_load_options
+ */
+class Tests_Option_PrimeOptions extends WP_UnitTestCase {
+
+ /**
+ * Tests that wp_load_options() loads multiple options.
+ *
+ * @ticket 58962
+ */
+ public function test_wp_load_options() {
+ // Create some options to load.
+ $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 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_load as $option ) {
+ $this->assertSame(
+ wp_cache_get( $option, 'options' ),
+ get_option( $option ),
+ "$option was not loaded to the 'options' cache group."
+ );
+
+ $this->assertFalse(
+ wp_cache_get( $option, 'notoptions' ),
+ get_option( $option ),
+ "$option was loaded to the 'notoptions' cache group."
+ );
+ }
+
+ // Ensure no additional database queries were made.
+ $this->assertSame(
+ $initial_query_count,
+ get_num_queries(),
+ 'Additional database queries were made.'
+ );
+ }
+
+ /**
+ * Tests wp_load_options() with options that do not exist in the database.
+ *
+ * @ticket 58962
+ */
+ public function test_wp_load_options_with_nonexistent_options() {
+ // Create some options to load.
+ $options_to_load = array(
+ 'option1',
+ 'option2',
+ );
+
+ /*
+ * Set values for the options,
+ * clear the cache for the options,
+ * check options are not in cache initially.
+ */
+ foreach ( $options_to_load as $option ) {
+ $this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
+ }
+
+ // 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_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_load as $option ) {
+ $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." );
+ }
+ }
+
+ /**
+ * Tests wp_load_options() with an empty array.
+ *
+ * @ticket 58962
+ */
+ public function test_wp_load_options_with_empty_array() {
+ $alloptions = wp_load_alloptions();
+ $notoptions = wp_cache_get( 'notoptions', 'options' );
+
+ 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 wp_load_options handles an empty "notoptions" cache.
+ *
+ * @ticket 58962
+ */
+ public function test_wp_load_options_handles_empty_notoptions_cache() {
+ wp_cache_delete( 'notoptions', 'options' );
+
+ wp_load_options( array( 'nonexistent_option' ) );
+
+ $notoptions = wp_cache_get( 'notoptions', 'options' );
+ $this->assertIsArray( $notoptions, 'The notoptions cache should be an array.' );
+ $this->assertArrayHasKey( 'nonexistent_option', $notoptions, 'nonexistent_option was not added to notoptions.' );
+ }
+}
</ins></span></pre></div>
<a id="branches64testsphpunittestsoptionwpLoadOptionsByGroupphpfromrev56990trunktestsphpunittestsoptionwpLoadOptionsByGroupphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: branches/6.4/tests/phpunit/tests/option/wpLoadOptionsByGroup.php (from rev 56990, trunk/tests/phpunit/tests/option/wpLoadOptionsByGroup.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.4/tests/phpunit/tests/option/wpLoadOptionsByGroup.php (rev 0)
+++ branches/6.4/tests/phpunit/tests/option/wpLoadOptionsByGroup.php 2023-10-24 14:34:43 UTC (rev 57004)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,75 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?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.' );
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>