wordpress-develop/tests/phpunit/tests/option/siteTransient.php
John Blackbourn 4f8057f7d5 Build/Test Tools: Introduce ms-required and ms-excluded groups for tests.
Tests in the `ms-excluded` group are now excluded when running tests with multisite enabled, and tests in the `ms-required` group are excluded when running tests without multisite enabled. The end result is a significantly reduced number of skipped tests polluting PHPUnit's output, which means verbose mode can be used to more easily see which tests are skipped or incomplete, and why.

See #40531


git-svn-id: https://develop.svn.wordpress.org/trunk@40520 602fd350-edb4-49c9-b593-d223f7449a82
2017-04-22 18:58:46 +00:00

62 lines
1.7 KiB
PHP

<?php
/**
* @group option
*/
class Tests_Option_SiteTransient extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
if ( wp_using_ext_object_cache() ) {
$this->markTestSkipped( 'Not testable with an external object cache.' );
}
}
function test_the_basics() {
$key = 'key1';
$value = 'value1';
$value2 = 'value2';
$this->assertFalse( get_site_transient( 'doesnotexist' ) );
$this->assertTrue( set_site_transient( $key, $value ) );
$this->assertEquals( $value, get_site_transient( $key ) );
$this->assertFalse( set_site_transient( $key, $value ) );
$this->assertTrue( set_site_transient( $key, $value2 ) );
$this->assertEquals( $value2, get_site_transient( $key ) );
$this->assertTrue( delete_site_transient( $key ) );
$this->assertFalse( get_site_transient( $key ) );
$this->assertFalse( delete_site_transient( $key ) );
}
function test_serialized_data() {
$key = __FUNCTION__;
$value = array( 'foo' => true, 'bar' => true );
$this->assertTrue( set_site_transient( $key, $value ) );
$this->assertEquals( $value, get_site_transient( $key ) );
$value = (object) $value;
$this->assertTrue( set_site_transient( $key, $value ) );
$this->assertEquals( $value, get_site_transient( $key ) );
$this->assertTrue( delete_site_transient( $key ) );
}
/**
* @ticket 22846
* @group ms-excluded
*/
public function test_set_site_transient_is_not_stored_as_autoload_option() {
$key = 'not_autoloaded';
if ( is_multisite() ) {
$this->markTestSkipped( 'Does not apply when used in multisite.' );
}
set_site_transient( $key, 'Not an autoload option' );
$options = wp_load_alloptions();
$this->assertFalse( isset( $options[ '_site_transient_' . $key ] ) );
}
}