Make WordPress Core


Ignore:
Timestamp:
09/26/2017 08:39:57 AM (8 years ago)
Author:
swissspidy
Message:

Embeds: Improve performance when embedding a post on Multisite.

After [37798], this fixes embeds coming from a different site in the network.

Props imath.
Fixes #40673. See #36767.

File:
1 edited

Legend:

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

    r39919 r41600  
    7070        $this->assertFalse( $actual );
    7171    }
     72
     73    /**
     74     * @ticket 40673
     75     * @group multisite
     76     * @group ms-required
     77     */
     78    public function test_wp_filter_pre_oembed_result_multisite_root_root() {
     79        $post_id   = self::factory()->post->create();
     80        $permalink = get_permalink( $post_id );
     81
     82        add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     83        $actual = $this->oembed->get_html( $permalink );
     84        remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     85
     86        $this->assertNotNull( $this->pre_oembed_result_filtered );
     87        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     88    }
     89
     90    /**
     91     * @ticket 40673
     92     * @group multisite
     93     * @group ms-required
     94     */
     95    public function test_wp_filter_pre_oembed_result_multisite_sub_samesub() {
     96        $user_id = self::factory()->user->create();
     97
     98        $blog_id = self::factory()->blog->create( array(
     99            'user_id' => $user_id,
     100        ) );
     101
     102        switch_to_blog( $blog_id );
     103
     104        $post_id   = self::factory()->post->create();
     105        $permalink = get_permalink( $post_id );
     106
     107        add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     108        $actual = $this->oembed->get_html( $permalink );
     109        remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     110
     111        restore_current_blog();
     112
     113        $this->assertNotNull( $this->pre_oembed_result_filtered );
     114        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     115    }
     116
     117    /**
     118     * @ticket 40673
     119     * @group multisite
     120     * @group ms-required
     121     */
     122    public function test_wp_filter_pre_oembed_result_multisite_sub_othersub() {
     123        $user_id = self::factory()->user->create();
     124
     125        $blog_id = self::factory()->blog->create( array(
     126            'user_id' => $user_id,
     127        ) );
     128
     129        switch_to_blog( $blog_id );
     130
     131        $post_id   = self::factory()->post->create();
     132        $permalink = get_permalink( $post_id );
     133
     134        $blog_id = self::factory()->blog->create( array(
     135            'user_id' => $user_id,
     136        ) );
     137
     138        switch_to_blog( $blog_id );
     139
     140        add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     141        $actual = $this->oembed->get_html( $permalink );
     142        remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     143
     144        restore_current_blog();
     145
     146        $this->assertNotNull( $this->pre_oembed_result_filtered );
     147        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     148    }
     149
     150    /**
     151     * @ticket 40673
     152     * @group multisite
     153     * @group ms-required
     154     */
     155    public function test_wp_filter_pre_oembed_result_multisite_sub_main() {
     156        $post_id   = self::factory()->post->create();
     157        $permalink = get_permalink( $post_id );
     158        $user_id   = self::factory()->user->create();
     159        $blog_id   = self::factory()->blog->create( array(
     160            'user_id' => $user_id,
     161        ) );
     162
     163        switch_to_blog( $blog_id );
     164
     165        add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     166        $actual = $this->oembed->get_html( $permalink );
     167        remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     168
     169        restore_current_blog();
     170
     171        $this->assertNotNull( $this->pre_oembed_result_filtered );
     172        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     173    }
    72174}
Note: See TracChangeset for help on using the changeset viewer.