From 245709dcd1dcd81de428a9e013c276b161732903 Mon Sep 17 00:00:00 2001
From: Andrew Ozz ]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content );
+ }
// Put the line breaks back.
return str_replace( '', "\n", $content );
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index 433943268b..5faa0cfae7 100644
--- a/tests/phpunit/tests/media.php
+++ b/tests/phpunit/tests/media.php
@@ -158,6 +158,72 @@ EOF;
$this->assertEquals( $content, $result );
}
+ function data_autoembed() {
+ return array(
+
+ // Should embed
+ array(
+'https://w.org',
+'[embed]'
+ ),
+ array(
+'test
+ https://w.org
+test',
+'test
+ [embed]
+test'
+ ),
+ array(
+' https://w.org [embed] https://w.org [embed] test
+https://w.org
+test test
+[embed]
+test https://w.org
+ [embed]
+
https://w.org
+'
+ ),
+ array(
+'
+https://w.org'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_autoembed
+ */
+ function test_autoembed( $content, $result = null ) {
+ $wp_embed = new Test_Autoembed;
+
+ $this->assertEquals( $wp_embed->autoembed( $content ), $result ? $result : $content );
+ }
+
function test_wp_prepare_attachment_for_js() {
// Attachment without media
$id = wp_insert_attachment(array(
@@ -1612,3 +1678,12 @@ EOF;
$this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
}
}
+
+/**
+ * Helper class for `test_autoembed`.
+ */
+class Test_Autoembed extends WP_Embed {
+ public function shortcode( $attr, $url = '' ) {
+ return '[embed]';
+ }
+}