-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scope module assets for calendar #564
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,100 @@ | ||
<?php | ||
|
||
class WP_Test_Edit_Flow_Calendar extends WP_UnitTestCase { | ||
|
||
protected static $admin_user_id; | ||
protected $old_wp_scripts; | ||
|
||
public static function wpSetUpBeforeClass( $factory ) { | ||
global $edit_flow; | ||
|
||
self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); | ||
|
||
/** | ||
* There's a capability's check in EF_Calendar `init` that will prevent embedding of assets | ||
* and setting of the `create_post_cap` property, so we set that capability here | ||
* | ||
* @see https://github.com/Automattic/Edit-Flow/blob/b4430c5d652b1c87736c3980ab8cf032bf49b6ad/modules/calendar/calendar.php#L84 | ||
* @see https://github.com/Automattic/Edit-Flow/blob/b4430c5d652b1c87736c3980ab8cf032bf49b6ad/modules/calendar/calendar.php#L87 | ||
*/ | ||
$edit_flow->calendar->create_post_cap = 'edit_posts'; | ||
|
||
$edit_flow->calendar->install(); | ||
$edit_flow->calendar->init(); | ||
} | ||
|
||
public static function wpTearDownAfterClass() { | ||
self::delete_user( self::$admin_user_id ); | ||
} | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; | ||
remove_action( 'wp_default_scripts', 'wp_default_scripts' ); | ||
remove_action( 'wp_default_scripts', 'wp_default_packages' ); | ||
$GLOBALS['wp_scripts'] = new WP_Scripts(); | ||
$GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); | ||
|
||
global $pagenow; | ||
$pagenow = 'post.php'; | ||
} | ||
|
||
function tearDown() { | ||
$GLOBALS['wp_scripts'] = $this->old_wp_scripts; | ||
add_action( 'wp_default_scripts', 'wp_default_scripts' ); | ||
|
||
global $pagenow; | ||
$pagenow = 'index.php'; | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* The calendar js should be enqueued on pages like post.php with a valid post type | ||
*/ | ||
public function test_scripts_enqueued_calendar_admin() { | ||
global $edit_flow, $pagenow, $wp_scripts; | ||
|
||
set_current_screen( 'admin' ); | ||
|
||
wp_default_scripts( $wp_scripts ); | ||
wp_default_packages( $wp_scripts ); | ||
|
||
$pagenow = 'index.php'; | ||
$_GET['page'] = 'calendar'; | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
$edit_flow->calendar->enqueue_admin_scripts(); | ||
|
||
$expected = "<script type='text/javascript' src='" . $edit_flow->calendar->module_url . 'lib/calendar.js?ver=' . EDIT_FLOW_VERSION . "'></script>"; | ||
|
||
$footer = get_echo( 'wp_print_footer_scripts' ); | ||
|
||
$this->assertContains( $expected, $footer ); | ||
} | ||
/** | ||
* The custom status js should not be enqueued on pages like admin.php | ||
*/ | ||
public function test_scripts_not_enqueued_calendar_admin() { | ||
global $edit_flow, $pagenow, $wp_scripts; | ||
|
||
set_current_screen( 'admin' ); | ||
|
||
wp_default_scripts( $wp_scripts ); | ||
wp_default_packages( $wp_scripts ); | ||
|
||
$pagenow = 'admin.php'; | ||
|
||
wp_set_current_user( self::$admin_user_id ); | ||
|
||
$edit_flow->calendar->enqueue_admin_scripts(); | ||
|
||
$expected = "<script type='text/javascript' src='" . $edit_flow->calendar->module_url . 'lib/calendar.js?ver=' . EDIT_FLOW_VERSION . "'></script>"; | ||
|
||
$footer = get_echo( 'wp_print_footer_scripts' ); | ||
|
||
$this->assertNotContains( $expected, $footer ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was making the PHPUnit tests around enqueuing noisy, so moved it to use
wp_add_inline_script