1 | <?php |
||
20 | class ImageRendererTest extends TestCase |
||
21 | { |
||
22 | private $renderer, $urlTranslation; |
||
23 | |||
24 | protected function setUp() |
||
25 | { |
||
26 | $this->urlTranslation = [ |
||
27 | 'http://local.url' => 'http://production.url' |
||
28 | ]; |
||
29 | $this->renderer = new ImageRenderer($this->urlTranslation); |
||
30 | } |
||
31 | |||
32 | public function testGetUrlTranslation() |
||
33 | { |
||
34 | $this->assertSame($this->urlTranslation, $this->renderer->getUrlTranslation()); |
||
35 | } |
||
36 | |||
37 | public function testRender() |
||
38 | { |
||
39 | $inline = $this->prophesize(Image::class); |
||
40 | $altElement = $this->prophesize(Text::class); |
||
41 | |||
42 | $inline |
||
43 | ->firstChild() |
||
44 | ->willReturn($altElement->reveal()); |
||
45 | $inline |
||
46 | ->getUrl() |
||
47 | ->willReturn('http://local.url/img/test.jpg'); |
||
48 | |||
49 | |||
50 | $altElement |
||
51 | ->getContent() |
||
52 | ->willReturn('testAltContent'); |
||
53 | |||
54 | $atts = [ |
||
55 | 'src' => 'http://production.url/img/test.jpg', |
||
56 | 'layout' => 'responsive', |
||
57 | 'alt' => 'testAltContent', |
||
58 | ]; |
||
59 | $expected = new HtmlElement('amp-img', $atts); |
||
60 | |||
61 | $this->assertEquals($expected, $this->renderer->render($inline->reveal(), $this->prophesize(ElementRendererInterface::class)->reveal())); |
||
62 | } |
||
63 | |||
64 | public function testRenderAltAttributeContainsAdditionalAttributes() |
||
65 | { |
||
66 | $inline = $this->prophesize(Image::class); |
||
67 | $altElement = $this->prophesize(Text::class); |
||
68 | |||
69 | $inline |
||
70 | ->firstChild() |
||
71 | ->willReturn($altElement->reveal()); |
||
72 | $inline |
||
73 | ->getUrl() |
||
74 | ->willReturn('http://local.url/img/test.jpg'); |
||
75 | |||
76 | |||
77 | $altElement |
||
78 | ->getContent() |
||
79 | ->willReturn('testAltContent{"width": 30, "height": 15, "layout": "fixed"}'); |
||
80 | |||
81 | $atts = [ |
||
82 | 'src' => 'http://production.url/img/test.jpg', |
||
83 | 'layout' => 'responsive', |
||
84 | 'width' => 30, |
||
85 | 'height' => 15, |
||
86 | 'layout' => 'fixed', |
||
87 | 'alt' => 'testAltContent', |
||
88 | ]; |
||
89 | $expected = new HtmlElement('amp-img', $atts); |
||
90 | |||
91 | $this->assertEquals($expected, $this->renderer->render($inline->reveal(), $this->prophesize(ElementRendererInterface::class)->reveal())); |
||
92 | } |
||
93 | } |