mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Embeds: Add oEmbed provider support.
For the past 6 years, WordPress has operated as an oEmbed consumer, allowing users to easily embed content from other sites. By adding oEmbed provider support, this allows any oEmbed consumer to embed posts from WordPress sites. In addition to creating an oEmbed provider, WordPress' oEmbed consumer code has been enhanced to work with any site that provides oEmbed data (as long as it matches some strict security rules), and provides a preview from within the post editor. For security, embeds appear within a sandboxed iframe - the iframe content is a template that can be styled or replaced entirely by the theme on the provider site. Props swissspidy, pento, melchoyce, netweb, pfefferle, johnbillion, extendwings, davidbinda, danielbachhuber, SergeyBiryukov, afercia Fixes #32522. git-svn-id: https://develop.svn.wordpress.org/trunk@34903 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
66
tests/phpunit/tests/oembed/headers.php
Normal file
66
tests/phpunit/tests/oembed/headers.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @group oembed
|
||||
* @group oembed-headers
|
||||
*/
|
||||
class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase {
|
||||
function test_request_json_response_headers() {
|
||||
if ( ! function_exists( 'xdebug_get_headers' ) ) {
|
||||
$this->markTestSkipped( 'xdebug is required for this test' );
|
||||
}
|
||||
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Hello World',
|
||||
) );
|
||||
|
||||
$request = array(
|
||||
'url' => get_permalink( $post->ID ),
|
||||
'format' => 'json',
|
||||
'maxwidth' => 600,
|
||||
'callback' => '',
|
||||
);
|
||||
|
||||
$legacy_controller = new WP_oEmbed_Controller();
|
||||
$legacy_controller->dispatch( $request );
|
||||
|
||||
$headers = xdebug_get_headers();
|
||||
|
||||
$this->assertTrue( in_array( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ), $headers ) );
|
||||
$this->assertTrue( in_array( 'X-Content-Type-Options: nosniff', $headers ) );
|
||||
|
||||
$request['callback'] = 'foobar';
|
||||
|
||||
$legacy_controller->dispatch( $request );
|
||||
|
||||
$headers = xdebug_get_headers();
|
||||
|
||||
$this->assertTrue( in_array( 'Content-Type: application/javascript; charset=' . get_option( 'blog_charset' ), $headers ) );
|
||||
$this->assertTrue( in_array( 'X-Content-Type-Options: nosniff', $headers ) );
|
||||
}
|
||||
|
||||
function test_request_xml_response_headers() {
|
||||
if ( ! function_exists( 'xdebug_get_headers' ) ) {
|
||||
$this->markTestSkipped( 'xdebug is required for this test' );
|
||||
}
|
||||
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Hello World',
|
||||
) );
|
||||
|
||||
$request = array(
|
||||
'url' => get_permalink( $post->ID ),
|
||||
'format' => 'xml',
|
||||
'maxwidth' => 600,
|
||||
);
|
||||
|
||||
$legacy_controller = new WP_oEmbed_Controller();
|
||||
$legacy_controller->dispatch( $request );
|
||||
|
||||
$headers = xdebug_get_headers();
|
||||
|
||||
$this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user