public function setup() { $this->themeDirectoryMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\File\\Factory')->disableOriginalConstructor()->getMock(); $this->themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $this->themeMock->expects($this->once())->method('getFullPath')->will($this->returnValue($this->themePath)); $this->readDirFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readDirFactory->expects($this->any())->method('create')->will($this->returnValue($this->themeDirectoryMock)); $this->componentRegistrar = $this->getMockForAbstractClass('Magento\\Framework\\Component\\ComponentRegistrarInterface'); $this->themeFileCollector = new Theme($this->fileFactoryMock, $this->readDirFactory, $this->componentRegistrar); }
public function testGetByAreaWithOtherAreaAndNumericThemeId() { $this->designMock->expects($this->once())->method('getDesignTheme')->will($this->returnValue($this->themeMock)); $this->designMock->expects($this->once())->method('getArea')->will($this->returnValue('design_area')); $this->designMock->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue(12)); $this->themeMock->expects($this->once())->method('getArea')->will($this->returnValue('theme_area')); $this->themeCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->themeCollectionMock)); $this->themeCollectionMock->expects($this->once())->method('getItemById')->with(12)->will($this->returnValue($this->themeMock)); $this->appStateMock->expects($this->once())->method('getAreaCode')->will($this->returnValue('other_area')); $this->assertEquals($this->themeMock, $this->model->get()); }
/** * @param string $area * @param string $themePath * @param string $locale * @param string $module * @param string $expectedId * @param string $savedValue * * @dataProvider cacheDataProvider */ public function testSaveToCache($area, $themePath, $locale, $module, $expectedId, $savedValue) { if (isset($params['theme'])) { $this->theme->expects($this->any())->method('getThemePath')->will($this->returnValue($params['theme'])); $params['theme'] = $this->theme; } else { $this->theme->expects($this->never())->method('getThemePath'); } $this->cache->expects($this->once())->method('save')->with($savedValue, $expectedId)->will($this->returnValue(true)); $actual = $this->object->saveToCache($savedValue, 'file', 'file.ext', $area, $themePath, $locale, $module); $this->assertTrue($actual); }
public function testGetFilesMultiple() { $dirPath = '/Magento_Customer/css/'; $themePath = '/opt/magento2/app/design/frontend/Magento/blank'; $searchPath = 'css/*.test'; $this->themeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themesDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap([['fileA.test', $dirPath . 'fileA.test'], ['fileB.tst', $dirPath . 'fileB.tst'], ['fileC.test', $dirPath . 'fileC.test']])); $fileMock = $this->getMockBuilder('Magento\\Framework\\View\\File')->disableOriginalConstructor()->getMock(); // Verifies correct files are searched for $this->themesDirectoryMock->expects($this->once())->method('search')->with($themePath . '/' . $searchPath)->will($this->returnValue(['fileA.test', 'fileC.test'])); // Verifies Magento_Customer was correctly produced from directory path $this->fileFactoryMock->expects($this->any())->method('create')->with($this->isType('string'), null, $this->equalTo($this->themeMock))->will($this->returnValue($fileMock)); $theme = new Theme($this->filesystemMock, $this->fileFactoryMock); // Only two files should be in array, which were returned from search $this->assertEquals([$fileMock, $fileMock], $theme->getFiles($this->themeMock, 'css/*.test')); }
/** * @param string $area * @param string $themePath * @param string $locale * @param string $module * @param array $files * * @dataProvider getFromCacheDataProvider */ public function testGetFromCache($area, $themePath, $locale, $module, array $files) { if (isset($params['theme'])) { $this->theme->expects($this->any())->method('getThemePath')->will($this->returnValue($params['theme'])); $params['theme'] = $this->theme; } else { $this->theme->expects($this->never())->method('getThemePath'); } $cachedSections = ['type:file|area:frontend|theme:magento_theme|locale:en_US' => ['module:Magento_Module|file:file.ext' => 'one/file.ext', 'module:Magento_Module|file:other_file.ext' => 'one/other_file.ext', 'module:|file:file.ext' => 'two/file.ext', 'module:|file:other_file.ext' => 'two/other_file.ext'], 'type:file|area:frontend|theme:magento_theme|locale:' => ['module:Magento_Module|file:file.ext' => 'three/file.ext', 'module:Magento_Module|file:other_file.ext' => 'four/other_file.ext'], 'type:file|area:frontend|theme:|locale:en_US' => ['module:Magento_Module|file:file.ext' => 'five/file.ext', 'module:Magento_Module|file:other_file.ext' => 'five/other_file.ext'], 'type:file|area:|theme:magento_theme|locale:en_US' => ['module:Magento_Module|file:file.ext' => 'seven/file.ext', 'module:Magento_Module|file:other_file.ext' => 'other_file.ext']]; $this->cache->expects($this->once())->method('load')->will($this->returnCallback(function ($sectionId) use($cachedSections) { if (!isset($cachedSections[$sectionId])) { return false; } return json_encode($cachedSections[$sectionId]); })); foreach ($files as $requested => $expected) { $actual = $this->object->getFromCache('file', $requested, $area, $themePath, $locale, $module); $this->assertSame($expected, $actual); } }
public function testGetFiles() { $files = []; foreach (['shared', 'theme'] as $fileType) { for ($i = 0; $i < 2; $i++) { $file = $this->getMock('\\Magento\\Framework\\Component\\ComponentFile', [], [], '', false); $file->expects($this->once())->method('getFullPath')->will($this->returnValue("{$fileType}/module/{$i}/path")); $file->expects($this->once())->method('getComponentName')->will($this->returnValue('Module_' . $i)); $files[$fileType][] = $file; } } $this->dirSearch->expects($this->any())->method('collectFilesWithContext')->willReturnMap([[ComponentRegistrar::MODULE, 'view/base/layout/*.xml', $files['shared']], [ComponentRegistrar::MODULE, 'view/frontend/layout/*.xml', $files['theme']]]); $this->fileFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->createFileMock()); $this->themeMock->expects($this->once())->method('getData')->with('area')->willReturn('frontend'); $result = $this->fileCollector->getFiles($this->themeMock, '*.xml'); $this->assertCount(4, $result); $this->assertInstanceOf('Magento\\Framework\\View\\File', $result[0]); $this->assertInstanceOf('Magento\\Framework\\View\\File', $result[1]); $this->assertInstanceOf('Magento\\Framework\\View\\File', $result[2]); $this->assertInstanceOf('Magento\\Framework\\View\\File', $result[3]); }
/** * * @dataProvider getFilesDataProvider * * @param $libraryFiles array Files in lib directory * @param $baseFiles array Files in base directory * @param $themeFiles array Files in theme * * * @return void */ public function testGetFiles($libraryFiles, $baseFiles, $themeFiles) { $this->fileListMock->expects($this->at(0))->method('add')->with($this->equalTo($libraryFiles)); $this->fileListMock->expects($this->at(1))->method('add')->with($this->equalTo($baseFiles)); $this->fileListMock->expects($this->any())->method('getAll')->will($this->returnValue(['returnedFile'])); $subPath = '*'; $this->libraryFilesMock->expects($this->atLeastOnce())->method('getFiles')->with($this->themeMock, $subPath)->will($this->returnValue($libraryFiles)); $this->baseFilesMock->expects($this->atLeastOnce())->method('getFiles')->with($this->themeMock, $subPath)->will($this->returnValue($baseFiles)); $this->overriddenBaseFilesMock->expects($this->any())->method('getFiles')->will($this->returnValue($themeFiles)); $aggregated = new Aggregated($this->fileListFactoryMock, $this->libraryFilesMock, $this->baseFilesMock, $this->overriddenBaseFilesMock, $this->loggerMock); $inheritedThemeMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([$inheritedThemeMock])); $this->assertEquals(['returnedFile'], $aggregated->getFiles($this->themeMock, $subPath)); }
/** * * @dataProvider getFilesDataProvider * * @param $libraryFiles array Files in lib directory * @param $themeFiles array Files in theme * * * @return void */ public function testGetFiles($libraryFiles, $themeFiles) { $this->fileListMock->expects($this->any())->method('getAll')->will($this->returnValue(['returnedFile'])); $this->libraryDirectoryMock->expects($this->any())->method('search')->will($this->returnValue($libraryFiles)); $this->libraryDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnCallback(function ($file) { return '/opt/Magneto/lib/' . $file; })); $themePath = '/var/Magento/ATheme'; $subPath = '*'; $this->themesDirectoryMock->expects($this->any())->method('search')->with($themePath . '/web/' . $subPath)->will($this->returnValue($themeFiles)); $library = new Library($this->fileListFactoryMock, $this->fileSystemMock, $this->fileFactoryMock); $inheritedThemeMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $inheritedThemeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([$inheritedThemeMock])); $this->assertEquals(['returnedFile'], $library->getFiles($this->themeMock, $subPath)); }
/** * * @dataProvider getFilesDataProvider * * @param $libraryFiles array Files in lib directory * @param $themeFiles array Files in theme * * * @return void */ public function testGetFiles($libraryFiles, $themeFiles) { $this->fileListMock->expects($this->any())->method('getAll')->will($this->returnValue(['returnedFile'])); $this->libraryDirectoryMock->expects($this->any())->method('search')->will($this->returnValue($libraryFiles)); $this->libraryDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnCallback(function ($file) { return '/opt/Magento/lib/' . $file; })); $themePath = '/var/Magento/ATheme'; $subPath = '*'; $readerMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock(); $this->readFactoryMock->expects($this->once())->method('create')->will($this->returnValue($readerMock)); $this->componentRegistrarMock->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $themePath)->will($this->returnValue(['/path/to/theme'])); $readerMock->expects($this->once())->method('search')->will($this->returnValue($themeFiles)); $inheritedThemeMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $inheritedThemeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([$inheritedThemeMock])); $this->assertEquals(['returnedFile'], $this->library->getFiles($this->themeMock, $subPath)); }
public function testGetFiles() { $sharedFiles = [ 'Namespace/One/view/base/layout/one.xml', 'Namespace/Two/view/base/layout/two.xml' ]; $themeFiles = [ 'Namespace/Two/view/frontend/layout/four.txt', 'Namespace/Two/view/frontend/layout/three.xml' ]; $this->directoryMock->expects($this->any()) ->method('search') ->willReturnMap( [ ['*/*/view/base/layout/*.xml', null, $sharedFiles], ['*/*/view/frontend/layout/*.xml', null, $themeFiles] ] ); $this->pathPatternHelperMock->expects($this->once()) ->method('translatePatternFromGlob') ->with('*.xml') ->willReturn('[^/]*\\.xml'); $this->directoryMock->expects($this->atLeastOnce()) ->method('getAbsolutePath') ->willReturnArgument(0); $this->fileFactoryMock->expects($this->atLeastOnce()) ->method('create') ->willReturn($this->createFileMock()); $this->themeMock->expects($this->once()) ->method('getData') ->with('area') ->willReturn('frontend'); $result = $this->fileCollector->getFiles($this->themeMock, '*.xml'); $this->assertCount(3, $result); $this->assertInstanceOf('Magento\Framework\View\File', $result[0]); $this->assertInstanceOf('Magento\Framework\View\File', $result[1]); $this->assertInstanceOf('Magento\Framework\View\File', $result[2]); }