siteTransient.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @group option
  4. */
  5. class Tests_Option_SiteTransient extends WP_UnitTestCase {
  6. function test_the_basics() {
  7. $key = rand_str();
  8. $value = rand_str();
  9. $value2 = rand_str();
  10. $this->assertFalse( get_site_transient( 'doesnotexist' ) );
  11. $this->assertTrue( set_site_transient( $key, $value ) );
  12. $this->assertEquals( $value, get_site_transient( $key ) );
  13. $this->assertFalse( set_site_transient( $key, $value ) );
  14. $this->assertTrue( set_site_transient( $key, $value2 ) );
  15. $this->assertEquals( $value2, get_site_transient( $key ) );
  16. $this->assertTrue( delete_site_transient( $key ) );
  17. $this->assertFalse( get_site_transient( $key ) );
  18. $this->assertFalse( delete_site_transient( $key ) );
  19. }
  20. function test_serialized_data() {
  21. $key = rand_str();
  22. $value = array( 'foo' => true, 'bar' => true );
  23. $this->assertTrue( set_site_transient( $key, $value ) );
  24. $this->assertEquals( $value, get_site_transient( $key ) );
  25. $value = (object) $value;
  26. $this->assertTrue( set_site_transient( $key, $value ) );
  27. $this->assertEquals( $value, get_site_transient( $key ) );
  28. $this->assertTrue( delete_site_transient( $key ) );
  29. }
  30. }