Example #1
0
 public function testExecute()
 {
     $file = 'css/styles-m' . '.less';
     $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]);
     $this->objectManager->expects($this->once())->method('configure');
     $this->sourceFileGeneratorPool->expects($this->once())->method('create')->with('less')->willReturn($this->getMock('Magento\\Framework\\Less\\FileGenerator', [], [], '', false));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($file, ['area' => 'frontend', 'theme' => 'Magento/blank', 'locale' => 'en_US'])->willReturn($this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\LocalInterface'));
     $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
     $this->chainFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false));
     $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], [], '', false));
     $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true);
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(['type' => 'less']);
     $this->assertContains('Successfully processed LESS and/or SASS files', $commandTester->getDisplay());
 }
Example #2
0
 /**
  * @expectedException \Magento\Framework\View\Asset\File\NotFoundException
  * @expectedExceptionMessage Unable to get content for 'Magento_Module/dir/file.css'
  */
 public function testGetContentNotFound()
 {
     $this->source->expects($this->once())
         ->method('getContent')
         ->with($this->object)
         ->will($this->returnValue(false));
     $this->object->getContent();
 }
 public function testCreateAsset()
 {
     $this->mockDesign();
     $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/static/'));
     $asset = $this->object->createAsset('test/file.js');
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset);
     $this->assertEquals('area/theme/locale/test/file.js', $asset->getPath());
     $this->assertEquals('test/file.js', $asset->getFilePath());
     $this->assertEquals('js', $asset->getContentType());
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File\\FallbackContext', $asset->getContext());
     $this->assertEquals('', $asset->getModule());
     $this->assertEquals('http://example.com/static/area/theme/locale/test/file.js', $asset->getUrl());
     $this->source->expects($this->once())->method('getFile')->with($asset)->will($this->returnValue('source'));
     $this->source->expects($this->once())->method('getContent')->with($asset)->will($this->returnValue('content'));
     $this->assertEquals('source', $asset->getSourceFile());
     $this->assertEquals('content', $asset->getContent());
     $anotherAsset = $this->object->createAsset('another/file.id');
     $this->assertSame($anotherAsset->getContext(), $asset->getContext());
 }
 /**
  * Test for processContent method (not empty content)
  */
 public function testProcessContentNotEmpty()
 {
     $assetMock = $this->getAssetMock();
     $this->appStateMock->expects(self::once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
     $this->assetSourceMock->expects(self::once())->method('getContent')->with($assetMock)->willReturn(self::TEST_CONTENT);
     $this->temporaryFileMock->expects(self::once())->method('createFile')->with(self::ASSET_PATH, self::TEST_CONTENT)->willReturn(__DIR__ . '/' . self::TMP_PATH_LESS);
     $assetMock->expects(self::once())->method('getPath')->willReturn(self::ASSET_PATH);
     $this->loggerMock->expects(self::never())->method('critical');
     $clearSymbol = ["\n", "\r", "\t", ' '];
     self::assertEquals(trim(str_replace($clearSymbol, '', file_get_contents(__DIR__ . '/' . self::TMP_PATH_CSS))), trim(str_replace($clearSymbol, '', $this->processor->processContent($assetMock))));
 }
 /**
  * Run test for process method
  */
 public function testProcess()
 {
     $this->lockerProcessMock->expects(self::once())->method('lockProcess')->with(self::isType('string'));
     $this->lockerProcessMock->expects(self::once())->method('unlockProcess');
     $assetMock = $this->getAssetNew();
     $this->assetBuilderMock->expects(self::once())->method('setArea')->with(self::AREA)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setTheme')->with(self::THEME)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setLocale')->with(self::LOCALE)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setModule')->with(self::MODULE)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setPath')->with(self::FILE_PATH)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('build')->willReturn($assetMock);
     $this->alternativeSourceMock->expects(self::once())->method('getAlternativesExtensionsNames')->willReturn(['less']);
     $this->assetSourceMock->expects(self::once())->method('getContent')->with($assetMock)->willReturn(self::NEW_CONTENT);
     $frontendCompilation = new FrontendCompilation($this->assetSourceMock, $this->assetBuilderMock, $this->alternativeSourceMock, $this->lockerProcessMock, 'lock');
     $frontendCompilation->process($this->getChainMockExpects());
 }