public function testReplaceTmpEncryptKey() { $keyPlaceholder = \Magento\Install\Model\Installer\Config::TMP_ENCRYPT_KEY_VALUE; $fixtureConfigData = "<key>{$keyPlaceholder}</key>"; $expectedConfigData = '<key>3c7cf2e909fd5e2268a6e1539ae3c835</key>'; $this->_directoryMock->expects($this->once())->method('readFile')->with($this->equalTo($this->_tmpConfigFile))->will($this->returnValue($fixtureConfigData)); $this->_directoryMock->expects($this->once())->method('writeFile')->with($this->equalTo($this->_tmpConfigFile), $this->equalTo($expectedConfigData))->will($this->returnValue($fixtureConfigData)); $this->_model->replaceTmpEncryptKey('3c7cf2e909fd5e2268a6e1539ae3c835'); }
public function testGenerateSwatchVariations() { $this->mediaDirectoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->willReturn('attribute/swatch/e/a/earth.png'); $image = $this->getMock('\\Magento\\Framework\\Image', ['resize', 'save', 'keepTransparency', 'constrainOnly', 'keepFrame', 'keepAspectRatio', 'backgroundColor', 'quality'], [], '', false); $this->imageFactoryMock->expects($this->any())->method('create')->willReturn($image); $this->generateImageConfig(); $image->expects($this->any())->method('resize')->will($this->returnSelf()); $this->mediaHelperObject->generateSwatchVariations('/e/a/earth.png'); }
/** * Set up */ public function setUp() { $this->context = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false); $this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', ['date', 'getConfigTimezone', 'diff', 'format'], [], '', false); $this->varDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['getRelativePath', 'readFile', 'isFile', 'stat'], [], '', false); $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false); $this->varDirectory->expects($this->any())->method('getRelativePath')->willReturn('path'); $this->varDirectory->expects($this->any())->method('readFile')->willReturn('contents'); $this->varDirectory->expects($this->any())->method('isFile')->willReturn(true); $this->varDirectory->expects($this->any())->method('stat')->willReturn(100); $this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->varDirectory); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->report = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Helper\\Report', ['context' => $this->context, 'timeZone' => $this->timezone, 'filesystem' => $this->filesystem]); }
/** * cover \Magento\Theme\Model\Wysiwyg\Storage::deleteDirectory */ public function testDeleteDirectory() { $directoryPath = $this->_storageRoot . '/../root'; $this->_helperStorage->expects($this->atLeastOnce())->method('getStorageRoot')->will($this->returnValue($this->_storageRoot)); $this->directoryWrite->expects($this->once())->method('delete')->with($directoryPath); $this->_storageModel->deleteDirectory($directoryPath); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage wrongColumnsNumber */ public function testRewind() { $this->_directoryMock->expects($this->any())->method('openFile')->will($this->returnValue(new \Magento\Framework\Filesystem\File\Read(__DIR__ . '/_files/test.csv', new \Magento\Framework\Filesystem\Driver\File()))); $model = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/test.csv', $this->_directoryMock); $this->assertSame(-1, $model->key()); $model->next(); $this->assertSame(0, $model->key()); $model->next(); $this->assertSame(1, $model->key()); $model->rewind(); $this->assertSame(0, $model->key()); $model->next(); $model->next(); $this->assertSame(2, $model->key()); $model->current(); }
public function testGetThumbnailPath() { $image = 'image_name.jpg'; $thumbnailPath = '/' . implode('/', array(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, \Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY, $image)); $this->customization->expects($this->any())->method('getCustomizationPath')->will($this->returnValue($this->customizationPath)); $this->directoryWrite->expects($this->any())->method('isExist')->will($this->returnValue(true)); $this->assertEquals($thumbnailPath, $this->helper->getThumbnailPath($image)); }
public function testGetDirsCollectionCreateSubDirectories() { $directoryName = 'test1'; $this->coreFileStorageMock->expects($this->once())->method('checkDbUsage')->willReturn(true); $this->directoryCollectionMock->expects($this->once())->method('getSubdirectories')->with(self::STORAGE_ROOT_DIR)->willReturn([['name' => $directoryName]]); $this->directoryDatabaseFactoryMock->expects($this->once())->method('create')->willReturn($this->directoryCollectionMock); $this->directoryMock->expects($this->once())->method('create')->with(rtrim(self::STORAGE_ROOT_DIR, '/') . '/' . $directoryName); $this->generalTestGetDirsCollection(self::STORAGE_ROOT_DIR); }
public function testRunReadinessCheckLastTimestamp() { $this->dbValidator->expects($this->once())->method('checkDatabaseConnection')->willReturn(true); $this->write->expects($this->once())->method('isExist')->willReturn(true); $this->write->expects($this->once())->method('readFile')->willReturn('{"current_timestamp": 50}'); $expected = [ReadinessCheck::KEY_READINESS_CHECKS => [ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED => true], ReadinessCheck::KEY_PHP_CHECKS => $this->expected, ReadinessCheck::KEY_LAST_TIMESTAMP => 50, ReadinessCheck::KEY_CURRENT_TIMESTAMP => 100]; $expectedJson = json_encode($expected, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); $this->write->expects($this->once())->method('writeFile')->with(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE, $expectedJson); $this->readinessCheck->runReadinessCheck(); }
public function setUpDirectoryWriteInstallation() { // CONFIG $this->directoryWriteMock ->expects($this->at(0)) ->method('isExist') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(1)) ->method('isDirectory') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(2)) ->method('isReadable') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(3)) ->method('isWritable') ->will($this->returnValue(true)); // VAR $this->directoryWriteMock ->expects($this->at(4)) ->method('isExist') ->will($this->returnValue(false)); // MEDIA $this->directoryWriteMock ->expects($this->at(5)) ->method('isExist') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(6)) ->method('isDirectory') ->will($this->returnValue(false)); // STATIC_VIEW $this->directoryWriteMock ->expects($this->at(7)) ->method('isExist') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(8)) ->method('isDirectory') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(9)) ->method('isReadable') ->will($this->returnValue(true)); $this->directoryWriteMock ->expects($this->at(10)) ->method('isWritable') ->will($this->returnValue(false)); }
public function testGetCurrentUrl() { $storeId = 1; $baseUrl = 'http://localhost'; $relativePath = '/../wysiwyg'; $this->imagesHelper->setStoreId($storeId); $this->storeMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)->willReturn($baseUrl); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->directoryWriteMock->expects($this->any())->method('getRelativePath')->willReturn($relativePath); $this->assertEquals($baseUrl . $relativePath . '/', $this->imagesHelper->getCurrentUrl()); }
/** * @covers \Magento\Framework\View\Design\Theme\Image::uploadPreviewImage */ public function testUploadPreviewImage() { $scope = 'test_scope'; $tmpFilePath = '/media_path/tmp/temporary.png'; $this->_themeMock->setData($this->_getThemeSampleData()); $this->_themeMock->setData('preview_image', 'test.png'); $this->_uploaderMock->expects($this->once())->method('uploadPreviewImage')->with($scope, '/media_path/tmp')->will($this->returnValue($tmpFilePath)); $this->_mediaDirectoryMock->expects($this->at(0))->method('getRelativePath')->will($this->returnArgument(0)); $this->_mediaDirectoryMock->expects($this->at(1))->method('delete')->with($this->stringContains('test.png')); $this->_mediaDirectoryMock->expects($this->at(2))->method('delete')->with($tmpFilePath); $this->_model->uploadPreviewImage($scope); }
/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->_driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface', [], '', false, false, true, ['getRealPath']); $this->_driverMock->expects($this->any())->method('getRealPath')->will($this->returnArgument(0)); $this->_directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['delete', 'getDriver'], [], '', false); $this->_directoryMock->expects($this->any())->method('getDriver')->will($this->returnValue($this->_driverMock)); $this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false); $this->_filesystemMock->expects($this->any())->method('getDirectoryWrite')->with(DirectoryList::MEDIA)->will($this->returnValue($this->_directoryMock)); $this->_adapterFactoryMock = $this->getMock('Magento\\Framework\\Image\\AdapterFactory', [], [], '', false); $this->_imageHelperMock = $this->getMock('Magento\\Cms\\Helper\\Wysiwyg\\Images', ['getStorageRoot'], [], '', false); $this->_imageHelperMock->expects($this->any())->method('getStorageRoot')->will($this->returnValue(self::STORAGE_ROOT_DIR)); $this->_resizeParameters = ['width' => 100, 'height' => 50]; $this->_storageCollectionFactoryMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage\\CollectionFactory', [], [], '', false); $this->_storageFileFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\FileFactory', [], [], '', false); $this->_storageDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\DatabaseFactory', [], [], '', false); $this->_directoryDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\Directory\\DatabaseFactory', [], [], '', false); $this->_uploaderFactoryMock = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\UploaderFactory')->disableOriginalConstructor()->getMock(); $this->_sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false); $this->_backendUrlMock = $this->getMock('Magento\\Backend\\Model\\Url', [], [], '', false); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->_model = $objectManagerHelper->getObject('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage', ['session' => $this->_sessionMock, 'backendUrl' => $this->_backendUrlMock, 'cmsWysiwygImages' => $this->_imageHelperMock, 'coreFileStorageDb' => $this->getMock('Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false), 'filesystem' => $this->_filesystemMock, 'imageFactory' => $this->_adapterFactoryMock, 'assetRepo' => $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false), 'storageCollectionFactory' => $this->_storageCollectionFactoryMock, 'storageFileFactory' => $this->_storageFileFactoryMock, 'storageDatabaseFactory' => $this->_storageDatabaseFactoryMock, 'directoryDatabaseFactory' => $this->_directoryDatabaseFactoryMock, 'uploaderFactory' => $this->_uploaderFactoryMock, 'resizeParameters' => $this->_resizeParameters]); }
/** * @test * @return void * @expectedException \InvalidArgumentException * @expectedExceptionMessage The image not found */ public function testGetThumbnailPathNotFound() { $image = 'notFoundImage.png'; $root = '/image'; $sourceNode = '/not/a/root'; $node = base64_encode($sourceNode); $this->request->expects($this->at(0))->method('getParam')->willReturnMap([[\Magento\Theme\Helper\Storage::PARAM_THEME_ID, null, 6], [\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE, null, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE], [\Magento\Theme\Helper\Storage::PARAM_NODE, null, $node]]); $this->urlDecoder->expects($this->once())->method('decode')->with($node)->willReturnCallback(function ($path) { return base64_decode($path); }); $this->directoryWrite->expects($this->once())->method('isDirectory')->with($root . $sourceNode)->willReturn(true); $this->directoryWrite->expects($this->once())->method('getRelativePath')->with($root . $sourceNode)->willReturn($sourceNode); $this->directoryWrite->expects($this->once())->method('isExist')->with($sourceNode . '/' . $image); $this->helper->getThumbnailPath($image); }
/** * Prepare mock of Sitemap model * * @param array $actualData * @param int $maxLines * @param int $maxFileSize * @param array $expectedFile * @param int $expectedWrites * @param array $robotsInfo * @return \Magento\Sitemap\Model\Sitemap|PHPUnit_Framework_MockObject_MockObject * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareSitemapModelMock(&$actualData, $maxLines, $maxFileSize, $expectedFile, $expectedWrites, $robotsInfo) { // Check that all $expectedWrites lines were written $actualData = []; $currentFile = ''; $streamWriteCallback = function ($str) use(&$actualData, &$currentFile) { if (!array_key_exists($currentFile, $actualData)) { $actualData[$currentFile] = ''; } $actualData[$currentFile] .= $str; }; // Check that all expected lines were written $this->_fileMock->expects($this->exactly($expectedWrites))->method('write')->will($this->returnCallback($streamWriteCallback)); // Check that all expected file descriptors were created $this->_directoryMock->expects($this->exactly(count($expectedFile)))->method('openFile')->will($this->returnCallback(function ($file) use(&$currentFile) { $currentFile = $file; })); // Check that all file descriptors were closed $this->_fileMock->expects($this->exactly(count($expectedFile)))->method('close'); if (count($expectedFile) == 1) { $this->_directoryMock->expects($this->once())->method('renameFile')->will($this->returnCallback(function ($from, $to) { \PHPUnit_Framework_Assert::assertEquals('/sitemap-1-1.xml', $from); \PHPUnit_Framework_Assert::assertEquals('/sitemap.xml', $to); })); } // Check robots txt $robotsStart = ''; if (isset($robotsInfo['robotsStart'])) { $robotsStart = $robotsInfo['robotsStart']; } $robotsFinish = 'Sitemap: http://store.com/sitemap.xml'; if (isset($robotsInfo['robotsFinish'])) { $robotsFinish = $robotsInfo['robotsFinish']; } $this->_directoryMock->expects($this->any())->method('readFile')->will($this->returnValue($robotsStart)); $this->_directoryMock->expects($this->any())->method('write')->with($this->equalTo('robots.txt'), $this->equalTo($robotsFinish)); // Mock helper methods $pushToRobots = 0; if (isset($robotsInfo['pushToRobots'])) { $pushToRobots = (int) $robotsInfo['pushToRobots']; } $this->_helperMockSitemap->expects($this->any())->method('getMaximumLinesNumber')->will($this->returnValue($maxLines)); $this->_helperMockSitemap->expects($this->any())->method('getMaximumFileSize')->will($this->returnValue($maxFileSize)); $this->_helperMockSitemap->expects($this->any())->method('getEnableSubmissionRobots')->will($this->returnValue($pushToRobots)); $model = $this->_getModelMock(true); return $model; }
protected function getModelMock() { $dbModelName = 'Magento\\Install\\Model\\Installer\\Db\\Mysql4'; $this->directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', [], [], '', false); $this->directoryMock->expects($this->once())->method('read')->will($this->returnValue([TESTS_TEMP_DIR])); $this->directoryMock->expects($this->any())->method('isDirectory')->will($this->returnValue(true)); $this->filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', [], [], '', false); $this->filesystemMock->expects($this->any())->method('getDirectoryWrite')->with()->will($this->returnValue($this->directoryMock)); /** * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */ $appStateMock = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false); $appStateMock->expects($this->any())->method('isInstalled')->will($this->returnValue(true)); $dbModelMock = $this->getMock($dbModelName, [], [], '', false); $dbModelMock->expects($this->any())->method('cleanUpDatabase')->will($this->returnValue($this)); /** * @var \Magento\Framework\ObjectManager|\PHPUnit_Framework_MockObject_MockObject */ $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->any())->method('get')->with($dbModelName)->will($this->returnValue($dbModelMock)); return new \Magento\Install\Model\Installer\Console($this->getMock('Magento\\Install\\Model\\Installer', [], [], '', false), $this->getMock('Magento\\Framework\\App\\Resource\\Config', [], [], '', false), $this->getMock('Magento\\Framework\\Module\\UpdaterInterface', [], [], '', false), $this->filesystemMock, $this->getMock('Magento\\Install\\Model\\Installer\\Data', [], [], '', false), $appStateMock, $this->getMock('Magento\\Framework\\Locale\\ListsInterface', [], [], '', false), $objectManagerMock); }
public function testClearNotExist() { $this->directoryWriteMock->expects($this->never())->method('delete'); $this->webLogger->clear(); }
/** * Test destination argument for the second getRelativePath after preg_replace. * * @depends testConstructorInternalCalls * @dataProvider constructorFileDestinationMatchDataProvider */ public function testConstructorFileDestinationMatch($fileName, $expectedfileName) { $this->directory->expects($this->at(0))->method('getRelativePath')->with($fileName); $this->directory->expects($this->at(1))->method('getRelativePath')->with($expectedfileName); $this->_invokeConstructor($fileName); }