WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/15/2016 07:55:19 AM (4 years ago)
Author:
swissspidy
Message:

Embeds: Allow embedding static front pages and pages having a child page with an embed slug.

This makes embed a special slug that can't be used for new pages/posts. When https://example.com/foo/embed/ is an existing page, embeds fall back to https://example.com/foo/?embed=true.
Adds unit tests.

Fixes #34971.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/oembed/controller.php

    r35654 r36307  
    170170    }
    171171
    172     function test_request_xml() {
    173         $user = self::factory()->user->create_and_get( array(
    174             'display_name' => 'John Doe',
    175         ) );
     172    /**
     173     * @ticket 34971
     174     */
     175    function test_request_static_front_page() {
    176176        $post = self::factory()->post->create_and_get( array(
    177             'post_author' => $user->ID,
    178             'post_title'  => 'Hello World',
    179         ) );
    180 
    181         $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
    182         $request->set_param( 'url', get_permalink( $post->ID ) );
    183         $request->set_param( 'format', 'xml' );
     177            'post_title' => 'Front page',
     178            'post_type'  => 'page',
     179        ) );
     180
     181        update_option( 'show_on_front', 'page' );
     182        update_option( 'page_on_front', $post->ID );
     183
     184        $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
     185        $request->set_param( 'url', home_url() );
    184186        $request->set_param( 'maxwidth', 400 );
    185187
     
    202204        $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] );
    203205        $this->assertEquals( get_home_url(), $data['provider_url'] );
     206        $this->assertEquals( get_bloginfo( 'name' ), $data['author_name'] );
     207        $this->assertEquals( get_home_url(), $data['author_url'] );
     208        $this->assertEquals( $post->post_title, $data['title'] );
     209        $this->assertEquals( 'rich', $data['type'] );
     210        $this->assertTrue( $data['width'] <= $request['maxwidth'] );
     211
     212        update_option( 'show_on_front', 'posts' );
     213    }
     214
     215    function test_request_xml() {
     216        $user = self::factory()->user->create_and_get( array(
     217            'display_name' => 'John Doe',
     218        ) );
     219        $post = self::factory()->post->create_and_get( array(
     220            'post_author' => $user->ID,
     221            'post_title'  => 'Hello World',
     222        ) );
     223
     224        $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
     225        $request->set_param( 'url', get_permalink( $post->ID ) );
     226        $request->set_param( 'format', 'xml' );
     227        $request->set_param( 'maxwidth', 400 );
     228
     229        $response = $this->server->dispatch( $request );
     230        $data     = $response->get_data();
     231
     232        $this->assertInternalType( 'array', $data );
     233        $this->assertNotEmpty( $data );
     234
     235        $this->assertArrayHasKey( 'version', $data );
     236        $this->assertArrayHasKey( 'provider_name', $data );
     237        $this->assertArrayHasKey( 'provider_url', $data );
     238        $this->assertArrayHasKey( 'author_name', $data );
     239        $this->assertArrayHasKey( 'author_url', $data );
     240        $this->assertArrayHasKey( 'title', $data );
     241        $this->assertArrayHasKey( 'type', $data );
     242        $this->assertArrayHasKey( 'width', $data );
     243
     244        $this->assertEquals( '1.0', $data['version'] );
     245        $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] );
     246        $this->assertEquals( get_home_url(), $data['provider_url'] );
    204247        $this->assertEquals( $user->display_name, $data['author_name'] );
    205248        $this->assertEquals( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] );
Note: See TracChangeset for help on using the changeset viewer.