wordpress-develop/tests/phpunit/tests/option/siteTransient.php
Sergey Biryukov 164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00

62 lines
1.6 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->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 ) );
}
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->assertFalse( isset( $options[ '_site_transient_' . $key ] ) );
}
}