/** * @param string $originalContent * @param string $foundPath * @param string $resolvedPath * @param array $foundFiles * @param string $expectedContent * * @dataProvider processDataProvider */ public function testProcess($originalContent, $foundPath, $resolvedPath, $foundFiles, $expectedContent) { $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, $originalContent, 'css'); $relatedAsset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false); $relatedAsset->expects($this->once())->method('getFilePath')->will($this->returnValue($resolvedPath)); $context = $this->getMock('\\Magento\\Framework\\View\\Asset\\File\\FallbackContext', [], [], '', false); $this->assetRepo->expects($this->once())->method('createRelated')->with($foundPath, $this->asset)->will($this->returnValue($relatedAsset)); $relatedAsset->expects($this->once())->method('getContext')->will($this->returnValue($context)); $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface'); $this->themeList->expects($this->once())->method('getThemeByFullPath')->will($this->returnValue($theme)); $files = []; foreach ($foundFiles as $file) { $fileObject = $this->getMock('Magento\\Framework\\View\\File', [], [], '', false); $fileObject->expects($this->any())->method('getModule')->will($this->returnValue($file['module'])); $fileObject->expects($this->any())->method('getFilename')->will($this->returnValue($file['filename'])); $files[] = $fileObject; } $this->fileSource->expects($this->once())->method('getFiles')->with($theme, $resolvedPath)->will($this->returnValue($files)); $this->object->process($chain); $this->assertEquals($expectedContent, $chain->getContent()); $this->assertEquals('css', $chain->getContentType()); }
/** * * @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)); }