WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2016 03:51:01 AM (3 years ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/adminbar.php

    r38398 r38508  
    340340        );
    341341    }
     342
     343    /**
     344     * @ticket 22247
     345     */
     346    public function test_admin_bar_has_edit_link_for_existing_posts() {
     347        wp_set_current_user( self::$editor_id );
     348
     349        $post = array(
     350            'post_author' => self::$editor_id,
     351            'post_status' => 'publish',
     352            'post_content' => rand_str(),
     353            'post_title' => rand_str(),
     354        );
     355        $id = wp_insert_post( $post );
     356
     357        // Set queried object to the newly created post.
     358        global $wp_the_query;
     359        $wp_the_query->queried_object = (object) array( 'ID' => $id, 'post_type' => 'post' );
     360
     361        $wp_admin_bar = $this->get_standard_admin_bar();
     362
     363        $node_edit = $wp_admin_bar->get_node( 'edit' );
     364        $this->assertNotNull( $node_edit );
     365    }
     366
     367    /**
     368     * @ticket 22247
     369     */
     370    public function test_admin_bar_has_no_edit_link_for_non_existing_posts() {
     371        wp_set_current_user( self::$editor_id );
     372
     373        // Set queried object to a non-existing post.
     374        global $wp_the_query;
     375        $wp_the_query->queried_object = (object) array( 'ID' => 0, 'post_type' => 'post' );
     376
     377        $wp_admin_bar = $this->get_standard_admin_bar();
     378
     379        $node_edit = $wp_admin_bar->get_node( 'edit' );
     380        $this->assertNull( $node_edit );
     381    }
     382
    342383}
Note: See TracChangeset for help on using the changeset viewer.