Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AlternativeTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative;
11 
12 class AlternativeTest extends \PHPUnit\Framework\TestCase
13 {
17  private $directory;
18 
22  private $rule;
23 
27  private $object;
28 
29  protected function setUp()
30  {
31  $this->directory = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
32  $readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
33  $readFactory->expects($this->any())
34  ->method('create')
35  ->will($this->returnValue($this->directory));
36  $this->rule = $this->createMock(\Magento\Framework\View\Design\Fallback\Rule\RuleInterface::class);
37  $rulePool = $this->createMock(\Magento\Framework\View\Design\Fallback\RulePool::class);
38  $rulePool->expects($this->any())
39  ->method('getRule')
40  ->with('type')
41  ->will($this->returnValue($this->rule));
42  $this->object = new Alternative($readFactory, $rulePool, ['css' => ['less']]);
43  }
44 
50  public function testConstructorException(array $alternativeExtensions)
51  {
52  $this->expectException('\InvalidArgumentException');
53  $this->expectExceptionMessage("\$alternativeExtensions must be an array with format:"
54  . " array('ext1' => array('ext1', 'ext2'), 'ext3' => array(...)]");
55 
56  $readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
57  $rulePool = $this->createMock(\Magento\Framework\View\Design\Fallback\RulePool::class);
58  new Alternative($readFactory, $rulePool, $alternativeExtensions);
59  }
60 
65  {
66  return [
67  'numerical keys' => [['css', 'less']],
68  'non-array values' => [['css' => 'less']],
69  ];
70  }
71 
72  public function testResolve()
73  {
74  $requestedFile = 'file.css';
75  $expected = 'some/dir/file.less';
76 
77  $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
78  $theme->expects($this->any())
79  ->method('getFullPath')
80  ->will($this->returnValue('magento_theme'));
81  $this->rule->expects($this->atLeastOnce())
82  ->method('getPatternDirs')
83  ->will($this->returnValue(['some/dir']));
84 
85  $fileExistsMap = [
86  ['file.css', false],
87  ['file.less', true],
88  ];
89  $this->directory->expects($this->any())
90  ->method('isExist')
91  ->will($this->returnValueMap($fileExistsMap));
92 
93  $actual = $this->object->resolve('type', $requestedFile, 'frontend', $theme, 'en_US', 'Magento_Module');
94  $this->assertSame($expected, $actual);
95  }
96 }
$theme