| 1 | <?php |
| 2 | |
| 3 | |
| 4 | /** |
| 5 | * Test functions against get_weekstartend. |
| 6 | * Tested scenarios: |
| 7 | * 1) No optional parameter is passed |
| 8 | * 2) Optional parameter is passed with the non-default option |
| 9 | * 3) start_of_week option is removed |
| 10 | * 4) Formatted time is provided from date function |
| 11 | * 5) No optional parameter is passed |
| 12 | * @group functions.php |
| 13 | */ |
| 14 | class Tests_Functions_Get_WeekStartEnd extends WP_UnitTestCase { |
| 15 | |
| 16 | // Monday (option_value 1) is the default start of week |
| 17 | function test_get_weekstartend() { |
| 18 | |
| 19 | $expected = array( |
| 20 | 'start' => 1454889600, |
| 21 | 'end' => 1455494399, |
| 22 | ); |
| 23 | |
| 24 | $this->assertEquals( $expected, get_weekstartend( '2016-02-12' ) ); |
| 25 | |
| 26 | } |
| 27 | |
| 28 | //Force the start of week to Sunday (0) |
| 29 | function test_get_weekstartend_start_of_week_set_to_sunday() { |
| 30 | |
| 31 | $expected = array( |
| 32 | 'start' => 1454803200, |
| 33 | 'end' => 1455407999, |
| 34 | ); |
| 35 | |
| 36 | $this->assertEquals( $expected, get_weekstartend( '2016-02-12', 0 ) ); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | //Runs the test with start_of_week option removed |
| 41 | function test_get_weekstartend_bad_option() { |
| 42 | $current_option = get_option( 'start_of_week' ); |
| 43 | delete_option( 'start_of_week' ); |
| 44 | |
| 45 | $expected = array( |
| 46 | 'start' => 1454803200, |
| 47 | 'end' => 1455407999, |
| 48 | ); |
| 49 | |
| 50 | $this->assertEquals( $expected, get_weekstartend( '2016-02-12' ) ); |
| 51 | |
| 52 | |
| 53 | update_option( 'start_of_week', $current_option ); |
| 54 | } |
| 55 | |
| 56 | function test_get_weekstartend_start_of_week_set_strtotime() { |
| 57 | |
| 58 | $expected = array( |
| 59 | 'start' => 1454889600, |
| 60 | 'end' => 1455494399, |
| 61 | ); |
| 62 | |
| 63 | $this->assertEquals( $expected, get_weekstartend( date( 'Y-m-d', strtotime( '2016-02-12' ) ) ) ); |
| 64 | |
| 65 | } |
| 66 | |
| 67 | // start of week is set to Monday by default |
| 68 | function test_get_weekstartend_start_of_week_set_to_monday() { |
| 69 | $expected = array( |
| 70 | 'start' => strtotime( '2016-02-08 00:00:00' ), // monday for week before |
| 71 | 'end' => strtotime( '2016-02-14 23:59:59' ), |
| 72 | ); |
| 73 | |
| 74 | $this->assertEquals( $expected, get_weekstartend( '2016-02-14' ) ); |
| 75 | |
| 76 | } |
| 77 | } |
| 78 | No newline at end of file |