Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AggregateTest.php
Go to the documentation of this file.
1 <?php
7 
8 class AggregateTest extends \PHPUnit\Framework\TestCase
9 {
13  private $_model;
14 
18  private $_fileList;
19 
23  private $_baseFiles;
24 
28  private $_themeFiles;
29 
33  private $_overridingBaseFiles;
34 
38  private $_overridingThemeFiles;
39 
40  protected function setUp()
41  {
42  $this->_fileList = $this->createMock(\Magento\Framework\View\File\FileList::class);
43  $this->_baseFiles = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
44  $this->_themeFiles = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
45  $this->_overridingBaseFiles = $this->getMockForAbstractClass(
46  \Magento\Framework\View\File\CollectorInterface::class
47  );
48  $this->_overridingThemeFiles = $this->getMockForAbstractClass(
49  \Magento\Framework\View\File\CollectorInterface::class
50  );
51  $fileListFactory = $this->createMock(\Magento\Framework\View\File\FileList\Factory::class);
52  $fileListFactory->expects($this->once())->method('create')->will($this->returnValue($this->_fileList));
53  $this->_model = new \Magento\Framework\View\Layout\File\Collector\Aggregated(
54  $fileListFactory,
55  $this->_baseFiles,
56  $this->_themeFiles,
57  $this->_overridingBaseFiles,
58  $this->_overridingThemeFiles
59  );
60  }
61 
66  public function testGetFiles()
67  {
68  $parentTheme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
69  $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
70  $theme->expects(
71  $this->once()
72  )->method(
73  'getInheritedThemes'
74  )->will(
75  $this->returnValue([$parentTheme, $parentTheme])
76  );
77 
78  $files = [
79  new \Magento\Framework\View\File('0.xml', 'Module_One'),
80  new \Magento\Framework\View\File('1.xml', 'Module_One', $parentTheme),
81  new \Magento\Framework\View\File('2.xml', 'Module_One', $parentTheme),
82  new \Magento\Framework\View\File('3.xml', 'Module_One', $parentTheme),
83  new \Magento\Framework\View\File('4.xml', 'Module_One', $theme),
84  new \Magento\Framework\View\File('5.xml', 'Module_One', $theme),
85  new \Magento\Framework\View\File('6.xml', 'Module_One', $theme),
86  ];
87 
88  $this->_baseFiles->expects(
89  $this->once()
90  )->method(
91  'getFiles'
92  )->with(
93  $theme
94  )->will(
95  $this->returnValue([$files[0]])
96  );
97 
98  $this->_themeFiles->expects(
99  $this->at(0)
100  )->method(
101  'getFiles'
102  )->with(
103  $parentTheme
104  )->will(
105  $this->returnValue([$files[1]])
106  );
107  $this->_overridingBaseFiles->expects(
108  $this->at(0)
109  )->method(
110  'getFiles'
111  )->with(
112  $parentTheme
113  )->will(
114  $this->returnValue([$files[2]])
115  );
116  $this->_overridingThemeFiles->expects(
117  $this->at(0)
118  )->method(
119  'getFiles'
120  )->with(
121  $parentTheme
122  )->will(
123  $this->returnValue([$files[3]])
124  );
125 
126  $this->_themeFiles->expects(
127  $this->at(1)
128  )->method(
129  'getFiles'
130  )->with(
131  $theme
132  )->will(
133  $this->returnValue([$files[4]])
134  );
135  $this->_overridingBaseFiles->expects(
136  $this->at(1)
137  )->method(
138  'getFiles'
139  )->with(
140  $theme
141  )->will(
142  $this->returnValue([$files[5]])
143  );
144  $this->_overridingThemeFiles->expects(
145  $this->at(1)
146  )->method(
147  'getFiles'
148  )->with(
149  $theme
150  )->will(
151  $this->returnValue([$files[6]])
152  );
153 
154  $this->_fileList->expects($this->at(0))->method('add')->with([$files[0]]);
155  $this->_fileList->expects($this->at(1))->method('add')->with([$files[1]]);
156  $this->_fileList->expects($this->at(2))->method('replace')->with([$files[2]]);
157  $this->_fileList->expects($this->at(3))->method('replace')->with([$files[3]]);
158  $this->_fileList->expects($this->at(4))->method('add')->with([$files[4]]);
159  $this->_fileList->expects($this->at(5))->method('replace')->with([$files[5]]);
160  $this->_fileList->expects($this->at(6))->method('replace')->with([$files[6]]);
161 
162  $this->_fileList->expects($this->atLeastOnce())->method('getAll')->will($this->returnValue($files));
163 
164  $this->assertSame($files, $this->_model->getFiles($theme, '*'));
165  }
166 }
foreach($appDirs as $dir) $files