assertEquals(preg_replace('/\s+/', '', $a ?? ''), preg_replace('/\s+/', '', $b ?? ''), $message); } private function getShortcodeHtml( string $urlA, string $urlB, string $firstResponse, string $secondResponse, array $arguments ): string { $firstResponse = str_replace("\n", '', $firstResponse ?? ''); $secondResponse = str_replace("\n", '', $secondResponse ?? ''); $embedContainer = $this->createEmbedContainer($urlA, $urlB, $firstResponse, $secondResponse); return EmbedShortcodeProvider::handle_shortcode($arguments, '', null, '', ['Embeddable' => $embedContainer]); } public function testYoutube() { $url = 'https://www.youtube.com/watch?v=dM15HfUYwF0'; $html = $this->getShortcodeHtml( $url, $url, << EOT, << $url, 'caption' => 'A nice video', 'width' => 777, 'height' => 437, ], ); $this->assertEqualIgnoringWhitespace( <<

A nice video

EOT, $html ); } public function testSoundcloud() { $url = 'https://soundcloud.com/napalmrecords/delain-suckerpunch'; $html = $this->getShortcodeHtml( $url, $url, << EOT, <<","author_name":"Napalm Records","author_url":"https://soundcloud.com/napalmrecords"} EOT, [ 'url' => $url ], ); $this->assertEqualIgnoringWhitespace( << EOT, $html ); } public function testVimeo() { $url = 'https://vimeo.com/680885625'; $html = $this->getShortcodeHtml( $url, $url, << EOT, <<<\/iframe>","width":640,"height":360,"duration":60,"description":"Mount Rainier was the first national park I ever visited so it was definitely exciting to be back with refined skills and better equipment. Here is a quick cap of the trip with more segments on the way.\n\nSong: And What Now of the Birds for Ben by David Jennings - March 3, 2021.","thumbnail_url":"https:\/\/i.vimeocdn.com\/video\/1380153025-d3b1840ae521cd936bdaaafaef280b9c0634e729c6b09bca7767792b553a5220-d_640","thumbnail_width":640,"thumbnail_height":360,"thumbnail_url_with_play_button":"https:\/\/i.vimeocdn.com\/filter\/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1380153025-d3b1840ae521cd936bdaaafaef280b9c0634e729c6b09bca7767792b553a5220-d_640&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png","upload_date":"2022-02-23 08:54:15","video_id":680885625,"uri":"\/videos\/680885625"} EOT, [ 'url' => $url ], ); $this->assertEqualIgnoringWhitespace( << EOT, $html ); } public function testFlickr() { $urlA = 'https://www.flickr.com/photos/philocycler/32119532132/in/photolist-QWhZSL-DFFK9V-JcDYRD-S5ksMB-KPznfz-dT81te-2aqUUb1-Gur1ok-cgfEL1-dUu2Cv-8iqmZ9-z5ktAq-z5mCCE-9FmXnE-UH4Y1d-VZsXJn-22zGNHz-e1mzTR-22uVLSo-VJJWsE-VJJJQG-8in8np-agL5ae-9KKkAe-29if7Rt'; $urlB = 'https://live.staticflickr.com/759/32119532132_50c3f7933f_b.jpg'; $html = $this->getShortcodeHtml( $urlA, $urlB, << EOT, <<\"bird\"<\/a>

Birdy

EOT, $html ); } public function testAudio() { // not implemented in Silerstripe so will fallback to a link to $urlA $urlA = 'https://www.someaudioplace.com/12345'; $urlB = 'https://www.someaudioplace.com/listen/12345'; $html = $this->getShortcodeHtml( $urlA, $urlB, << EOT, <<"} EOT, [ 'url' => $urlB, ], ); $this->assertEqualIgnoringWhitespace( << EOT, $html ); } public function testFlushCachedShortcodes() { /** @var CacheInterface $cache */ $url = 'http://www.test-service.com/abc123'; $content = '

Some content with an [embed url="' . $url . '" thumbnail="https://example.com/mythumb.jpg" ' . 'class="leftAlone ss-htmleditorfield-file embed" width="480" height="270"]' . $url . '[/embed]

'; $embedHtml = '

A nice video

EOT, $html ); } public function testWhitelistIsConfigurable() { // Allow new whitelisted attribute Config::modify()->merge(EmbedShortcodeProvider::class, 'attribute_whitelist', ['data-some-value']); $url = 'https://www.youtube.com/watch?v=dM15HfUYwF0'; $html = $this->getShortcodeHtml( $url, $url, << EOT, << $url, 'caption' => 'A nice video', 'width' => 779, 'height' => 437, 'data-some-value' => 'my-data', 'onmouseover' => 'alert(2)', 'style' => 'background-color:red;', ], ); $this->assertEqualIgnoringWhitespace( <<

A nice video

EOT, $html ); } }