mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-25 13:44:30 +00:00
Tests: Rename classes in phpunit/tests/option/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650], [51651], [51860], [52264], [52265], [53489]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53494 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
110
tests/phpunit/tests/option/wpLoadAlloptions.php
Normal file
110
tests/phpunit/tests/option/wpLoadAlloptions.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Test wp_load_alloptions().
|
||||
*
|
||||
* @group option
|
||||
*/
|
||||
class Tests_Option_wpLoadAlloptions extends WP_UnitTestCase {
|
||||
protected $alloptions = null;
|
||||
|
||||
public function tear_down() {
|
||||
$this->alloptions = null;
|
||||
parent::tear_down();
|
||||
}
|
||||
|
||||
public function test_if_alloptions_is_cached() {
|
||||
$this->assertNotEmpty( wp_cache_get( 'alloptions', 'options' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_if_alloptions_is_cached
|
||||
*/
|
||||
public function test_if_cached_alloptions_is_deleted() {
|
||||
$this->assertTrue( wp_cache_delete( 'alloptions', 'options' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_if_alloptions_is_cached
|
||||
*/
|
||||
public function test_if_alloptions_are_retrieved_from_cache() {
|
||||
global $wpdb;
|
||||
$before = $wpdb->num_queries;
|
||||
wp_load_alloptions();
|
||||
$after = $wpdb->num_queries;
|
||||
|
||||
// Database has not been hit.
|
||||
$this->assertSame( $before, $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_if_cached_alloptions_is_deleted
|
||||
*/
|
||||
public function test_if_alloptions_are_retrieved_from_database() {
|
||||
global $wpdb;
|
||||
|
||||
// Delete the existing cache first.
|
||||
wp_cache_delete( 'alloptions', 'options' );
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
wp_load_alloptions();
|
||||
$after = $wpdb->num_queries;
|
||||
|
||||
// Database has been hit.
|
||||
$this->assertSame( $before + 1, $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_if_cached_alloptions_is_deleted
|
||||
*/
|
||||
public function test_filter_pre_cache_alloptions_is_called() {
|
||||
$temp = wp_installing();
|
||||
|
||||
/**
|
||||
* Set wp_installing() to false.
|
||||
*
|
||||
* If wp_installing is false and the cache is empty, the filter is called regardless if it's multisite or not.
|
||||
*/
|
||||
wp_installing( false );
|
||||
|
||||
// Delete the existing cache first.
|
||||
wp_cache_delete( 'alloptions', 'options' );
|
||||
|
||||
add_filter( 'pre_cache_alloptions', array( $this, 'return_pre_cache_filter' ) );
|
||||
$all_options = wp_load_alloptions();
|
||||
|
||||
// Value could leak to other tests if not reset.
|
||||
wp_installing( $temp );
|
||||
|
||||
// Filter was called.
|
||||
$this->assertSame( $this->alloptions, $all_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_if_alloptions_is_cached
|
||||
*/
|
||||
public function test_filter_pre_cache_alloptions_is_not_called() {
|
||||
$temp = wp_installing();
|
||||
|
||||
/**
|
||||
* Set wp_installing() to true.
|
||||
*
|
||||
* If wp_installing is true and it's multisite, the cache and filter are not used.
|
||||
* If wp_installing is true and it's not multisite, the cache is used (if not empty), and the filter not.
|
||||
*/
|
||||
wp_installing( true );
|
||||
|
||||
add_filter( 'pre_cache_alloptions', array( $this, 'return_pre_cache_filter' ) );
|
||||
wp_load_alloptions();
|
||||
|
||||
// Value could leak to other tests if not reset.
|
||||
wp_installing( $temp );
|
||||
|
||||
// Filter was not called.
|
||||
$this->assertNull( $this->alloptions );
|
||||
}
|
||||
|
||||
public function return_pre_cache_filter( $alloptions ) {
|
||||
$this->alloptions = $alloptions;
|
||||
return $this->alloptions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user