[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/tests/tests/format/ -> timedates.php (source)

   1  <?php
   2  
   3  /**
   4   * Formatting functions for time & dates
   5   *
   6   * @group formatting
   7   * @group timedate
   8   * @since 0.1
   9   */
  10  class Format_Test_Dates extends PHPUnit\Framework\TestCase {
  11  
  12      protected function tearDown(): void {
  13          yourls_remove_all_filters( 'get_time_offset' );
  14      }
  15  
  16      /**
  17       * Test yourls_get_timestamp returns an int
  18       */
  19      function test_get_time_offset() {
  20          $this->assertIsInt( yourls_get_time_offset() );
  21      }
  22  
  23      /**
  24       * Test yourls_get_datetime_format returns a string
  25       */
  26      function test_get_datetime_format() {
  27          $this->assertIsString( yourls_get_datetime_format('M d, Y H:i') );
  28          $this->assertIsString( yourls_get_datetime_format( 10 ) );
  29          $this->assertIsString( yourls_get_datetime_format(false) );
  30      }
  31  
  32      /**
  33       * Test yourls_get_date_format returns a string
  34       */
  35      function test_get_date_format() {
  36          $this->assertIsString( yourls_get_date_format('M d, Y') );
  37          $this->assertIsString( yourls_get_date_format( 10 ) );
  38          $this->assertIsString( yourls_get_date_format(false) );
  39      }
  40  
  41      /**
  42       * Test yourls_get_time_format returns a string
  43       */
  44      function test_get_time_format() {
  45          $this->assertIsString( yourls_get_time_format('H:i') );
  46          $this->assertIsString( yourls_get_time_format( 10 ) );
  47          $this->assertIsString( yourls_get_time_format(false) );
  48      }
  49  
  50      /**
  51       * Test yourls_get_timestamp returns unmodified timestamp if no offset
  52       */
  53      function test_get_time_offset_zero() {
  54          $now = time();
  55  
  56          yourls_add_filter('get_time_offset', 'yourls_return_zero' );
  57          $this->assertEquals( $now, yourls_get_timestamp( $now ) );
  58      }
  59  
  60      /**
  61       * Test yourls_get_timestamp returns a timestamp with offset
  62       */
  63      function test_get_time_offset_non_zero() {
  64          $now = time();
  65  
  66          $offset = mt_rand(-12,12);
  67  
  68          yourls_add_filter('get_time_offset', function() use($offset) {return $offset;} );
  69          $this->assertEquals( $now + ($offset * 3600), yourls_get_timestamp( $now ) );
  70      }
  71  
  72  }


Generated: Wed Sep 28 05:10:02 2022 Cross-referenced by PHPXref 0.7.1