diff --git a/src/Embed/Platforms/FacebookVideo.php b/src/Embed/Platforms/FacebookVideo.php index 1b6805d..1b49b6a 100644 --- a/src/Embed/Platforms/FacebookVideo.php +++ b/src/Embed/Platforms/FacebookVideo.php @@ -3,13 +3,44 @@ namespace Hyvor\Unfold\Embed\Platforms; use Hyvor\Unfold\Embed\EmbedParserAbstract; +use Hyvor\Unfold\Embed\EmbedParserCustomInterface; +use Hyvor\Unfold\Embed\PlatformHelpers\FacebookHelper; -class FacebookVideo extends EmbedParserAbstract +class FacebookVideo extends EmbedParserAbstract implements EmbedParserCustomInterface { public const PRIORITY = 3; public function regex() { - return []; + return [ + /** + * The following regex are derived from the FacebookVideo oembed schema + * "https://www.facebook.com/* /videos/*", + * "https://www.facebook.com/video.php?id=*", + * "https://www.facebook.com/video.php?v=*" + */ + + // with username + 'https?://(www|m|business)\.facebook\.com/([^/]+)/videos/([^/]+)', + + // video.php with id or v + 'https?://(www|m|business)\.facebook\.com/video\.php\?[^/]*(id|v)=([^&]+)', + + // watch with v + 'https?://(www|m|business)\.facebook\.com/watch/?\?[^/]*v=([^&]+)', + + // reel + 'https?://(www|m|business)\.facebook\.com/reel/([^/]+)', + ]; + } + + public function getEmbedHtml(array $matches): string + { + $sdk = FacebookHelper::sdkScript(); + $url = $this->url; + return << +HTML; } } diff --git a/tests/Unit/Embed/Platforms/FacebookPageTest.php b/tests/Unit/Embed/Platforms/FacebookPageTest.php index f94b60e..d005327 100644 --- a/tests/Unit/Embed/Platforms/FacebookPageTest.php +++ b/tests/Unit/Embed/Platforms/FacebookPageTest.php @@ -6,13 +6,27 @@ use Hyvor\Unfold\Embed\Platforms\FacebookPage; use Hyvor\Unfold\Embed\Platforms\FacebookPost; -it('matches a facebook page', function () { - $url = 'https://www.facebook.com/GMANetwork/about'; +//it('matches a facebook page', function () { +// $url = 'https://www.facebook.com/GMANetwork/about'; +// $parser = new FacebookPage($url); +// +// $response = $parser->parse($parser->match()); +// var_dump($response->html); +// expect($response->html)->toBeString(); +//}); + +it('embeds facebook page', function () { + $url = 'https://www.facebook.com/geonarah'; + $parser = new FacebookPage($url); + $match = $parser->match(); + $response = $parser->parse($match); - $response = $parser->parse($parser->match()); - var_dump($response->html); - expect($response->html)->toBeString(); + $html = $response->html; + expect($html)->toContain('
' + ); }); it('embed class prioritizes facebook post before page', function () { diff --git a/tests/Unit/Embed/Platforms/FacebookPostTest.php b/tests/Unit/Embed/Platforms/FacebookPostTest.php index ff34ac2..cedee52 100644 --- a/tests/Unit/Embed/Platforms/FacebookPostTest.php +++ b/tests/Unit/Embed/Platforms/FacebookPostTest.php @@ -11,9 +11,11 @@ $match = $parser->match(); $response = $parser->parse($match); - var_dump($response->html); - expect(true)->toBeTrue(); - //dd($response->html); + $html = $response->html; + expect($html)->toContain('
' + ); }); it('matches', function ($url) { diff --git a/tests/Unit/Embed/Platforms/FacebookVideoTest.php b/tests/Unit/Embed/Platforms/FacebookVideoTest.php index 9a6061b..dc00531 100644 --- a/tests/Unit/Embed/Platforms/FacebookVideoTest.php +++ b/tests/Unit/Embed/Platforms/FacebookVideoTest.php @@ -1,3 +1,51 @@ getEmbedHtml($facebook->match()); +// +// dd($embed); +//}); + +it('embeds facebook videos', function () { + $url = 'https://www.facebook.com/username/videos/123456789'; + + $parser = new FacebookVideo($url); + $match = $parser->match(); + $response = $parser->parse($match); + + $html = $response->html; + expect($html)->toContain('
' + ); +}); + +it('matches', function ($url) { + $facebook = new FacebookVideo($url); + expect($facebook->match())->toBeArray(); +})->with([ + // with username + 'https://www.facebook.com/username/videos/123456789', + + // video.php with id + 'https://www.facebook.com/video.php?id=123456789', + 'https://www.facebook.com/video.php?s=1&id=123456789', + + // video.php with v + 'https://www.facebook.com/video.php?v=123456789', + 'https://www.facebook.com/video.php?s=1&v=123456789', + + // watch + 'https://www.facebook.com/watch/?v=123456789', + 'https://www.facebook.com/watch/?s=1&v=123456789', + 'https://www.facebook.com/watch?v=123456789', + + // reel + 'https://www.facebook.com/reel/123456789', +]); \ No newline at end of file