123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Test for view filesystem model
- */
- namespace Magento\Framework\View\Test\Unit;
- class FileSystemTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_model;
- /**
- * @var \Magento\Framework\View\Design\FileResolution\Fallback\File|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_fileResolution;
- /**
- * @var \Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_templateFileResolution;
- /**
- * @var \Magento\Framework\View\Design\FileResolution\Fallback\LocaleFile|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_localeFileResolution;
- /**
- * @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_staticFileResolution;
- /**
- * @var \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile
- * |\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_emailTemplateFileResolution;
- /**
- * @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $_assetRepo;
- protected function setUp()
- {
- $this->_fileResolution = $this->createMock(\Magento\Framework\View\Design\FileResolution\Fallback\File::class);
- $this->_templateFileResolution = $this->createMock(
- \Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile::class
- );
- $this->_localeFileResolution = $this->createMock(
- \Magento\Framework\View\Design\FileResolution\Fallback\LocaleFile::class
- );
- $this->_staticFileResolution = $this->createMock(
- \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile::class
- );
- $this->_emailTemplateFileResolution = $this->createMock(
- \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile::class
- );
- $this->_assetRepo = $this->createPartialMock(
- \Magento\Framework\View\Asset\Repository::class,
- ['extractScope', 'updateDesignParams', 'createAsset']
- );
- $this->_model = new \Magento\Framework\View\FileSystem(
- $this->_fileResolution,
- $this->_templateFileResolution,
- $this->_localeFileResolution,
- $this->_staticFileResolution,
- $this->_emailTemplateFileResolution,
- $this->_assetRepo
- );
- }
- public function testGetFilename()
- {
- $params = [
- 'area' => 'some_area',
- 'themeModel' => $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class),
- 'module' => 'Some_Module', //It should be set in \Magento\Framework\View\Asset\Repository::extractScope
- // but PHPUnit has troubles with passing arguments by reference
- ];
- $file = 'Some_Module::some_file.ext';
- $expected = 'path/to/some_file.ext';
- $this->_fileResolution->expects($this->once())
- ->method('getFile')
- ->with($params['area'], $params['themeModel'], 'some_file.ext', 'Some_Module')
- ->will($this->returnValue($expected));
- $this->_assetRepo->expects($this->any())
- ->method('extractScope')
- ->with($file, $params)
- ->will($this->returnValue('some_file.ext'));
- $actual = $this->_model->getFilename($file, $params);
- $this->assertEquals($expected, $actual);
- }
- public function testGetTemplateFileName()
- {
- $params = [
- 'area' => 'some_area',
- 'themeModel' => $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class),
- 'module' => 'Some_Module', //It should be set in \Magento\Framework\View\Asset\Repository::extractScope
- // but PHPUnit has troubles with passing arguments by reference
- ];
- $file = 'Some_Module::some_file.ext';
- $expected = 'path/to/some_file.ext';
- $this->_templateFileResolution->expects($this->once())
- ->method('getFile')
- ->with($params['area'], $params['themeModel'], 'some_file.ext', 'Some_Module')
- ->will($this->returnValue($expected));
- $this->_assetRepo->expects($this->any())
- ->method('extractScope')
- ->with($file, $params)
- ->will($this->returnValue('some_file.ext'));
- $actual = $this->_model->getTemplateFileName($file, $params);
- $this->assertEquals($expected, $actual);
- }
- public function testGetLocaleFileName()
- {
- $params = [
- 'area' => 'some_area',
- 'themeModel' => $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class),
- 'locale' => 'some_locale',
- ];
- $file = 'some_file.ext';
- $expected = 'path/to/some_file.ext';
- $this->_localeFileResolution->expects($this->once())
- ->method('getFile')
- ->with($params['area'], $params['themeModel'], $params['locale'], 'some_file.ext')
- ->will($this->returnValue($expected));
- $actual = $this->_model->getLocaleFileName($file, $params);
- $this->assertEquals($expected, $actual);
- }
- public function testGetViewFile()
- {
- $params = [
- 'area' => 'some_area',
- 'themeModel' => $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class),
- 'locale' => 'some_locale',
- 'module' => 'Some_Module',
- ];
- $file = 'Some_Module::some_file.ext';
- $expected = 'path/to/some_file.ext';
- $this->_staticFileResolution->expects($this->once())
- ->method('getFile')
- ->with($params['area'], $params['themeModel'], $params['locale'], 'some_file.ext', 'Some_Module')
- ->will($this->returnValue($expected));
- $actual = $this->_model->getStaticFileName($file, $params);
- $this->assertEquals($expected, $actual);
- }
- /**
- * @param string $path
- * @param string $expectedResult
- * @dataProvider normalizePathDataProvider
- */
- public function testNormalizePath($path, $expectedResult)
- {
- $result = $this->_model->normalizePath($path);
- $this->assertEquals($expectedResult, $result);
- }
- /**
- * @return array
- */
- public function normalizePathDataProvider()
- {
- return [
- 'standard path' => ['/dir/somedir/somefile.ext', '/dir/somedir/somefile.ext'],
- 'one dot path' => ['/dir/somedir/./somefile.ext', '/dir/somedir/somefile.ext'],
- 'two dots path' => ['/dir/somedir/../somefile.ext', '/dir/somefile.ext'],
- 'two times two dots path' => ['/dir/../somedir/../somefile.ext', '/somefile.ext']
- ];
- }
- /**
- * @param string $relatedPath
- * @param string $path
- * @param string $expectedResult
- * @dataProvider offsetPathDataProvider
- */
- public function testOffsetPath($relatedPath, $path, $expectedResult)
- {
- $result = $this->_model->offsetPath($relatedPath, $path);
- $this->assertEquals($expectedResult, $result);
- }
- /**
- * @return array
- */
- public function offsetPathDataProvider()
- {
- return [
- 'local path' => [
- '/some/directory/two/another/file.ext',
- '/some/directory/one/file.ext',
- '../two/another',
- ],
- 'local path reverted' => [
- '/some/directory/one/file.ext',
- '/some/directory/two/another/file.ext',
- '../../one',
- ],
- 'url' => [
- 'http://example.com/images/logo.gif',
- 'http://example.com/themes/demo/css/styles.css',
- '../../../images',
- ],
- 'same path' => [
- '/some/directory/file.ext',
- '/some/directory/file1.ext',
- '.',
- ],
- 'non-normalized' => [
- '/some/directory/../one/file.ext',
- '/some/directory/./two/another/file.ext',
- '../../../one',
- ],
- ];
- }
- public function testGetEmailTemplateFile()
- {
- $locale = \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE;
- $params = [
- 'area' => 'some_area',
- 'themeModel' => $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class),
- 'module' => 'Some_Module',
- 'locale' => $locale
- ];
- $file = 'Some_Module::some_file.ext';
- $expected = 'path/to/some_file.ext';
- $this->_emailTemplateFileResolution->expects($this->once())
- ->method('getFile')
- ->with($params['area'], $params['themeModel'], $locale, $file, 'Some_Module')
- ->will($this->returnValue($expected));
- $actual = $this->_model->getEmailTemplateFileName($file, $params, 'Some_Module');
- $this->assertEquals($expected, $actual);
- }
- }
|