| | 1 | <?php |
| | 2 | /** |
| | 3 | * @group functions.php |
| | 4 | * @group current_time |
| | 5 | */ |
| | 6 | |
| | 7 | /** |
| | 8 | * |
| | 9 | * Test for current_time() function in the /includes/functions.php file |
| | 10 | * |
| | 11 | */ |
| | 12 | class Tests_Functions_current_time extends WP_UnitTestCase { |
| | 13 | |
| | 14 | function test_current_time_null_parms() { |
| | 15 | $this->assertEquals( '', current_time( null ), 'Null passed' ); |
| | 16 | } |
| | 17 | |
| | 18 | function test_current_time_pass_year() { |
| | 19 | $this->assertEquals( date( 'Y-m-d' ), current_time( 'Y-m-d' ), 'Y-m-d passed' ); |
| | 20 | } |
| | 21 | |
| | 22 | function test_current_time_pass_full_format() { |
| | 23 | $this->assertEquals( date( 'F j, Y, g:i a' ), current_time( 'F j, Y, g:i a' ), 'F j, Y, g:i a passed' ); |
| | 24 | } |
| | 25 | |
| | 26 | function test_current_time_pass_year_gmt() { |
| | 27 | $this->assertEquals( date( 'Y-m-d' ), current_time( 'Y-m-d', true ), 'Y-m-d, true passed' ); |
| | 28 | } |
| | 29 | |
| | 30 | function test_current_time_pass_year_1() { |
| | 31 | $this->assertEquals( date( 'Y-m-d' ), current_time( 'Y-m-d', 1 ), 'Y-m-d, true passed' ); |
| | 32 | } |
| | 33 | |
| | 34 | function test_current_time_pass_year_not_gmt() { |
| | 35 | $this->assertEquals( date( 'Y-m-d' ), current_time( 'Y-m-d', false ), 'Y-m-d, false passed' ); |
| | 36 | } |
| | 37 | |
| | 38 | function test_current_time_pass_year_not_gmt_offset() { |
| | 39 | update_option( 'gmt_offset', 6 ); |
| | 40 | $this->assertEquals( date( 'F j, Y, g:i a', time() + ( 6 * HOUR_IN_SECONDS ) ), current_time( 'F j, Y, g:i a', false ), 'Y-m-d, false passed' ); |
| | 41 | } |
| | 42 | |
| | 43 | function test_current_time_pass_timestamp_not_gmt_offset() { |
| | 44 | update_option( 'gmt_offset', 6 ); |
| | 45 | $this->assertEquals( time() + ( 6 * HOUR_IN_SECONDS ), current_time( 'timestamp', false ), 'timestamp, false passed' ); |
| | 46 | } |
| | 47 | |
| | 48 | function test_current_time_pass_timestamp_gmt_offset() { |
| | 49 | update_option( 'gmt_offset', 6 ); |
| | 50 | $this->assertEquals( time(), current_time( 'timestamp', true ), 'timestamp, true passed' ); |
| | 51 | } |
| | 52 | |
| | 53 | function test_current_time_pass_timestamp_not_gmt() { |
| | 54 | update_option( 'gmt_offset', 6 ); |
| | 55 | $this->assertEquals( time() + ( 6 * HOUR_IN_SECONDS ), current_time( 'timestamp', false ), 'timestamp, false passed' ); |
| | 56 | } |
| | 57 | |
| | 58 | function test_current_time_pass_timestamp_gmt() { |
| | 59 | update_option( 'gmt_offset', 6 ); |
| | 60 | $this->assertEquals( time(), current_time( 'timestamp', true ), 'timestamp, true passed' ); |
| | 61 | } |
| | 62 | |
| | 63 | function test_current_time_pass_mysql_not_gmt_offset() { |
| | 64 | update_option( 'gmt_offset', 6 ); |
| | 65 | $this->assertEquals( gmdate( 'Y-m-d H:i:s', ( time() + ( 6 * HOUR_IN_SECONDS ) ) ), current_time( 'mysql', false ), 'mysql, false passed' ); |
| | 66 | } |
| | 67 | |
| | 68 | function test_current_time_pass_mysql_gmt_offset() { |
| | 69 | update_option( 'gmt_offset', 6 ); |
| | 70 | $this->assertEquals( gmdate( 'Y-m-d H:i:s', ( time() ) ), current_time( 'mysql', true ), 'mysql, true passed' ); |
| | 71 | } |
| | 72 | |
| | 73 | function test_current_time_pass_mysql_not_gmt() { |
| | 74 | update_option( 'gmt_offset', 6 ); |
| | 75 | $this->assertEquals( gmdate( 'Y-m-d H:i:s', ( time() + ( 6 * HOUR_IN_SECONDS ) ) ), current_time( 'mysql', false ), 'mysql, false passed' ); |
| | 76 | } |
| | 77 | |
| | 78 | function test_current_time_pass_mysql_gmt() { |
| | 79 | update_option( 'gmt_offset', 6 ); |
| | 80 | $this->assertEquals( gmdate( 'Y-m-d H:i:s' ), current_time( 'mysql', true ), 'mysql, true passed' ); |
| | 81 | } |
| | 82 | } |