示例#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);
 }
示例#2
0
 /**
  * @param string $assetRelPath
  * @param string $relatedFieldId
  * @param string $similarRelPath
  * @param string $expectedResult
  * @dataProvider convertModuleNotationToPathModularSeparatorDataProvider
  */
 public function testConvertModuleNotationToPathModularSeparator($assetRelPath, $relatedFieldId, $similarRelPath, $expectedResult)
 {
     $similarAsset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $similarAsset->expects($this->any())->method('getPath')->will($this->returnValue($similarRelPath));
     $this->asset->expects($this->once())->method('getPath')->will($this->returnValue($assetRelPath));
     $this->assetRepo->expects($this->once())->method('createSimilar')->with($relatedFieldId, $this->asset)->will($this->returnValue($similarAsset));
     $this->assertEquals($expectedResult, $this->object->convertModuleNotationToPath($this->asset, $relatedFieldId));
 }
 /**
  * @param bool $isSecure
  * @dataProvider getViewFileUrlDataProvider
  */
 public function testGetViewFileUrl($isSecure)
 {
     $this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure));
     $this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) {
         return isset($value['_secure']) && $value['_secure'] === $isSecure;
     }))->will($this->returnValue('result url'));
     $this->assertEquals('result url', $this->model->getViewFileUrl('some file'));
 }
示例#4
0
 public function testGetTranslationFilePath()
 {
     $path = 'path';
     $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']);
     $this->assetRepoMock->expects($this->atLeastOnce())->method('getStaticViewFileContext')->willReturn($contextMock);
     $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path);
     $this->assertEquals($path, $this->model->getTranslationFilePath());
 }
示例#5
0
 protected function setUp()
 {
     $baseUrl = 'http://example.com/pub/static/';
     $path = 'frontend/Magento/blank/en_US';
     $this->context = $this->getMock('\\Magento\\Framework\\View\\Asset\\File\\Context', null, [$baseUrl, DirectoryList::STATIC_VIEW, $path]);
     $this->assetRepo = $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false);
     $this->assetRepo->expects($this->any())->method('getStaticViewFileContext')->will($this->returnValue($this->context));
     $this->object = new \Magento\Framework\View\Asset\NotationResolver\Variable($this->assetRepo);
 }
示例#6
0
 public function testGetTemplateFileName()
 {
     $params = array('area' => 'some_area', 'themeModel' => $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', array(), array(), '', false, false), 'module' => 'Some_Module');
     $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 testCreateTranslateConfigAsset()
 {
     $path = 'relative path';
     $expectedPath = $path . '/' . FileManager::TRANSLATION_CONFIG_FILE_NAME;
     $fileMock = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']);
     $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock);
     $contextMock->expects($this->once())->method('getPath')->willReturn($path);
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with($expectedPath, '')->willReturn($fileMock);
     $this->assertSame($fileMock, $this->model->createTranslateConfigAsset());
 }
 public function testCreateRequireJsAssetDevMode()
 {
     $this->config->expects($this->once())->method('getConfigFileRelativePath')->will($this->returnValue('requirejs/file.js'));
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->assetRepo->expects($this->once())->method('createArbitrary')->with('requirejs/file.js', '')->will($this->returnValue($this->asset));
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     $this->dir->expects($this->never())->method('isExist');
     $data = 'requirejs config data';
     $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
     $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
     $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
 }
 public function getViewFileUrlWithException()
 {
     $params = ['a' => 'b'];
     $paramsSecure = ['a' => 'b', '_secure' => false];
     $fileId = 'file id';
     $fileUrl = 'exception url';
     $this->requestMock->expects($this->once())->method('isSecure')->willReturn(false);
     $exception = new LocalizedException('message');
     $this->repositoryMock->expects($this->once())->method('getUrlWithParams')->with($fileId, $paramsSecure)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->urlMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($fileUrl);
     $this->assertEquals($fileUrl, $this->model->getViewFileUrl($fileId, $params));
 }
 /**
  * Run test for execute method
  */
 public function testExecute()
 {
     /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
     $assetMock = $this->getMockBuilder(LocalInterface::class)->getMockForAbstractClass();
     $this->validatorMock->expects(self::once())->method('isValid')->with(self::LOCALE_TEST_VALUE)->willReturn(true);
     $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', self::AREA_TEST_VALUE, self::LOCALE_TEST_VALUE, self::THEME_TEST_VALUE, self::TYPE_TEST_VALUE);
     $outputMock->expects(self::at(0))->method('writeln')->with($message);
     $outputMock->expects(self::at(1))->method('writeln')->with('<comment>-> file-test-value/test/file</comment>');
     $outputMock->expects(self::at(2))->method('writeln')->with('<info>Successfully processed.</info>');
     $this->assetRepositoryMock->expects(self::once())->method('createAsset')->with('file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, ['area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_TEST_VALUE, 'locale' => self::LOCALE_TEST_VALUE])->willReturn($assetMock);
     $this->assetPublisherMock->expects(self::once())->method('publish')->with($assetMock);
     $assetMock->expects(self::once())->method('getFilePath')->willReturn(self::FILE_TEST_VALUE);
     $this->sourceThemeDeployCommand->run($this->getInputMock(), $outputMock);
 }
示例#11
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());
 }
示例#12
0
 public function testCreateMinResolverAsset()
 {
     $this->configMock->expects($this->any())->method('getMinResolverRelativePath')->willReturn('relative path');
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with('relative path');
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->object->createMinResolverAsset();
 }
示例#13
0
 public function testAddRss()
 {
     $title = 'test title';
     $href = 'http://test.com';
     $expected = ['attributes' => 'rel="alternate" type="application/rss+xml" title="test title"'];
     $this->assetRepo->expects($this->once())->method('createRemoteAsset')->with($href, 'unknown')->will($this->returnValue($this->remoteAsset));
     $this->pageAssets->expects($this->once())->method('add')->with('link/http://test.com', $this->remoteAsset, $expected);
     $this->assertInstanceOf('Magento\\Framework\\View\\Page\\Config', $this->model->addRss($title, $href));
 }
 public function testClearBundleJsPool()
 {
     $context = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File\\FallbackContext')->disableOriginalConstructor()->getMock();
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->willReturn($this->dir);
     $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($context);
     $context->expects($this->once())->method('getPath')->willReturn('/path/to/directory');
     $this->dir->expects($this->once())->method('delete')->with('/path/to/directory/' . \Magento\Framework\RequireJs\Config::BUNDLE_JS_DIR)->willReturn(true);
     $this->assertTrue($this->object->clearBundleJsPool());
 }
 public function testProcessException()
 {
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, '//@magento_import "some/file.css";', 'css');
     $exception = new \LogicException('Error happened');
     $this->assetRepo->expects($this->once())->method('createRelated')->will($this->throwException($exception));
     $this->errorHandler->expects($this->once())->method('processException')->with($exception);
     $this->object->process($chain);
     $this->assertEquals('', $chain->getContent());
     $this->assertEquals('css', $chain->getContentType());
 }
示例#16
0
 /**
  * @covers \Magento\Cms\Model\Wysiwyg\Config::getSkinImagePlaceholderPath
  */
 public function testGetSkinImagePlaceholderPath()
 {
     $staticPath = 'pub/static';
     $placeholderPath = 'adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
     $expectedResult = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getBaseStaticDir')->willReturn($staticPath);
     $this->assetRepoMock->expects($this->any())->method('createAsset')->with(\Magento\Cms\Model\Wysiwyg\Config::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->willReturn($this->assetFileMock);
     $this->assetFileMock->expects($this->once())->method('getPath')->willReturn($placeholderPath);
     $this->assertEquals($expectedResult, $this->wysiwygConfig->getSkinImagePlaceholderPath());
 }
 /**
  * Run test for execute method with non existing theme
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Verify entered values of the argument and options.
  */
 public function testExecuteNonExistingValue()
 {
     /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
     $assetMock = $this->getMockBuilder(LocalInterface::class)->getMockForAbstractClass();
     $this->validatorMock->expects(self::once())->method('isValid')->with(self::LOCALE_TEST_VALUE)->willReturn(true);
     $this->assetRepositoryMock->expects(self::once())->method('createAsset')->with('file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, ['area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_NONEXISTING_VALUE, 'locale' => self::LOCALE_TEST_VALUE])->willReturn($assetMock);
     $this->assetPublisherMock->expects(self::once())->method('publish')->with($assetMock)->willThrowException(new \Magento\Framework\View\Asset\File\NotFoundException());
     $valueMap = [['area', self::AREA_TEST_VALUE], ['locale', self::LOCALE_TEST_VALUE], ['theme', self::THEME_NONEXISTING_VALUE], ['type', self::TYPE_TEST_VALUE]];
     $this->sourceThemeDeployCommand->run($this->getInputMock($valueMap), $outputMock);
 }
示例#18
0
 public function testGetViewConfig()
 {
     $themeMock = $this->getMock('Magento\\Theme\\Model\\Theme', ['getId', 'getCustomization', 'getCustomViewConfigPath'], [], '', false);
     $themeMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(2));
     $themeMock->expects($this->once())->method('getCustomization')->will($this->returnSelf());
     $themeMock->expects($this->once())->method('getCustomViewConfigPath')->will($this->returnValue(''));
     $params = ['themeModel' => $themeMock];
     $configFile = 'config.xml';
     $this->repositoryMock->expects($this->atLeastOnce())->method('updateDesignParams')->with($this->equalTo($params))->will($this->returnSelf());
     $iterator = $this->getMock('Magento\\Framework\\Config\\FileIterator', [], [], '', false);
     $iterator->expects($this->once())->method('toArray')->will($this->returnValue([]));
     $this->readerMock->expects($this->once())->method('getConfigurationFiles')->with($this->equalTo(basename(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)))->will($this->returnValue($iterator));
     $this->directoryReadMock->expects($this->once())->method('isExist')->with($this->anything())->will($this->returnValue(true));
     $this->fileSystemMock->expects($this->once())->method('getFilename')->with($this->equalTo(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME), $params)->will($this->returnValue($configFile));
     $this->directoryReadMock->expects($this->any())->method('getRelativePath')->with($this->equalTo($configFile))->will($this->returnArgument(0));
     $xmlData = '<view><vars module="Magento_Catalog"><var name="test">1</var></vars></view>';
     $this->directoryReadMock->expects($this->once())->method('readFile')->with($this->equalTo($configFile))->will($this->returnValue($xmlData));
     $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params));
     // lazy load test
     $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params));
 }
示例#19
0
 public function testIteratorInterfaceMerge()
 {
     $assets = [$this->assetJsOne, $this->assetJsTwo];
     $this->logger->expects($this->never())->method('critical');
     /** @var Merged $merged */
     $merged = (new ObjectManager($this))->getObject(Merged::class, ['logger' => $this->logger, 'mergeStrategy' => $this->mergeStrategy, 'assetRepo' => $this->assetRepo, 'assets' => $assets]);
     $mergedAsset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->mergeStrategy->expects($this->once())->method('merge')->with($assets, $mergedAsset)->willReturn(null);
     $this->assetRepo->expects($this->once())->method('createArbitrary')->willReturn($mergedAsset);
     $expectedResult = [$mergedAsset];
     $this->assertIteratorEquals($expectedResult, $merged);
     $this->assertIteratorEquals($expectedResult, $merged);
     // ensure merging happens only once
 }
 /**
  * @param string $mode
  * @param string $requestedPath
  * @param string $requestedModule
  * @param bool $moduleExists
  * @param string $expectedFile
  * @param array $expectedParams
  *
  * @dataProvider launchDataProvider
  */
 public function testLaunch($mode, $requestedPath, $requestedModule, $moduleExists, $expectedFile, array $expectedParams)
 {
     $this->state->expects($this->once())->method('getMode')->will($this->returnValue($mode));
     $this->state->expects($this->once())->method('setAreaCode')->with('area');
     $this->configLoader->expects($this->once())->method('load')->with('area')->will($this->returnValue(['config']));
     $this->objectManager->expects($this->once())->method('configure')->with(['config']);
     $this->request->expects($this->once())->method('get')->with('resource')->will($this->returnValue($requestedPath));
     $this->moduleList->expects($this->any())->method('has')->with($requestedModule)->will($this->returnValue($moduleExists));
     $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $asset->expects($this->once())->method('getSourceFile')->will($this->returnValue('resource/file.css'));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($expectedFile, $expectedParams)->will($this->returnValue($asset));
     $this->publisher->expects($this->once())->method('publish')->with($asset);
     $this->response->expects($this->once())->method('setFilePath')->with('resource/file.css');
     $this->object->launch();
 }
 public function testExecute()
 {
     $themeId = 1;
     $fileParam = '/path/to/file.ext';
     $fileId = 'fileId';
     $sourceFile = '/source/file.ext';
     $relPath = 'file.ext';
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['theme_id', null, $themeId], ['file', null, $fileParam]]);
     $file = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->setMethods(['getId', 'load'])->getMockForAbstractClass();
     $urlDecoder = $this->getMockBuilder('Magento\\Framework\\Url\\DecoderInterface')->getMock();
     $directoryRead = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock();
     $this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Url\\DecoderInterface')->willReturn($urlDecoder);
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Framework\\View\\Design\\ThemeInterface')->willReturn($theme);
     $urlDecoder->expects($this->once())->method('decode')->with($fileParam)->willReturn($fileId);
     $theme->expects($this->once())->method('load')->with($themeId)->willReturnSelf();
     $theme->expects($this->once())->method('getId')->willReturn($themeId);
     $this->repository->expects($this->once())->method('createAsset')->with($fileId, ['themeModel' => $theme])->willReturn($file);
     $this->filesystem->expects($this->once())->method('getDirectoryRead')->with(DirectoryList::ROOT)->willReturn($directoryRead);
     $file->expects($this->once())->method('getSourceFile')->willReturn($sourceFile);
     $directoryRead->expects($this->once())->method('getRelativePath')->with($sourceFile)->willReturn($relPath);
     $this->fileFactory->expects($this->once())->method('create')->with($relPath, ['type' => 'filename', 'value' => $relPath], DirectoryList::ROOT)->willReturn($this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->getMock());
     $this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $this->controller->execute());
 }
示例#22
0
 /**
  * @covers Magento\Theme\Model\Theme\Image\Path::getPreviewImageDefaultUrl
  */
 public function testDefaultPreviewImageUrlGetter()
 {
     $this->_assetRepo->expects($this->once())->method('getUrl')->with(\Magento\Theme\Model\Theme\Image\Path::DEFAULT_PREVIEW_IMAGE);
     $this->model->getPreviewImageDefaultUrl();
 }
示例#23
0
 public function testGetUrlNoSelection()
 {
     $this->testSetBaseNoSelectionFile();
     $this->repository->expects($this->once())->method('getUrl')->will($this->returnValue('someurl'));
     $this->assertEquals('someurl', $this->image->getUrl());
 }