Make WordPress Core


Ignore:
Timestamp:
02/23/2015 06:47:01 PM (10 years ago)
Author:
SergeyBiryukov
Message:

Add unit tests for get_page_template_slug().

props tyxla.
fixes #31389.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/template.php

    r31338 r31522  
    198198        $this->assertContains( 'value="' . $p . '"', $found );
    199199    }
     200
     201    /**
     202     * @ticket 31389
     203     */
     204    public function test_get_page_template_slug_by_id() {
     205        $page_id = $this->factory->post->create( array(
     206            'post_type' => 'page',
     207        ) );
     208
     209        $this->assertEquals( '', get_page_template_slug( $page_id ) );
     210
     211        update_post_meta( $page_id, '_wp_page_template', 'default' );
     212        $this->assertEquals( '', get_page_template_slug( $page_id ) );
     213
     214        update_post_meta( $page_id, '_wp_page_template', 'example.php' );
     215        $this->assertEquals( 'example.php', get_page_template_slug( $page_id ) );
     216    }
     217
     218    /**
     219     * @ticket 31389
     220     */
     221    public function test_get_page_template_slug_from_loop() {
     222        $page_id = $this->factory->post->create( array(
     223            'post_type' => 'page',
     224        ) );
     225
     226        update_post_meta( $page_id, '_wp_page_template', 'example.php' );
     227        $this->go_to( get_permalink( $page_id ) );
     228
     229        $this->assertEquals( 'example.php', get_page_template_slug() );
     230    }
     231
     232    /**
     233     * @ticket 31389
     234     */
     235    public function test_get_page_template_slug_non_page() {
     236        $post_id = $this->factory->post->create( array(
     237            'post_type' => 'post',
     238        ) );
     239
     240        $this->assertFalse( get_page_template_slug( $post_id ) );
     241
     242        $this->go_to( get_permalink( $post_id ) );
     243        $this->assertFalse( get_page_template_slug() );
     244    }
    200245}
Note: See TracChangeset for help on using the changeset viewer.