Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HeadTest.php
Go to the documentation of this file.
1 <?php
8 
12 
13 class HeadTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
20  protected function setUp()
21  {
22  $this->model = new Head();
23  }
24 
25  public function testInterpret()
26  {
27  $readerContextMock = $this->getMockBuilder(\Magento\Framework\View\Layout\Reader\Context::class)
28  ->disableOriginalConstructor()
29  ->getMock();
30  $structureMock = $this->getMockBuilder(\Magento\Framework\View\Page\Config\Structure::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33  $readerContextMock->expects($this->once())
34  ->method('getPageConfigStructure')
35  ->willReturn($structureMock);
36 
37  $xml = file_get_contents(__DIR__ . '/../_files/template_head.xml');
38  $element = new Element($xml);
39 
40  $structureMock->expects($this->at(0))
41  ->method('setTitle')
42  ->with('Test title')
43  ->willReturnSelf();
44 
45  $structureMock->expects($this->at(1))
46  ->method('setMetaData')
47  ->with('meta_name', 'meta_content')
48  ->willReturnSelf();
49 
50  $structureMock->expects($this->at(2))
51  ->method('setMetaData')
52  ->with('og:video:secure_url', 'https://secure.example.com/movie.swf')
53  ->willReturnSelf();
54 
55  $structureMock->expects($this->at(3))
56  ->method('setMetaData')
57  ->with('og:locale:alternate', 'uk_UA')
58  ->willReturnSelf();
59 
60  $structureMock->expects($this->at(4))
61  ->method('addAssets')
62  ->with('path/file-3.css', ['src' => 'path/file-3.css', 'media' => 'all', 'content_type' => 'css'])
63  ->willReturnSelf();
64 
65  $structureMock->expects($this->at(5))
66  ->method('addAssets')
67  ->with('path/file.js', ['src' => 'path/file.js', 'defer' => 'defer', 'content_type' => 'js'])
68  ->willReturnSelf();
69 
70  $structureMock->expects($this->at(6))
71  ->method('addAssets')
72  ->with('http://url.com', ['src' => 'http://url.com', 'src_type' => 'url'])
73  ->willReturnSelf();
74 
75  $structureMock->expects($this->at(7))
76  ->method('removeAssets')
77  ->with('path/remove/file.css')
78  ->willReturnSelf();
79 
80  $structureMock->expects($this->at(8))
81  ->method('setElementAttribute')
82  ->with(Config::ELEMENT_TYPE_HEAD, 'head_attribute_name', 'head_attribute_value')
83  ->willReturnSelf();
84 
85  $structureMock->expects($this->at(9))
86  ->method('addAssets')
87  ->with(
88  'path/file-1.css',
89  ['src' => 'path/file-1.css', 'media' => 'all', 'content_type' => 'css', 'order' => 10]
90  )
91  ->willReturnSelf();
92 
93  $structureMock->expects($this->at(10))
94  ->method('addAssets')
95  ->with(
96  'path/file-2.css',
97  ['src' => 'path/file-2.css', 'media' => 'all', 'content_type' => 'css', 'order' => 30]
98  )
99  ->willReturnSelf();
100 
101  $this->assertEquals($this->model, $this->model->interpret($readerContextMock, $element->children()[0]));
102  }
103 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$element
Definition: element.phtml:12