From b7eb19f8ddb7ccbb6866182d79f86e1209dbae6e Mon Sep 17 00:00:00 2001
From: jrfnl <github_nospam@adviesenzo.nl>
Date: Thu, 29 Sep 2016 18:44:53 +0200
Subject: [PATCH] Unit tests for the oembed regex fixes.

---
 tests/phpunit/tests/oembed.php | 43 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/tests/phpunit/tests/oembed.php b/tests/phpunit/tests/oembed.php
index 6f8787d..92e816a 100644
--- a/tests/phpunit/tests/oembed.php
+++ b/tests/phpunit/tests/oembed.php
@@ -8,7 +8,7 @@ class Tests_oEmbed extends WP_UnitTestCase {
 		'youtube-shorturl'     => '#https?://youtu\.be/.*#i',
 		'vimeo'                => '#https?://(.+\.)?vimeo\.com/.*#i',
 		'dailymotion'          => '#https?://(www\.)?dailymotion\.com/.*#i',
-		'dailymotion-shorturl' => '#https?://dai.ly/.*#i',
+		'dailymotion-shorturl' => '#https?://dai\.ly/.*#i',
 		'flickr'               => '#https?://(www\.)?flickr\.com/.*#i',
 		'flickr-shorturl'      => '#https?://flic\.kr/.*#i',
 		'smugmug'              => '#https?://(.+\.)?smugmug\.com/.*#i',
@@ -16,14 +16,14 @@ class Tests_oEmbed extends WP_UnitTestCase {
 		'photobucket-album'    => 'http://i*.photobucket.com/albums/*',
 		'photobucket-group'    => 'http://gi*.photobucket.com/groups/*',
 		'scribd'               => '#https?://(www\.)?scribd\.com/doc/.*#i',
-		'wordpress-tv'         => '#https?://wordpress.tv/.*#i',
+		'wordpress-tv'         => '#https?://wordpress\.tv/.*#i',
 		'polldaddy'            => '#https?://(.+\.)?polldaddy\.com/.*#i',
 		'polldaddy-shorturl'   => '#https?://poll\.fm/.*#i',
 		'funnyordie'           => '#https?://(www\.)?funnyordie\.com/videos/.*#i',
 		'twitter'              => '#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i',
 		'twitter-timeline'     => '#https?://(www\.)?twitter\.com/.+?/timelines/.*#i',
 		'twitter-moment'       => '#https?://(www\.)?twitter\.com/i/moments/.*#i',
-		'vine'                 => '#https?://vine.co/v/.*#i',
+		'vine'                 => '#https?://vine\.co/v/.*#i',
 		'soundcloud'           => '#https?://(www\.)?soundcloud\.com/.*#i',
 		'slideshare'           => '#https?://(.+?\.)?slideshare\.net/.*#i',
 		'instagram'            => '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i',
@@ -40,7 +40,7 @@ class Tests_oEmbed extends WP_UnitTestCase {
 		'kickstarter-shorturl' => '#https?://kck\.st/.*#i',
 		'cloudup'              => '#https?://cloudup\.com/.*#i',
 		'reverbnation'         => '#https?://(www\.)?reverbnation\.com/.*#i',
-		'videopress'           => '#https?://videopress.com/v/.*#',
+		'videopress'           => '#https?://videopress\.com/v/.*#',
 		'reddit-comments'      => '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i',
 		'speakerdeck'          => '#https?://(www\.)?speakerdeck\.com/.*#i',
 		'facebook-post'        => '#https?://www\.facebook\.com/.*/posts/.*#i',
@@ -812,4 +812,39 @@ class Tests_oEmbed extends WP_UnitTestCase {
 
 	}
 
+
+	/**
+	 * Test the tests
+	 *
+	 * @group oembed
+	 * @ticket 38187
+	 * @dataProvider dataShouldNotMatchOembedRegex
+	 *
+	 * @param string $url A url which should not match any of the predefined providers.
+	 */
+	public function testUrlShouldNotMatchOembedRegex( $url ) {
+
+		$this->assertSame( false, self::$oembed->get_provider( $url, array( 'discover' => false ) ) );
+
+	}
+
+	/**
+	 * Data provider for our oEmbed tests
+	 *
+	 * @return array
+	 */
+	public function dataShouldNotMatchOembedRegex() {
+		$providers = self::$provider_map;
+
+		return array(
+			array( 'http://dairly/something' ),
+			array( 'https://daisly/' ),
+			array( 'http://wordpressstv/' ),
+			array( 'https://wordpressstv/somethingelse' ),
+			array( 'http://vinerco/v/andanother' ),
+			array( 'https://vineqco/v/' ),
+			array( 'http://videopressscom/v/' ),
+			array( 'https://videopresstcom/v/covered' ),
+		);
+	}
 }
-- 
1.9.5.msysgit.0

