/**
  * @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();
     }
 }
 function it_skips_converting_non_youtube_object_tags(EventInterface $event, ElementInterface $element, ElementInterface $childElement)
 {
     $element->getChildren()->shouldBeCalled()->willReturn([$childElement]);
     $childElement->getAttribute('value')->shouldBeCalled()->willReturn('http://metube.com/embed/XGSy3_Czz8k');
     $event->stopPropagation()->shouldNotBeCalled();
     $element->createWritableElement('div', ['class' => 'youtube-container'])->shouldNotBeCalled();
     $this->handleObject($event, $element);
 }
 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);
 }
 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);
 }
 /**
  * Create an amp-twitter tag
  *
  * @param ElementInterface $element
  * @param $twitterStatusId
  * @return ElementInterface
  */
 private function createAmpTwitterTag(ElementInterface $element, $twitterStatusId)
 {
     return $element->createWritableElement('amp-twitter', ['layout' => 'responsive', 'data-tweetid' => $twitterStatusId, 'width' => 390, 'height' => 330, 'data-cards' => 'hidden']);
 }
 /**
  * @param ElementInterface $element
  * @param $embedCode
  * @return ElementInterface
  */
 private function createAmpTag(ElementInterface $element, $embedCode)
 {
     return $element->createWritableElement('amp-youtube', ['data-videoid' => $embedCode, 'layout' => 'responsive', 'width' => '560', 'height' => '315']);
 }