wordpress-develop/tests/phpunit/tests/option/siteTransient.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

62 lines
1.6 KiB
PHP

<?php
/**
* @group option
*/
class Tests_Option_SiteTransient extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
if ( wp_using_ext_object_cache() ) {
$this->markTestSkipped( 'Not testable with an external object cache.' );
}
}
public function test_the_basics() {
$key = 'key1';
$value = 'value1';
$value2 = 'value2';
$this->assertFalse( get_site_transient( 'doesnotexist' ) );
$this->assertTrue( set_site_transient( $key, $value ) );
$this->assertSame( $value, get_site_transient( $key ) );
$this->assertFalse( set_site_transient( $key, $value ) );
$this->assertTrue( set_site_transient( $key, $value2 ) );
$this->assertSame( $value2, get_site_transient( $key ) );
$this->assertTrue( delete_site_transient( $key ) );
$this->assertFalse( get_site_transient( $key ) );
$this->assertFalse( delete_site_transient( $key ) );
}
public function test_serialized_data() {
$key = __FUNCTION__;
$value = array(
'foo' => true,
'bar' => true,
);
$this->assertTrue( set_site_transient( $key, $value ) );
$this->assertSame( $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';
set_site_transient( $key, 'Not an autoload option' );
$options = wp_load_alloptions();
$this->assertArrayNotHasKey( '_site_transient_' . $key, $options );
}
}