/**
  * @expectedException \Zend_Json_Exception
  */
 public function testGetPackageNameInvalidJson()
 {
     $this->componentRegistrar->expects($this->once())->method('getPath')->willReturn('path/to/A');
     $this->dirRead->expects($this->once())->method('isExist')->willReturn(true);
     $this->dirRead->expects($this->once())->method('readFile')->willReturn('{"name": }');
     $this->themePackageInfo->getPackageName('themeA');
 }
 public function testSetTemplateContext()
 {
     $template = 'themedir/template.phtml';
     $this->rootDirMock->expects($this->once())->method('isFile')->with($template)->will($this->returnValue(true));
     $context = new \Magento\Framework\Object();
     $this->_templateEngine->expects($this->once())->method('render')->with($context);
     $this->_block->setTemplateContext($context);
     $this->_block->fetchView($template);
 }
Example #3
0
 /**
  * @covers \Magento\Framework\App\Config\Initial\Reader::read
  */
 public function testReadValidConfig()
 {
     $testXmlFilesList = array(file_get_contents($this->_filePath . 'initial_config1.xml'), file_get_contents($this->_filePath . 'initial_config2.xml'));
     $expectedConfig = array('data' => array(), 'metadata' => array());
     $this->_fileResolverMock->expects($this->at(0))->method('get')->with('config.xml', 'global')->will($this->returnValue($testXmlFilesList));
     $this->_converterMock->expects($this->once())->method('convert')->with($this->anything())->will($this->returnValue($expectedConfig));
     $this->rootDirectory->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
     $this->rootDirectory->expects($this->any())->method('readFile')->will($this->returnValue('<config></config>'));
     $this->assertEquals($expectedConfig, $this->_model->read());
 }
Example #4
0
 /**
  * test get storage data
  */
 public function testGetStorageData()
 {
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with($this->equalTo(DirectoryList::MEDIA))->will($this->returnValue($this->directoryReadMock));
     $this->directoryReadMock->expects($this->any())->method('isDirectory')->will($this->returnValueMap([['/', true], ['folder_one', true], ['file_three.txt', false], ['folder_one/.svn', false], ['folder_one/file_one.txt', false], ['folder_one/folder_two', true], ['folder_one/folder_two/.htaccess', false], ['folder_one/folder_two/file_two.txt', false]]));
     $paths = ['folder_one', 'file_three.txt', 'folder_one/.svn', 'folder_one/file_one.txt', 'folder_one/folder_two', 'folder_one/folder_two/.htaccess', 'folder_one/folder_two/file_two.txt'];
     sort($paths);
     $this->directoryReadMock->expects($this->once())->method('readRecursively')->with($this->equalTo('/'))->will($this->returnValue($paths));
     $expected = ['files' => ['file_three.txt', 'folder_one/file_one.txt', 'folder_one/folder_two/file_two.txt'], 'directories' => [['name' => 'folder_one', 'path' => '/'], ['name' => 'folder_two', 'path' => 'folder_one']]];
     $actual = $this->storageFile->getStorageData();
     $this->assertEquals($expected, $actual);
 }
Example #5
0
 /**
  * test get storage data
  */
 public function testGetStorageData()
 {
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with($this->equalTo(\Magento\Framework\App\Filesystem::MEDIA_DIR))->will($this->returnValue($this->directoryReadMock));
     $this->directoryReadMock->expects($this->any())->method('isDirectory')->will($this->returnValueMap(array(array('/', true), array('folder_one', true), array('file_three.txt', false), array('folder_one/.svn', false), array('folder_one/file_one.txt', false), array('folder_one/folder_two', true), array('folder_one/folder_two/.htaccess', false), array('folder_one/folder_two/file_two.txt', false))));
     $paths = array('folder_one', 'file_three.txt', 'folder_one/.svn', 'folder_one/file_one.txt', 'folder_one/folder_two', 'folder_one/folder_two/.htaccess', 'folder_one/folder_two/file_two.txt');
     sort($paths);
     $this->directoryReadMock->expects($this->once())->method('readRecursively')->with($this->equalTo('/'))->will($this->returnValue($paths));
     $expected = array('files' => array('file_three.txt', 'folder_one/file_one.txt', 'folder_one/folder_two/file_two.txt'), 'directories' => array(array('name' => 'folder_one', 'path' => '/'), array('name' => 'folder_two', 'path' => 'folder_one')));
     $actual = $this->storageFile->getStorageData();
     $this->assertEquals($expected, $actual);
 }
 public function testResolve()
 {
     $requestedFile = 'file.css';
     $expected = 'some/dir/file.less';
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->any())->method('getFullPath')->will($this->returnValue('magento_theme'));
     $this->rule->expects($this->atLeastOnce())->method('getPatternDirs')->will($this->returnValue(['some/dir']));
     $fileExistsMap = [['file.css', false], ['file.less', true]];
     $this->directory->expects($this->any())->method('isExist')->will($this->returnValueMap($fileExistsMap));
     $actual = $this->object->resolve('type', $requestedFile, 'frontend', $theme, 'en_US', 'Magento_Module');
     $this->assertSame($expected, $actual);
 }
 protected function setUp()
 {
     $this->_resolver = $this->getMock('Magento\\Framework\\View\\Element\\Template\\File\\Resolver', [], [], '', false);
     $this->_validator = $this->getMock('Magento\\Framework\\View\\Element\\Template\\File\\Validator', [], [], '', false);
     $this->rootDirMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false);
     $this->rootDirMock->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
     $this->_filesystem = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $this->_filesystem->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT, DriverPool::FILE)->will($this->returnValue($this->rootDirMock));
     $this->_templateEngine = $this->getMock('Magento\\Framework\\View\\TemplateEnginePool', ['render', 'get'], [], '', false);
     $this->_templateEngine->expects($this->any())->method('get')->will($this->returnValue($this->_templateEngine));
     $appState = $this->getMock('Magento\\Framework\\App\\State', ['getAreaCode'], [], '', false);
     $appState->expects($this->any())->method('getAreaCode')->will($this->returnValue('frontend'));
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_block = $helper->getObject('Magento\\Framework\\View\\Element\\Template', ['filesystem' => $this->_filesystem, 'enginePool' => $this->_templateEngine, 'resolver' => $this->_resolver, 'validator' => $this->_validator, 'appState' => $appState, 'data' => ['template' => 'template.phtml', 'module_name' => 'Fixture_Module']]);
 }
Example #8
0
 public function testResolveNonexistentFile()
 {
     $this->readFactoryMock->expects($this->any())->method('create')->willReturn($this->directoryMock);
     $this->ruleMock->expects($this->once())->method('getPatternDirs')->willReturn(['some/dir']);
     $this->directoryMock->expects($this->once())->method('isExist')->willReturn(false);
     $this->assertFalse($this->object->resolve('type', 'file.ext', 'frontend', $this->getMockForTheme('magento_theme'), 'en_US', 'Magento_Module'));
 }
 public function testCheckUpdater()
 {
     $json = [ReadinessCheck::KEY_READINESS_CHECKS => [CronScriptReadinessCheck::UPDATER_KEY_FILE_PERMISSIONS_VERIFIED => true], ReadinessCheck::KEY_CURRENT_TIMESTAMP => 200, ReadinessCheck::KEY_LAST_TIMESTAMP => 140];
     $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
     $expected = ['success' => true];
     $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
 }
Example #10
0
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     $sizeMap = [['catalog/product/image_1.jpg', ['size' => 399659]], ['catalog/product/image_2.jpg', ['size' => 879394]]];
     $imagesResult = [['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0', 'url' => 'url_to_the_image/image_2.jpg', 'size' => 879394], ['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1', 'url' => 'url_to_the_image/image_1.jpg', 'size' => 399659]];
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0']]];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
     $this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
     $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
 }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Missing key 'packages' in 'composer.lock' file
  */
 public function testGetRequiredExceptionMissingPackages()
 {
     $this->directoryReadMock->expects($this->once())->method('isExist')->will($this->returnValue(true));
     $this->directoryReadMock->expects($this->once())->method('readFile')->with('composer.lock')->will($this->returnValue('{"platform-dev":{"ext-e":"*", "f":"*"}}'));
     $phpInfo = new PhpInformation($this->filesystemMock);
     $phpInfo->getRequired();
 }
Example #12
0
 public function testProcessRequestReturnsNotFoundIfFileIsNotSynchronized()
 {
     $this->sync->expects($this->once())->method('synchronize')->with(self::RELATIVE_FILE_PATH);
     $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with()->will($this->returnValue(self::MEDIA_DIRECTORY));
     $this->directoryMock->expects($this->once())->method('isReadable')->with(self::RELATIVE_FILE_PATH)->will($this->returnValue(false));
     $this->responseMock->expects($this->once())->method('setHttpResponseCode')->with(404);
     $this->assertSame($this->responseMock, $this->model->launch());
 }
Example #13
0
 public function testResolveFromCache()
 {
     $expectedPath = '/some/dir/file.ext';
     $this->cache->expects($this->once())->method('getFromCache')->with('type', 'file.ext', 'frontend', 'magento_theme', 'en_US', 'Magento_Module')->will($this->returnValue($expectedPath));
     $this->directory->expects($this->once())->method('getAbsolutePath')->with($expectedPath)->will($this->returnValue($expectedPath));
     $this->rule->expects($this->never())->method('getPatternDirs');
     $this->cache->expects($this->never())->method('saveToCache');
     $actualPath = $this->object->resolve('type', 'file.ext', 'frontend', $this->getMockForTheme('magento_theme'), 'en_US', 'Magento_Module');
     $this->assertSame($expectedPath, $actualPath);
 }
Example #14
0
 public function testUploadJsFile()
 {
     $fileName = 'file.name';
     $this->_fileSizeMock->expects($this->once())->method('getMaxFileSize')->will($this->returnValue(600 * self::MB_MULTIPLIER));
     $this->_service = new \Magento\Theme\Model\Uploader\Service($this->_filesystemMock, $this->_fileSizeMock, $this->_uploaderFactory, ['js' => '500M']);
     $this->_directoryMock->expects($this->once())->method('getRelativePath')->with($fileName)->will($this->returnValue($fileName));
     $this->_directoryMock->expects($this->once())->method('readFile')->with($fileName)->will($this->returnValue('content'));
     $this->_uploader->expects($this->once())->method('validateFile')->will($this->returnValue(['name' => $fileName, 'tmp_name' => $fileName]));
     $this->_uploader->expects($this->once())->method('getFileSize')->will($this->returnValue('499'));
     $this->assertEquals(['content' => 'content', 'filename' => $fileName], $this->_service->uploadJsFile($fileName));
 }
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     // @codingStandardsIgnoreStart
     $encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image`_2.jpg","size":399659}]';
     // @codingStandardsIgnoreEnd
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image']]];
     $firstStat = ['size' => 879394];
     $secondStat = ['size' => 399659];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
     $this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
     $this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
     $this->assertSame($encodedString, $this->content->getImagesJson());
 }
Example #16
0
 public function testRead()
 {
     $this->_filesystemDirectoryMock->expects($this->at(1))->method('readFile')->will($this->returnValue(file_get_contents($this->_paths[0])));
     $this->_filesystemDirectoryMock->expects($this->at(3))->method('readFile')->will($this->returnValue(file_get_contents($this->_paths[1])));
     $this->_moduleDirResolver->expects($this->at(0))->method('getModuleName')->with(__DIR__ . '/_files/Fixture/ModuleOne/etc/email_templates_one.xml')->will($this->returnValue('Fixture_ModuleOne'));
     $this->_moduleDirResolver->expects($this->at(1))->method('getModuleName')->with(__DIR__ . '/_files/Fixture/ModuleTwo/etc/email_templates_two.xml')->will($this->returnValue('Fixture_ModuleTwo'));
     $constraint = function (\DOMDocument $actual) {
         try {
             $expected = file_get_contents(__DIR__ . '/_files/email_templates_merged.xml');
             $expectedNorm = preg_replace('/xsi:noNamespaceSchemaLocation="[^"]*"/', '', $expected, 1);
             $actualNorm = preg_replace('/xsi:noNamespaceSchemaLocation="[^"]*"/', '', $actual->saveXML(), 1);
             \PHPUnit_Framework_Assert::assertXmlStringEqualsXmlString($expectedNorm, $actualNorm);
             return true;
         } catch (\PHPUnit_Framework_AssertionFailedError $e) {
             return false;
         }
     };
     $expectedResult = new \stdClass();
     $this->_converter->expects($this->once())->method('convert')->with($this->callback($constraint))->will($this->returnValue($expectedResult));
     $this->assertSame($expectedResult, $this->_model->read('scope'));
 }
Example #17
0
 public function testProcessRequestReturnsFileIfItsProperlySynchronized()
 {
     $relativeFilePath = '_files';
     $filePath = str_replace('\\', '/', __DIR__ . '/' . $relativeFilePath);
     $this->_requestMock->expects($this->any())->method('getPathInfo')->will($this->returnValue($this->_mediaDirectory . '/'));
     $this->_sync->expects($this->once())->method('synchronize');
     $this->_requestMock->expects($this->any())->method('getFilePath')->will($this->returnValue($filePath));
     $this->directoryReadMock->expects($this->once())->method('getRelativePath')->with($filePath)->will($this->returnValue($relativeFilePath));
     $this->directoryReadMock->expects($this->once())->method('isReadable')->with($relativeFilePath)->will($this->returnValue(true));
     $this->_responseMock->expects($this->once())->method('setFilePath')->with($filePath);
     $this->assertSame($this->_responseMock, $this->_model->launch());
 }
Example #18
0
 protected function setUp()
 {
     $this->resolver = $this->getMock('Magento\\Framework\\View\\Element\\Template\\File\\Resolver', [], [], '', false);
     $this->validator = $this->getMock('Magento\\Framework\\View\\Element\\Template\\File\\Validator', [], [], '', false);
     $this->rootDirMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false);
     $this->rootDirMock->expects($this->any())->method('getRelativePath')->willReturnArgument(0);
     $this->filesystem = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $this->filesystem->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT, DriverPool::FILE)->willReturn($this->rootDirMock);
     $this->templateEngine = $this->getMock('Magento\\Framework\\View\\TemplateEnginePool', ['render', 'get'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->templateEngine->expects($this->any())->method('get')->willReturn($this->templateEngine);
     $appState = $this->getMock('Magento\\Framework\\App\\State', ['getAreaCode'], [], '', false);
     $appState->expects($this->any())->method('getAreaCode')->willReturn('frontend');
     $storeManagerMock = $this->getMock(StoreManager::class, [], [], '', false);
     $storeMock = $this->getMock(Store::class, [], [], '', false);
     $storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
     $storeMock->expects($this->any())->method('getCode')->willReturn('storeCode');
     $urlBuilderMock = $this->getMock(UrlInterface::class, [], [], '', false);
     $urlBuilderMock->expects($this->any())->method('getBaseUrl')->willReturn('baseUrl');
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->block = $helper->getObject('Magento\\Framework\\View\\Element\\Template', ['filesystem' => $this->filesystem, 'enginePool' => $this->templateEngine, 'resolver' => $this->resolver, 'validator' => $this->validator, 'appState' => $appState, 'logger' => $this->loggerMock, 'storeManager' => $storeManagerMock, 'urlBuilder' => $urlBuilderMock, 'data' => ['template' => 'template.phtml', 'module_name' => 'Fixture_Module']]);
 }
 public function testGetFilesWrongAncestor()
 {
     $themePath = 'area/theme_path';
     $inputPath = '*.xml';
     $filePath = 'design/area/theme_path/Module_One/override/theme/vendor/parent_theme/1.xml';
     $expectedMessage = "Trying to override modular view file '{$filePath}' for theme 'vendor/parent_theme'" . ", which is not ancestor of theme 'vendor/theme_path'";
     $this->setExpectedException('Magento\\Framework\\Exception\\LocalizedException', $expectedMessage);
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->once())->method('getFullPath')->willReturn($themePath);
     $theme->expects($this->once())->method('getParentTheme')->willReturn(null);
     $theme->expects($this->once())->method('getCode')->willReturn('vendor/theme_path');
     $this->themeDirectory->expects($this->once())->method('search')->with('*_*/override/theme/*/*/*.xml')->willReturn([$filePath]);
     $this->pathPatternHelperMock->expects($this->any())->method('translatePatternFromGlob')->with($inputPath)->willReturn('[^/]*\\.xml');
     $this->componentRegistrar->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $themePath)->will($this->returnValue('/full/theme/path'));
     $this->model->getFiles($theme, $inputPath);
 }
 /**
  * Setup DirectoryReadMock to use a specified directory for reading composer files
  *
  * @param $composerDir string Directory under _files that contains composer files
  */
 private function setupDirectoryMock($composerDir)
 {
     $valueMap = [['vendor_path.php', null, __DIR__ . '/_files/vendor_path.php'], [null, null, __DIR__ . '/_files/' . $composerDir]];
     $this->directoryReadMock->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap($valueMap));
 }
Example #21
0
    protected function setUp()
    {
        $this->_resolver = $this->getMock(
            'Magento\Framework\View\Element\Template\File\Resolver',
            [],
            [],
            '',
            false
        );

        $this->_validator = $this->getMock(
            'Magento\Framework\View\Element\Template\File\Validator',
            [],
            [],
            '',
            false
        );

        $this->rootDirMock = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
        $this->rootDirMock->expects($this->any())
            ->method('getRelativePath')
            ->will($this->returnArgument(0));
        $appDirMock = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
        $themesDirMock = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
        $themesDirMock->expects($this->any())
            ->method('getAbsolutePath')
            ->will($this->returnValue('themedir'));

        $this->_filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false);
        $this->_filesystem->expects($this->any())
            ->method('getDirectoryRead')
            ->will($this->returnValueMap([
                [\Magento\Framework\App\Filesystem\DirectoryList::THEMES, DriverPool::FILE, $themesDirMock],
                [\Magento\Framework\App\Filesystem\DirectoryList::APP, DriverPool::FILE, $appDirMock],
                [\Magento\Framework\App\Filesystem\DirectoryList::ROOT, DriverPool::FILE, $this->rootDirMock],
                [
                    \Magento\Framework\App\Filesystem\DirectoryList::TEMPLATE_MINIFICATION_DIR, DriverPool::FILE,
                    $this->rootDirMock
                ],
            ]));

        $this->_templateEngine = $this->getMock(
            'Magento\Framework\View\TemplateEnginePool',
            ['render', 'get'],
            [],
            '',
            false
        );

        $this->_templateEngine->expects($this->any())->method('get')->will($this->returnValue($this->_templateEngine));

        $appState = $this->getMock('Magento\Framework\App\State', ['getAreaCode'], [], '', false);
        $appState->expects($this->any())->method('getAreaCode')->will($this->returnValue('frontend'));
        $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
        $this->_block = $helper->getObject(
            'Magento\Framework\View\Element\Template',
            [
                'filesystem' => $this->_filesystem,
                'enginePool' => $this->_templateEngine,
                'resolver' => $this->_resolver,
                'validator' => $this->_validator,
                'appState' => $appState,
                'data' => ['template' => 'template.phtml', 'module_name' => 'Fixture_Module']
            ]
        );
    }
Example #22
0
 public function testGetContentsNoFile()
 {
     $this->directoryReadMock->expects($this->atLeastOnce())->method('isFile')->will($this->returnValue(false));
     $license = new License($this->filesystemMock);
     $this->assertFalse($license->getContents());
 }