-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support i18n in story budget date picker
- Loading branch information
Showing
3 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
class WP_Test_Edit_Flow_Story_Budget extends WP_UnitTestCase { | ||
|
||
protected static $admin_user_id; | ||
|
||
public static function wpSetUpBeforeClass( $factory ) { | ||
self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); | ||
} | ||
|
||
public static function wpTearDownAfterClass() { | ||
self::delete_user( self::$admin_user_id ); | ||
} | ||
|
||
/** | ||
* Test that the story budget date filter handles valid date | ||
*/ | ||
function test_story_budget_set_start_date_filter() { | ||
global $edit_flow; | ||
|
||
$user = get_user_by( 'id', self::$admin_user_id ); | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
// Users filters need to be set (they're set by default) | ||
$edit_flow->story_budget->update_user_filters(); | ||
|
||
$new_filters['start_date'] = '2019-12-01'; | ||
|
||
$users_filters = $edit_flow->story_budget->update_user_filters_from_form_date_range_change( $user, $new_filters ); | ||
|
||
$this->assertEquals( '2019-12-01', $users_filters['start_date'] ); | ||
} | ||
|
||
/** | ||
* Test that the story budget date filter handles invalid date | ||
*/ | ||
function test_story_budget_set_start_date_filter_invalid() { | ||
global $edit_flow; | ||
|
||
$user = get_user_by( 'id', self::$admin_user_id ); | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
// Users filters need to be set (they're set by default) | ||
$edit_flow->story_budget->update_user_filters(); | ||
|
||
$new_filters['start_date'] = 'not a date'; | ||
|
||
$users_filters = $edit_flow->story_budget->update_user_filters_from_form_date_range_change( $user, $new_filters ); | ||
|
||
$this->assertEquals( date( 'Y-m-d' ), $users_filters['start_date'] ); | ||
} | ||
|
||
/** | ||
* Test that the story budget number of days filter handles valid number of days | ||
*/ | ||
function test_story_budget_set_number_days_filter() { | ||
global $edit_flow; | ||
|
||
$user = get_user_by( 'id', self::$admin_user_id ); | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
// Users filters need to be set (they're set by default) | ||
$edit_flow->story_budget->update_user_filters(); | ||
|
||
$new_filters['number_days'] = 10; | ||
|
||
$users_filters = $edit_flow->story_budget->update_user_filters_from_form_date_range_change( $user, $new_filters ); | ||
|
||
$this->assertEquals( 10, $users_filters['number_days'] ); | ||
} | ||
|
||
/** | ||
* Test that the story budget number of days filter handles invalid number of days | ||
*/ | ||
function test_story_budget_set_number_days_filter_invalid() { | ||
global $edit_flow; | ||
|
||
$user = get_user_by( 'id', self::$admin_user_id ); | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
// Users filters need to be set (they're set by default) | ||
$edit_flow->story_budget->update_user_filters(); | ||
|
||
$new_filters['number_days'] = 'not days'; | ||
|
||
$users_filters = $edit_flow->story_budget->update_user_filters_from_form_date_range_change( $user, $new_filters ); | ||
|
||
$this->assertEquals( 1, $users_filters['number_days'] ); | ||
} | ||
|
||
/** | ||
* Test that the story budget handles both valid date and number of days filters | ||
*/ | ||
function test_story_budget_set_date_and_number_days_filters() { | ||
global $edit_flow; | ||
|
||
$user = get_user_by( 'id', self::$admin_user_id ); | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
// Users filters need to be set (they're set by default) | ||
$edit_flow->story_budget->update_user_filters(); | ||
|
||
$new_filters['start_date'] = '2019-12-01'; | ||
$new_filters['number_days'] = 10; | ||
|
||
$users_filters = $edit_flow->story_budget->update_user_filters_from_form_date_range_change( $user, $new_filters ); | ||
|
||
$this->assertEquals( 10, $users_filters['number_days'] ); | ||
$this->assertEquals( '2019-12-01', $users_filters['start_date'] ); | ||
} | ||
} |