/**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     // Should mutate all images and stop propagation
     if (function_exists('cloudinary_url')) {
         $src = $element->getAttribute('src');
         $width = $element->getAttribute('width');
         $height = $element->getAttribute('height');
         $sizes = $this->generateSizes();
         $srcset = $this->generateSrcset($src);
         $urlConfig = ['width' => 400, 'height' => 225, 'crop' => 'limit', 'sign_url' => true, 'type' => 'fetch', 'effect' => 'sharpen'];
         if ($width < 100 || $height < 100) {
             $width = $urlConfig['width'];
             $height = $urlConfig['height'];
         } else {
             $urlConfig['width'] = $width;
             $urlConfig['height'] = $height;
         }
         // Create the responsive <amp-img /> tag
         $ampImg = $element->createWritableElement('amp-img');
         $ampImg->setAttribute('src', cloudinary_url($src, $urlConfig));
         $ampImg->setAttribute('width', $width);
         $ampImg->setAttribute('height', $height);
         $ampImg->setAttribute('sizes', $sizes);
         $ampImg->setAttribute('srcset', $srcset);
         $ampImg->setAttribute('layout', 'responsive');
         $ampImg->setAttribute('alt', $element->getAttribute('alt'));
         $ampImg->setAttribute('attribution', $element->getAttribute('attribution'));
         $ampImg->setAttribute('class', 'amp-img');
         $element->replaceWith($ampImg);
         $event->stopPropagation();
     }
 }
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     /** @var ElementInterface $ampImg */
     $ampImg = $element->createWritableElement('amp-img');
     foreach ($this->validAttributes as $attribute) {
         if ($element->getAttribute($attribute)) {
             $ampImg->setAttribute($attribute, $element->getAttribute($attribute));
         }
     }
     return $element->replaceWith($ampImg);
 }
 function it_converts_a_youtube_object_tag(EventInterface $event, ElementInterface $element, Element $child, Element $containerElement, Element $ampYoutubeElement)
 {
     $event->stopPropagation()->shouldBeCalled();
     $element->getChildren()->shouldBeCalled()->willReturn([$child]);
     $child->getAttribute('value')->shouldBeCalled()->willReturn('http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1');
     $element->createWritableElement('div', ['class' => 'youtube-container'])->shouldBeCalled()->willReturn($containerElement);
     $containerElement->appendChild($ampYoutubeElement)->shouldBeCalled();
     $element->replaceWith($containerElement)->shouldBeCalled();
     $element->createWritableElement('amp-youtube', ['data-videoid' => 'XGSy3_Czz8k', 'layout' => 'responsive', 'width' => '560', 'height' => '315'])->shouldBeCalled()->willReturn($ampYoutubeElement);
     $this->handleObject($event, $element);
 }
 public function it_converts_an_image_to_amp_img(ElementInterface $ampImg, EventInterface $event, ElementInterface $element)
 {
     $ampImg->setAttribute('src', 'foo.jpg')->shouldBeCalled();
     $ampImg->setAttribute('width', 300)->shouldBeCalled();
     $ampImg->setAttribute('height', 250)->shouldBeCalled();
     $ampImg->setAttribute('class', 'amp-img')->shouldBeCalled();
     $ampImg->setAttribute('srcset', '')->shouldNotBeCalled();
     $ampImg->setAttribute('alt', '')->shouldNotBeCalled();
     $ampImg->setAttribute('attribution', '')->shouldNotBeCalled();
     $element->getAttribute('src')->shouldBeCalled()->willReturn('foo.jpg');
     $element->getAttribute('width')->shouldBeCalled()->willReturn(300);
     $element->getAttribute('height')->shouldBeCalled()->willReturn(250);
     $element->getAttribute('class')->shouldBeCalled()->willReturn('amp-img');
     $element->getAttribute('srcset')->shouldBeCalled()->willReturn('');
     $element->getAttribute('alt')->shouldBeCalled()->willReturn('');
     $element->getAttribute('attribution')->shouldBeCalled()->willReturn('');
     $element->createWritableElement('amp-img')->willReturn($ampImg);
     $element->replaceWith($ampImg)->shouldBeCalled();
     $this->handleTagImg($event, $element);
 }