| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Test wp_filter_object_list(), wp_list_filter(), wp_list_pluck(). |
| 5 | * |
| 6 | * @group functions.php |
| 7 | */ |
| 8 | /** |
| 9 | * Convert given date string into a different format. |
| 10 | * |
| 11 | * $format should be either a PHP date format string, e.g. 'U' for a Unix |
| 12 | * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. |
| 13 | * |
| 14 | * If $translate is true then the given date and format string will |
| 15 | * be passed to date_i18n() for translation. |
| 16 | * |
| 17 | * @since 0.71 |
| 18 | * |
| 19 | * @param string $format Format of the date to return. |
| 20 | * @param string $date Date string to convert. |
| 21 | * @param bool $translate Whether the return date should be translated. Default true. |
| 22 | * |
| 23 | * @return string|int Formatted date string, or Unix timestamp. |
| 24 | */ |
| 25 | //function mysql2date( $format, $date, $translate = true ) { |
| 26 | // if ( empty( $date ) ) |
| 27 | // return false; |
| 28 | // |
| 29 | // if ( 'G' == $format ) |
| 30 | // return strtotime( $date . ' +0000' ); |
| 31 | // |
| 32 | // $i = strtotime( $date ); |
| 33 | // |
| 34 | // if ( 'U' == $format ) |
| 35 | // return $i; |
| 36 | // |
| 37 | // if ( $translate ) |
| 38 | // return date_i18n( $format, $i ); |
| 39 | // else |
| 40 | // return date( $format, $i ); |
| 41 | //} |
| 42 | |
| 43 | |
| 44 | class Tests_Functions_mysql2date extends WP_UnitTestCase { |
| 45 | |
| 46 | function test_mysql2date_false() { |
| 47 | $this->assertFalse( mysql2date( '', '' ) ); |
| 48 | $this->assertFalse( mysql2date( '', '2012-12-30' ) ); |
| 49 | $this->assertFalse( mysql2date( 'Y-m-d', '' ) ); |
| 50 | |
| 51 | // must be valid date |
| 52 | $this->assertFalse( mysql2date( 'Y-m-d', '42351234523541345143534534535314' ) ); |
| 53 | $this->assertFalse( mysql2date( 'Y-m-d', '1' ) ); |
| 54 | $this->assertFalse( mysql2date( 'Y-m-d', '1355270400' ) ); // unix date does work |
| 55 | |
| 56 | $this->assertFalse( mysql2date( 'Y-m-d', 'i am not a date' ) ); |
| 57 | |
| 58 | |
| 59 | } |
| 60 | |
| 61 | |
| 62 | function test_mysql2date() { |
| 63 | $formated_now = date( 'Y-m-d' ); |
| 64 | |
| 65 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30' ) ); |
| 66 | $this->assertEquals( '12-12-30', mysql2date( 'y-m-d', '2012-12-30' ) ); |
| 67 | $this->assertEquals( '1356825600', mysql2date( 'G', '2012-12-30' ) ); |
| 68 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30', true ) ); |
| 69 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', '2012-12-30', false ) ); |
| 70 | |
| 71 | $this->assertEquals( '2012-12-30', mysql2date( 'Y-m-d', 'December 30, 2012, 12:00 am' ) ); |
| 72 | |
| 73 | |
| 74 | $this->assertEquals( '1356825600', mysql2date( 'U', '2012-12-30' ) ); |
| 75 | |
| 76 | $this->assertEquals( $formated_now, mysql2date( 'Y-m-d', 'today' ) ); |
| 77 | $this->assertNotEquals( $formated_now, mysql2date( 'Y-m-d', 'tomorrow' ) ); |
| 78 | |
| 79 | |
| 80 | $this->assertEquals( 'December 30, 2012, 12:00 am', mysql2date( 'F j, Y, g:i a', '2012-12-30' ) ); |
| 81 | // no change on the phpunit as testing in english |
| 82 | $this->assertEquals( 'December 30, 2012, 12:00 am', mysql2date( 'F j, Y, g:i a', '2012-12-30' ), true ); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | } |
| 87 | No newline at end of file |