Skip to content

Commit db120e1

Browse files
author
Connor Jennings
committed
Updates to tests
1 parent 52882ba commit db120e1

File tree

2 files changed

+114
-6
lines changed

2 files changed

+114
-6
lines changed

modules/custom-status/custom-status.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,16 +1763,20 @@ public function fix_post_row_actions( $actions, $post ) {
17631763
* @return bool
17641764
*/
17651765
public function is_custom_status_view() {
1766+
17661767
if( $this->is_current_module_settings_view() ) {
17671768
return true;
17681769
}
1770+
17691771
if( ! $this->is_active_view( array( 'post.php', 'edit.php', 'post-new.php', 'page.php', 'edit-pages.php', 'page-new.php' ) ) ) {
17701772
return false;
17711773
}
1774+
17721775
$post_type_obj = get_post_type_object( $this->get_current_post_type() );
17731776
if( $post_type_obj && ! current_user_can( $post_type_obj->cap->edit_posts ) ) {
17741777
return false;
17751778
}
1779+
17761780
return true;
17771781
}
17781782

tests/test-edit-flow-custom-status.php

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,40 @@
33
class WP_Test_Edit_Flow_Custom_Status extends WP_UnitTestCase {
44

55
protected static $admin_user_id;
6-
protected static $EF_Custom_Status;
6+
protected $old_wp_scripts;
77

88
public static function wpSetUpBeforeClass( $factory ) {
9+
global $edit_flow;
10+
911
self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );
1012

11-
self::$EF_Custom_Status = new EF_Custom_Status();
12-
self::$EF_Custom_Status->install();
13-
self::$EF_Custom_Status->init();
13+
$edit_flow->custom_status->install();
14+
$edit_flow->custom_status->init();
1415
}
1516

1617
public static function wpTearDownAfterClass() {
1718
self::delete_user( self::$admin_user_id );
18-
self::$EF_Custom_Status = null;
1919
}
2020

2121
function setUp() {
2222
parent::setUp();
2323

24+
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
25+
remove_action( 'wp_default_scripts', 'wp_default_scripts' );
26+
remove_action( 'wp_default_scripts', 'wp_default_packages' );
27+
$GLOBALS['wp_scripts'] = new WP_Scripts();
28+
$GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' );
29+
2430
global $pagenow;
2531
$pagenow = 'post.php';
2632
}
2733

2834
function tearDown() {
29-
parent::tearDown();
35+
$GLOBALS['wp_scripts'] = $this->old_wp_scripts;
36+
add_action( 'wp_default_scripts', 'wp_default_scripts' );
3037

38+
parent::tearDown();
39+
3140
global $pagenow;
3241
$pagenow = 'index.php';
3342
}
@@ -332,4 +341,99 @@ public function test_fix_get_sample_permalink_should_respect_hierarchy_of_publis
332341
$this->assertSame( home_url() . '/publish-parent-page/%pagename%/', $actual[0] );
333342
$this->assertSame( 'child-page', $actual[1] );
334343
}
344+
345+
/**
346+
* On the custom status settings page, the custom status settings js should be enqueued
347+
*/
348+
public function test_scripts_enqueued_custom_status_settings_screen() {
349+
global $edit_flow, $pagenow, $wp_scripts;
350+
351+
wp_default_scripts( $wp_scripts );
352+
wp_default_packages( $wp_scripts );
353+
354+
$pagenow = 'admin.php';
355+
$_GET['page'] = 'ef-custom-status-settings';
356+
357+
// Custom Status Settings JS has a dependency on `edit-flow-settings-js`
358+
$edit_flow->settings->action_admin_enqueue_scripts();
359+
$edit_flow->custom_status->enqueue_admin_scripts();
360+
361+
$expected = "<script type='text/javascript' src='" . $edit_flow->custom_status->module_url . "lib/custom-status-configure.js?ver=" . EDIT_FLOW_VERSION . "'></script>";
362+
363+
$footer = get_echo( 'wp_print_footer_scripts' );
364+
365+
$this->assertContains( $expected, $footer );
366+
367+
}
368+
369+
/**
370+
* The custom status settings js should not be enqueued on pages other than the
371+
* custom status settings page
372+
*/
373+
public function test_scripts_not_enqueued_custom_status_settings_screen() {
374+
global $edit_flow, $pagenow, $wp_scripts;
375+
376+
wp_default_scripts( $wp_scripts );
377+
wp_default_packages( $wp_scripts );
378+
379+
$pagenow = 'post-new.php';
380+
381+
$edit_flow->settings->action_admin_enqueue_scripts();
382+
$edit_flow->custom_status->enqueue_admin_scripts();
383+
384+
$expected = "<script type='text/javascript' src='" . $edit_flow->custom_status->module_url . "lib/custom-status-configure.js?ver=" . EDIT_FLOW_VERSION . "'></script>";
385+
386+
$footer = get_echo( 'wp_print_footer_scripts' );
387+
388+
$this->assertNotContains( $expected, $footer );
389+
}
390+
391+
/**
392+
* The custom status js should be enqueued on pages like post.php with a valid post type
393+
*/
394+
public function test_scripts_enqueued_custom_status_post() {
395+
global $edit_flow, $pagenow, $wp_scripts;
396+
397+
set_current_screen( 'admin' );
398+
399+
wp_default_scripts( $wp_scripts );
400+
wp_default_packages( $wp_scripts );
401+
402+
$pagenow = 'post-new.php';
403+
$_REQUEST['post_type'] = 'post';
404+
405+
wp_set_current_user( self::$admin_user_id );
406+
407+
$edit_flow->custom_status->enqueue_admin_scripts();
408+
409+
$expected = "<script type='text/javascript' src='" . $edit_flow->custom_status->module_url . "lib/custom-status.js?ver=" . EDIT_FLOW_VERSION . "'></script>";
410+
411+
$footer = get_echo( 'wp_print_footer_scripts' );
412+
413+
$this->assertContains( $expected, $footer );
414+
}
415+
416+
/**
417+
* The custom status js should not be enqueued on pages like admin.php
418+
*/
419+
public function test_scripts_not_enqueued_custom_status_admin() {
420+
global $edit_flow, $pagenow, $wp_scripts;
421+
422+
set_current_screen( 'admin' );
423+
424+
wp_default_scripts( $wp_scripts );
425+
wp_default_packages( $wp_scripts );
426+
427+
$pagenow = 'admin.php';
428+
429+
wp_set_current_user( self::$admin_user_id );
430+
431+
$edit_flow->custom_status->enqueue_admin_scripts();
432+
433+
$expected = "<script type='text/javascript' src='" . $edit_flow->custom_status->module_url . "lib/custom-status.js?ver=" . EDIT_FLOW_VERSION . "'></script>";
434+
435+
$footer = get_echo( 'wp_print_footer_scripts' );
436+
437+
$this->assertNotContains( $expected, $footer );
438+
}
335439
}

0 commit comments

Comments
 (0)