| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Test for mysql2date() |
| 5 | * |
| 6 | * @group functions.php |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | |
| 11 | class Tests_Functions_mysql2date extends WP_UnitTestCase { |
| 12 | |
| 13 | /** |
| 14 | * @ticket 28992 |
| 15 | */ |
| 16 | function test_mysql2date_false() { |
| 17 | $this->assertFalse( mysql2date( '', '' ) ); |
| 18 | $this->assertFalse( mysql2date( '', '2012-12-30' ) ); |
| 19 | $this->assertFalse( mysql2date( 'Y-m-d', '' ) ); |
| 20 | |
| 21 | // must be valid date |
| 22 | $this->assertFalse( mysql2date( 'Y-m-d', '42351234523541345143534534535314' ) ); |
| 23 | $this->assertFalse( mysql2date( 'Y-m-d', '1' ) ); |
| 24 | $this->assertFalse( mysql2date( 'Y-m-d', '1355270400' ) ); // unix date does work |
| 25 | |
| 26 | $this->assertFalse( mysql2date( 'Y-m-d', 'i am not a date' ) ); |
| 27 | |
| 28 | |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * @ticket 28992 |
| 34 | */ |
| 35 | function test_mysql2date() { |
| 36 | $formated_now = date( 'Y-m-d' ); |
| 37 | |
| 38 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30' ) ); |
| 39 | $this->assertEquals( '12-12-30', mysql2date( 'y-m-d', '2012-12-30' ) ); |
| 40 | $this->assertEquals( '1356825600', mysql2date( 'G', '2012-12-30' ) ); |
| 41 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30', true ) ); |
| 42 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30', false ) ); |
| 43 | |
| 44 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', 'December 30, 2012, 12:00 am' ) ); |
| 45 | |
| 46 | |
| 47 | $this->assertEquals( '1356825600', mysql2date( 'U', '2012-12-30' ) ); |
| 48 | |
| 49 | $this->assertEquals( $formated_now, mysql2date( 'Y-m-d', 'today' ) ); |
| 50 | $this->assertNotEquals( $formated_now, mysql2date( 'Y-m-d', 'tomorrow' ) ); |
| 51 | |
| 52 | |
| 53 | $this->assertEquals( 'December 30, 2012, 12:00 am', mysql2date( 'F j, Y, g:i a', '2012-12-30' ) ); |
| 54 | // no change on the phpunit as testing in english |
| 55 | $this->assertEquals( 'December 30, 2012, 12:00 am', mysql2date( 'F j, Y, g:i a', '2012-12-30' ), true ); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | No newline at end of file |