Пример #1
0
 public function testGenerateLessFileTree()
 {
     $originalContent = 'original content';
     $expectedContent = 'updated content';
     $expectedRelativePath = 'view_preprocessed/less/some/file.less';
     $expectedPath = '/var/view_preprocessed/less/some/file.less';
     $asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $originalContent, 'less');
     $this->magentoImport->expects($this->once())->method('process')->with($chain);
     $this->import->expects($this->once())->method('process')->with($chain);
     $relatedAssetOne = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $relatedAssetOne->expects($this->any())->method('getPath')->will($this->returnValue('related/file_one.css'));
     $relatedAssetOne->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_one.css'"));
     $relatedAssetTwo = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $relatedAssetTwo->expects($this->any())->method('getPath')->will($this->returnValue('related/file_two.css'));
     $relatedAssetTwo->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_two.css'"));
     $assetsMap = [['related/file_one.css', $asset, $relatedAssetOne], ['related/file_two.css', $asset, $relatedAssetTwo]];
     $this->assetRepo->expects($this->any())->method('createRelated')->will($this->returnValueMap($assetsMap));
     $relatedFilesOne = [['related/file_one.css', $asset]];
     $this->import->expects($this->at(1))->method('getRelatedFiles')->will($this->returnValue($relatedFilesOne));
     $relatedFilesTwo = [['related/file_two.css', $asset]];
     $this->import->expects($this->at(3))->method('getRelatedFiles')->will($this->returnValue($relatedFilesTwo));
     $this->import->expects($this->at(5))->method('getRelatedFiles')->will($this->returnValue([]));
     $writeMap = [[$expectedRelativePath, $expectedContent], ['related/file_one.css', "content of 'related/file_one.css'"], ['related/file_two.css', "content of 'related/file_two.css'"]];
     $pathsMap = [[$expectedRelativePath, $expectedPath], ['related/file_one.css', '/var/view_preprocessed/less/related/file_one.css'], ['related/file_two.css', '/var/view_preprocessed/less/related/file_two.css']];
     $this->tmpDirectory->expects($this->any())->method('writeFile')->will($this->returnValueMap($writeMap));
     $this->tmpDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap($pathsMap));
     $actual = $this->object->generateLessFileTree($chain);
     $this->assertSame($expectedPath, $actual);
 }
 public function testGenerateLessFileTree()
 {
     $lessDirectory = 'path/to/less';
     $expectedContent = 'updated content';
     $expectedRelativePath = 'some/file.less';
     $expectedPath = $lessDirectory . '/some/file.less';
     $asset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $chain = $this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false);
     $this->config->expects($this->any())->method('getLessDirectory')->willReturn($lessDirectory);
     $this->tmpDirectory->expects($this->once())->method('isExist')->willReturn(true);
     $this->magentoImport->expects($this->once())->method('process')->with($chain);
     $this->import->expects($this->once())->method('process')->with($chain);
     $this->relatedGenerator->expects($this->once())->method('generate')->with($this->import);
     $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
     $chain->expects($this->once())->method('getContent')->willReturn($expectedContent);
     $chain->expects($this->once())->method('getAsset')->willReturn($asset);
     $this->temporaryFile->expects($this->once())->method('createFile')->with($expectedRelativePath, $expectedContent)->willReturn($expectedPath);
     $this->assertSame($expectedPath, $this->object->generateFileTree($chain));
 }