From 43ca4120948fcb508c3911e892d6a45af37292ca Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 2 Sep 2016 03:51:01 +0000 Subject: [PATCH] Toolbar: Add unit tests for edit links. When there is no post ID, there should be no edit link. This adds unit tests for it. Fixes #22247. Props akibjorklund. git-svn-id: https://develop.svn.wordpress.org/trunk@38508 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/adminbar.php | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index a7d86980b4..12a767d9f6 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -339,4 +339,45 @@ class Tests_AdminBar extends WP_UnitTestCase { ), ); } + + /** + * @ticket 22247 + */ + public function test_admin_bar_has_edit_link_for_existing_posts() { + wp_set_current_user( self::$editor_id ); + + $post = array( + 'post_author' => self::$editor_id, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + ); + $id = wp_insert_post( $post ); + + // Set queried object to the newly created post. + global $wp_the_query; + $wp_the_query->queried_object = (object) array( 'ID' => $id, 'post_type' => 'post' ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + + $node_edit = $wp_admin_bar->get_node( 'edit' ); + $this->assertNotNull( $node_edit ); + } + + /** + * @ticket 22247 + */ + public function test_admin_bar_has_no_edit_link_for_non_existing_posts() { + wp_set_current_user( self::$editor_id ); + + // Set queried object to a non-existing post. + global $wp_the_query; + $wp_the_query->queried_object = (object) array( 'ID' => 0, 'post_type' => 'post' ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + + $node_edit = $wp_admin_bar->get_node( 'edit' ); + $this->assertNull( $node_edit ); + } + }