From 8276b63238585e2d5df129cfff73928b3c8c2294 Mon Sep 17 00:00:00 2001 From: Connor Jennings Date: Mon, 2 Dec 2019 14:01:17 -0500 Subject: [PATCH] Use $post argument in check_if_post_state_is_status (exists since 3.6.0). --- modules/custom-status/custom-status.php | 8 ++--- tests/test-edit-flow-custom-status.php | 44 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/modules/custom-status/custom-status.php b/modules/custom-status/custom-status.php index e90340d6f..74a53cbe0 100644 --- a/modules/custom-status/custom-status.php +++ b/modules/custom-status/custom-status.php @@ -749,16 +749,16 @@ function _filter_manage_posts_custom_column( $column_name ) { * * @param array $post_states An array of post display states. */ - function check_if_post_state_is_status($post_states) { + function check_if_post_state_is_status( $post_states, $post ) { - global $post; - $statuses = get_post_status_object(get_post_status($post->ID)); + $statuses = get_post_status_object( get_post_status( $post->ID ) ); foreach ( $post_states as $state ) { if ( $state !== $statuses->label ) { echo ''; } } - return $post_states; + + return $post_states; } /** diff --git a/tests/test-edit-flow-custom-status.php b/tests/test-edit-flow-custom-status.php index e2bf350f8..7294a6ea7 100644 --- a/tests/test-edit-flow-custom-status.php +++ b/tests/test-edit-flow-custom-status.php @@ -4,6 +4,11 @@ class WP_Test_Edit_Flow_Custom_Status extends WP_UnitTestCase { protected static $admin_user_id; protected static $EF_Custom_Status; + + /** + * @var \Walker_Nav_Menu The instance of the walker. + */ + public $walker; public static function wpSetUpBeforeClass( $factory ) { self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); @@ -21,6 +26,10 @@ public static function wpTearDownAfterClass() { function setUp() { parent::setUp(); + /** Walker_Nav_Menu class */ + require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php'; + $this->walker = new Walker_Nav_Menu_Checklist(); + global $pagenow; $pagenow = 'post.php'; } @@ -332,4 +341,39 @@ public function test_fix_get_sample_permalink_should_respect_hierarchy_of_publis $this->assertSame( home_url() . '/publish-parent-page/%pagename%/', $actual[0] ); $this->assertSame( 'child-page', $actual[1] ); } + + /** + * Validate the usage of $post in `check_if_post_state_is_status` hook + */ + public function test_walker_nav_menu_checklist_title() { + $expected = ''; + $post_id = $this->factory->post->create(); + $post_title = get_the_title( $post_id ); + + $item = array( + 'ID' => $post_id, + 'object_id' => $post_id, + 'title' => $post_title, + 'menu_item_parent' => null, + 'object' => null, + 'type' => 'post', + 'url' => '', + 'attr_title' => '', + 'classes' => array(), + 'target' => '_blank', + 'xfn' => '', + 'current' => false, + ); + + $args = array( + 'before' => '', + 'after' => '', + 'link_before' => '', + 'link_after' => '', + ); + + $this->walker->start_el( $expected, (object) $item, 0, (object) $args ); + + $this->assertStringStartsWith( "
  • ", $expected ); + } } \ No newline at end of file