From 6473bc82d42a6dd87e09e4a4082215ac90a7de2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Ke=C3=9Feler?= Date: Tue, 16 Mar 2021 23:00:18 +0100 Subject: [PATCH] fix: video with attributes --- src/ChrisKonnertz/OpenGraph/OpenGraph.php | 2 +- tests/OpenGraphTests.php | 28 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ChrisKonnertz/OpenGraph/OpenGraph.php b/src/ChrisKonnertz/OpenGraph/OpenGraph.php index 4dec6aa..d768155 100644 --- a/src/ChrisKonnertz/OpenGraph/OpenGraph.php +++ b/src/ChrisKonnertz/OpenGraph/OpenGraph.php @@ -567,7 +567,7 @@ public function video(string $videoFile, array $attributes = null) : self ]; $tag = $this->lastTag('type'); - if ($tag and starts_with($tag->value, 'video.')) { + if ($tag and strpos($tag->value, 'video.') === 0) { $specialValid = [ 'actor', 'role', diff --git a/tests/OpenGraphTests.php b/tests/OpenGraphTests.php index d51902b..24deb11 100644 --- a/tests/OpenGraphTests.php +++ b/tests/OpenGraphTests.php @@ -5,10 +5,10 @@ */ class OpenGraphTest extends \PHPUnit\Framework\TestCase { - + /** * Creates and returns a new instance - * + * * @return ChrisKonnertz\OpenGraph\OpenGraph */ protected function getInstance() @@ -18,7 +18,7 @@ protected function getInstance() /** * Creates and returns a new instance with dummy values - * + * * @return ChrisKonnertz\OpenGraph\OpenGraph */ protected function getDummy() @@ -110,12 +110,12 @@ public function testMbDescription() $og = $this->getDummy(); mb_internal_encoding('UTF-8'); - + $char = '☺'; // Unicode char U+263A (white smiley) $og->description($char, 1); $tag = $og->lastTag('description'); - + $this->assertEquals($tag->value, $char); } @@ -130,10 +130,26 @@ public function testUrl() $og->clear(); $url = 'http://example.org/'; - putenv('APP_URL='.$url); + putenv('APP_URL=' . $url); $og->url($url); $tag = $og->lastTag('url'); $this->assertEquals($tag->value, $url); } + public function testVideoAttributes() + { + $og = $this->getDummy(); + $og->video('https://example.org/video.swf', [ + 'width' => 300, + 'height' => 200, + 'type' => 'application/x-shockwave-flash' + ]); + + $tag = $og->lastTag('video'); + $this->assertEquals($tag->value, 'https://example.org/video.swf'); + + $tag = $og->lastTag('video:type'); + $this->assertEquals($tag->value, 'application/x-shockwave-flash'); + } + }