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('