ResponsiveEmbedsTest.php
62 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ResponsiveEmbedsTest.php |
| 4 | * |
| 5 | * @package Tests |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | namespace Embera\Html; |
| 13 | |
| 14 | use PHPUnit\Framework\TestCase; |
| 15 | |
| 16 | class ResponsiveEmbedsTest extends TestCase |
| 17 | { |
| 18 | public function testEmptyHtmlResponse() |
| 19 | { |
| 20 | $response = [ |
| 21 | 'type' => 'video', |
| 22 | 'embera_provider_name' => 'Youtube', |
| 23 | 'html' => '', |
| 24 | 'other' => true, |
| 25 | ]; |
| 26 | |
| 27 | $responsive = new ResponsiveEmbeds(); |
| 28 | $this->assertEquals($responsive->transform($response), $response); |
| 29 | } |
| 30 | |
| 31 | public function testBasicYoutubeResponse() |
| 32 | { |
| 33 | $html = '<iframe width="560" height="315" src="https://www.youtube.com/embed/ovpVWuuUgJg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'; |
| 34 | $expected = '<div class="embera-embed-responsive embera-embed-responsive-video embera-embed-responsive-provider-youtube"><iframe class="embera-embed-responsive-item embera-embed-responsive-item-video" src="https://www.youtube.com/embed/ovpVWuuUgJg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'; |
| 35 | $response = [ |
| 36 | 'type' => 'video', |
| 37 | 'embera_provider_name' => 'Youtube', |
| 38 | 'html' => $html, |
| 39 | ]; |
| 40 | |
| 41 | $responsive = new ResponsiveEmbeds(); |
| 42 | $responsiveResponse = $responsive->transform($response); |
| 43 | $this->assertEquals($expected, $responsiveResponse['html']); |
| 44 | } |
| 45 | |
| 46 | public function testAdvancedYoutubeResponse() |
| 47 | { |
| 48 | $html = '<iframe class="example" width="560" height="315" src="https://www.youtube.com/embed/ovpVWuuUgJg" frameborder="0" style="width:100px;margin:0;height:40px;max-height:100px;" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'; |
| 49 | $expected = '<div class="embera-embed-responsive embera-embed-responsive-video embera-embed-responsive-provider-youtube"><iframe class="example embera-embed-responsive-item embera-embed-responsive-item-video" src="https://www.youtube.com/embed/ovpVWuuUgJg" frameborder="0" style="margin:0;" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'; |
| 50 | $response = [ |
| 51 | 'type' => 'video', |
| 52 | 'embera_provider_name' => 'Youtube', |
| 53 | 'html' => $html, |
| 54 | ]; |
| 55 | |
| 56 | $responsive = new ResponsiveEmbeds(); |
| 57 | $responsiveResponse = $responsive->transform($response); |
| 58 | $this->assertEquals($expected, $responsiveResponse['html']); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 |