mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group oembed
|
|
*/
|
|
class Tests_oEmbed_Discovery extends WP_UnitTestCase {
|
|
function test_add_oembed_discovery_links_non_singular() {
|
|
ob_start();
|
|
wp_oembed_add_discovery_links();
|
|
$actual = ob_get_clean();
|
|
$this->assertSame( '', $actual );
|
|
}
|
|
|
|
function test_add_oembed_discovery_links_to_post() {
|
|
$post_id = $this->factory->post->create();
|
|
$this->go_to( get_permalink( $post_id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
|
|
ob_start();
|
|
wp_oembed_add_discovery_links();
|
|
$actual = ob_get_clean();
|
|
|
|
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
|
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
|
|
function test_add_oembed_discovery_links_to_page() {
|
|
$post_id = $this->factory->post->create( array(
|
|
'post_type' => 'page'
|
|
));
|
|
$this->go_to( get_permalink( $post_id ) );
|
|
|
|
$this->assertQueryTrue( 'is_page', 'is_singular' );
|
|
|
|
ob_start();
|
|
wp_oembed_add_discovery_links();
|
|
$actual = ob_get_clean();
|
|
|
|
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
|
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
|
|
function test_add_oembed_discovery_links_to_attachment() {
|
|
$post_id = $this->factory->post->create();
|
|
$file = DIR_TESTDATA . '/images/canola.jpg';
|
|
$attachment_id = $this->factory->attachment->create_object( $file, $post_id, array(
|
|
'post_mime_type' => 'image/jpeg',
|
|
) );
|
|
|
|
$this->go_to( get_permalink( $attachment_id ) );
|
|
|
|
$this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' );
|
|
|
|
ob_start();
|
|
wp_oembed_add_discovery_links();
|
|
$actual = ob_get_clean();
|
|
|
|
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
|
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
}
|