protected function configureAdminArea()
 {
     $config = ['test config'];
     $this->configLoaderMock->expects($this->once())->method('load')->with(FrontNameResolver::AREA_CODE)->will($this->returnValue($config));
     $this->objectManager->expects($this->once())->method('configure')->with($config);
     $this->stateMock->expects($this->once())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
 }
 /**
  * @return void
  */
 public function testWidgetDirective()
 {
     $result = 'some text';
     $construction = ['{{widget type="Widget\\Link" anchor_text="Test" template="block.phtml" id_path="p/1"}}', 'widget', ' type="" anchor_text="Test" template="block.phtml" id_path="p/1"'];
     $this->appStateMock->expects($this->once())->method('emulateAreaCode')->with('frontend', [$this->filterEmulate, 'generateWidget'], [$construction])->willReturn($result);
     $this->assertSame($result, $this->filterEmulate->widgetDirective($construction));
 }
예제 #3
0
 public function testNotUnlockProcessInProductionMode()
 {
     $this->stateMock->expects(self::exactly(2))->method('getMode')->willReturn(State::MODE_PRODUCTION);
     $this->filesystemMock->expects(self::never())->method('getDirectoryWrite');
     $this->lockerProcess->lockProcess(self::LOCK_NAME);
     $this->lockerProcess->unlockProcess();
 }
 /**
  * @dataProvider dataProvider
  */
 public function testAroundDispatchDisabled($state)
 {
     $this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null));
     $this->versionMock->expects($this->never())->method('process');
     $this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state));
     $this->responseMock->expects($this->never())->method('setHeader');
     $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock);
 }
예제 #5
0
 protected function setUp()
 {
     $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getBasePath', 'isSecure', 'getHttpHost'], [], '', false, false);
     $this->requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/'));
     $this->requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host'));
     $this->appState = $this->getMock('\\Magento\\Framework\\App\\State', ['isInstalled'], [], '', false, false);
     $this->appState->expects($this->atLeastOnce())->method('isInstalled')->will($this->returnValue(true));
 }
예제 #6
0
 public function testBeforeExecuteWithProductionMode()
 {
     $this->appState->expects($this->once())->method('getMode')->willReturn('production');
     $this->themeRegistration->expects($this->never())->method('register');
     $this->logger->expects($this->never())->method('critical');
     $object = new Registration($this->themeRegistration, $this->logger, $this->appState);
     $object->beforeExecute($this->abstractAction, $this->request);
 }
예제 #7
0
 public function testPublish()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
     $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
     $this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
     $this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true));
     $this->assertTrue($this->object->publish($this->getAsset()));
 }
예제 #8
0
 /**
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $loggerExpects
  * @param string $stateMode
  * @return void
  * @dataProvider reorderChildElementLogDataProvider
  */
 public function testReorderChildElementLog($loggerExpects, $stateMode)
 {
     $parentName = 'parent';
     $childName = 'child';
     $offsetOrSibling = '-';
     $this->stateMock->expects($this->once())->method('getMode')->willReturn($stateMode);
     $this->loggerMock->expects($loggerExpects)->method('critical')->with("Broken reference: the '{$childName}' tries to reorder itself towards '', but " . "their parents are different: '{$parentName}' and '' respectively.");
     $this->dataStructure->reorderChildElement($parentName, $childName, $offsetOrSibling);
 }
예제 #9
0
 public function testCreateRequireJsAssetDevMode()
 {
     $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->createRequireJsAsset());
 }
 public function testLoad()
 {
     $area = $this->getMock('Magento\\Framework\\App\\Area', [], [], '', false);
     $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('area'));
     $this->_areaListMock->expects($this->once())->method('getArea')->with('area')->will($this->returnValue($area));
     $area->expects($this->at(0))->method('load')->with(\Magento\Framework\App\Area::PART_DESIGN)->will($this->returnValue($area));
     $area->expects($this->at(1))->method('load')->with(\Magento\Framework\App\Area::PART_TRANSLATE)->will($this->returnValue($area));
     $this->_model->load($this->_requestMock);
 }
 public function testGetFileIfMinificationIsDisabled()
 {
     $this->assetConfig->expects($this->once())->method('isMinifyHtml')->willReturn(false);
     $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $expected = 'some/file.ext';
     $this->resolver->expects($this->once())->method('resolve')->with(RulePool::TYPE_TEMPLATE_FILE, 'file.ext', 'frontend', $theme, null, 'Magento_Module')->will($this->returnValue($expected));
     $this->state->expects($this->never())->method('getMode');
     $actual = $this->object->getFile('frontend', $theme, 'file.ext', 'Magento_Module');
     $this->assertSame($expected, $actual);
 }
예제 #12
0
 public function testToHtmlWithSubscriber()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['id', null, 2], ['store', null, 1], ['subscriber', null, 3]]);
     $subscriber = $this->getMock('Magento\\Newsletter\\Model\\Subscriber', [], [], '', false);
     $subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf();
     $this->subscriberFactory->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);
     $this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
     $this->template->expects($this->atLeastOnce())->method('revertDesign');
     $this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')->with(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, [$this->template, 'getProcessedTemplate'], [['subscriber' => $subscriber]])->willReturn('Processed Template');
     $this->assertEquals('Processed Template', $this->preview->toHtml());
 }
예제 #13
0
 public function testGetByAreaWithOtherAreaAndNumericThemeId()
 {
     $this->designMock->expects($this->once())->method('getDesignTheme')->will($this->returnValue($this->themeMock));
     $this->designMock->expects($this->once())->method('getArea')->will($this->returnValue('design_area'));
     $this->designMock->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue(12));
     $this->themeMock->expects($this->once())->method('getArea')->will($this->returnValue('theme_area'));
     $this->themeCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->themeCollectionMock));
     $this->themeCollectionMock->expects($this->once())->method('getItemById')->with(12)->will($this->returnValue($this->themeMock));
     $this->appStateMock->expects($this->once())->method('getAreaCode')->will($this->returnValue('other_area'));
     $this->assertEquals($this->themeMock, $this->model->get());
 }
예제 #14
0
 public function testAroundResultWithPluginDeveloperMode()
 {
     $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true);
     $this->state->expects($this->once())->method('getMode')->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER);
     $this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2');
     $this->response->expects($this->any())->method('setHeader')->withConsecutive(['X-Magento-Cache-Control', 'test'], ['X-Magento-Cache-Debug', 'MISS', true], ['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]);
     $this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags');
     $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->will($this->returnValue(true));
     $this->kernel->expects($this->once())->method('process')->with($this->response);
     $result = call_user_func($this->closure);
     $this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response));
 }
예제 #15
0
 protected function setUp()
 {
     $this->_configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->_stringHelperMock = $this->getMock('\\Magento\\Framework\\Stdlib\\String', array(), array(), '', false, false);
     $this->_requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', array('getBasePath', 'isSecure', 'getHttpHost'), array(), '', false, false);
     $this->_requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/'));
     $this->_requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host'));
     $this->_appState = $this->getMock('\\Magento\\Framework\\App\\State', array('isInstalled'), array(), '', false, false);
     $this->_appState->expects($this->atLeastOnce())->method('isInstalled')->will($this->returnValue(true));
     $this->_filesystem = $this->getMock('\\Magento\\Framework\\App\\Filesystem', array(), array(), '', false, false);
     $this->config = new \Magento\Framework\Session\Config($this->_configMock, $this->_stringHelperMock, $this->_requestMock, $this->_appState, $this->_filesystem, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER, __DIR__);
 }
예제 #16
0
 public function testLaunchDispatchesCronEvent()
 {
     $configLoader = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
     $eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\ObjectManager\\ConfigLoaderInterface', $configLoader], ['Magento\\Framework\\Event\\ManagerInterface', $eventManagerMock]]));
     $crontabConfig = ['config'];
     $configLoader->expects($this->once())->method('load')->with(Area::AREA_CRONTAB)->willReturn($crontabConfig);
     $this->objectManager->expects($this->once())->method('configure')->with($crontabConfig);
     $this->_stateMock->expects($this->once())->method('setAreaCode')->with(Area::AREA_CRONTAB);
     $eventManagerMock->expects($this->once())->method('dispatch')->with('default');
     $this->_responseMock->expects($this->once())->method('setCode')->with(0);
     $this->assertEquals($this->_responseMock, $this->_model->launch());
 }
예제 #17
0
 public function testWidgetDirective()
 {
     $subscriber = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', [], [], '', false);
     $this->filter->setVariables(['subscriber' => $subscriber]);
     $construction = '{{widget type="\\Magento\\Cms\\Block\\Widget\\Page\\Link" page_id="1"}}';
     $store = $this->getMockForAbstractClass('Magento\\Store\\Api\\Data\\StoreInterface', [], '', false);
     $store->expects($this->once())->method('getId')->willReturn(1);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $this->appState->expects($this->once())->method('emulateAreaCode')->with('frontend', [$this->filter, 'generateWidget'], [[1 => $construction, 2 => 'type="\\Magento\\Cms\\Block\\Widget\\Page\\Link" page_id="1" store_id ="1"']])->willReturn('<div class="widget block block-cms-link-inline">
                 <a href="http://magento.test/">
                     <span>Home page</span>
                 </a>
             </div>');
     $this->filter->widgetDirective([1 => $construction, 2 => 'type="\\Magento\\Cms\\Block\\Widget\\Page\\Link" page_id="1"']);
 }
 /**
  * @return void
  */
 public function testGetData()
 {
     $themePath = 'blank';
     $areaCode = 'adminhtml';
     $files = [['path1'], ['path2']];
     $relativePathMap = [['path1' => 'relativePath1'], ['path2' => 'relativePath2']];
     $contentsMap = [['relativePath1' => 'content1$.mage.__("hello1")content1'], ['relativePath2' => 'content2$.mage.__("hello2")content2']];
     $patterns = ['~\\$\\.mage\\.__\\([\'|\\"](.+?)[\'|\\"]\\)~'];
     $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->filesUtilityMock->expects($this->once())->method('getJsFiles')->with($areaCode, $themePath)->willReturn($files);
     $this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnMap($relativePathMap);
     $this->rootDirectoryMock->expects($this->any())->method('readFile')->willReturnMap($contentsMap);
     $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
     $this->assertEquals([], $this->model->getData($themePath));
 }
예제 #19
0
    /**
     * Test handling exception during dispatch.
     */
    public function testDispatchWithException()
    {
        $this->_appStateMock->expects($this->any())->method('isInstalled')->will($this->returnValue(true));
        $exceptionMessage = 'some error message';
        $exception = new \Magento\Webapi\Exception($exceptionMessage);
        $this->_soapServerMock->expects($this->any())->method('handle')->will($this->throwException($exception));
        $this->_errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnValue($exception));
        $encoding = "utf-8";
        $this->_soapServerMock->expects($this->any())->method('getApiCharset')->will($this->returnValue($encoding));
        $this->_soapController->dispatch($this->_requestMock);
        $expectedMessage = <<<EXPECTED_MESSAGE
<?xml version="1.0" encoding="{$encoding}"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" >
   <env:Body>
      <env:Fault>
         <env:Code>
            <env:Value>env:Sender</env:Value>
         </env:Code>
         <env:Reason>
            <env:Text xml:lang="en">some error message</env:Text>
         </env:Reason>
      </env:Fault>
   </env:Body>
</env:Envelope>
EXPECTED_MESSAGE;
        $this->assertXmlStringEqualsXmlString($expectedMessage, $this->_responseMock->getBody());
    }
예제 #20
0
 public function testRobotsAdminhtml()
 {
     $this->areaResolverMock->expects($this->once())->method('getAreaCode')->willReturn('adminhtml');
     $robots = 'test_robots';
     $this->model->setRobots($robots);
     $this->assertEquals('NOINDEX,NOFOLLOW', $this->model->getRobots());
 }
 public function testBeforeDispatch()
 {
     $customerId = 1;
     $customerGroupId = 1;
     $this->appState->expects($this->any())->method('getAreaCode')->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
     $this->request->expects($this->any())->method('isPost')->willReturn(true);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
     $this->customerRepository->expects($this->any())->method('getById')->with($customerId)->willReturn($customerMock);
     $this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
     $this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
     $this->session->expects($this->once())->method('regenerateId');
     $this->notificationStorage->expects($this->any())->method('isExists')->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)->willReturn(true);
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }
예제 #22
0
 public function testBreakAfter()
 {
     $areaCode = 'frontend';
     $breakAfter = 5;
     $this->deploymentConfig->expects($this->once())->method('get')->with(Config::PARAM_BREAK_AFTER . '_' . $areaCode)->willReturn($breakAfter);
     $this->appState->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->assertEquals($this->config->getBreakAfter(), $breakAfter);
 }
예제 #23
0
 public function testGetLifetimeFrontend()
 {
     $areaCode = 'frontend';
     $expectedLifetime = 234;
     $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with(Config::XML_PATH_COOKIE_LIFETIME, ScopeInterface::SCOPE_STORE)->willReturn($expectedLifetime);
     $this->assertEquals($this->config->getLifetime(), $expectedLifetime);
 }
예제 #24
0
 /**
  * @test
  * @return void
  */
 public function getFullThemePath()
 {
     $areaCode = 'frontend';
     $this->appState->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $path = 'some/path';
     $this->_model->setThemePath($path);
     $this->assertEquals($areaCode . Theme::PATH_SEPARATOR . $path, $this->_model->getFullPath());
 }
예제 #25
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_appStateMock->expects($this->any())->method('isInstalled')->will($this->returnValue(true));
     $this->_authzServiceMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
예제 #26
0
 public function testLoadDataNoTheme()
 {
     $forceReload = true;
     $this->expectsSetConfig(null, null);
     $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue([]));
     $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('frontend'));
     $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue([]));
     $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue([]));
     $this->assertEquals($this->translate, $this->translate->loadData(null, $forceReload));
 }
예제 #27
0
 /**
  * Test for setting error handler and printing
  *
  * @covers \Magento\Framework\Error\Handler::handler
  * @expectedException \Exception
  * @throws \Exception
  */
 public function testErrorHandlerPrint()
 {
     $this->appState->expects($this->any())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     set_error_handler(array($this->handler, 'handler'));
     try {
         trigger_error('testErrorHandlerPrint', E_USER_NOTICE);
     } catch (\Exception $e) {
         restore_error_handler();
         throw $e;
     }
 }
예제 #28
0
 /**
  * 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))));
 }
예제 #29
0
 public function testFinish()
 {
     $cacheTypeListArray = array('one', 'two');
     $this->_cache->expects($this->once())->method('clean');
     $this->_config->expects($this->once())->method('reinit');
     $this->_cacheState->expects($this->once())->method('persist');
     $this->_cacheState->expects($this->exactly(count($cacheTypeListArray)))->method('setEnabled');
     $this->_cacheTypeList->expects($this->once())->method('getTypes')->will($this->returnValue($cacheTypeListArray));
     $this->_appState->expects($this->once())->method('setInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->_installerConfig->expects($this->once())->method('replaceTmpInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->assertSame($this->_model, $this->_model->finish());
 }
 /**
  * @return void
  */
 public function testGetData()
 {
     $themePath = 'blank';
     $areaCode = 'adminhtml';
     $filePaths = [['path1'], ['path2'], ['path3'], ['path4']];
     $jsFilesMap = [['base', $themePath, '*', '*', [$filePaths[0]]], [$areaCode, $themePath, '*', '*', [$filePaths[1]]]];
     $staticFilesMap = [['base', $themePath, '*', '*', [$filePaths[2]]], [$areaCode, $themePath, '*', '*', [$filePaths[3]]]];
     $expectedResult = ['hello1' => 'hello1translated', 'hello2' => 'hello2translated', 'hello3' => 'hello3translated', 'hello4' => 'hello4translated'];
     $contentsMap = ['content1$.mage.__("hello1")content1', 'content2$.mage.__("hello2")content2', 'content2$.mage.__("hello3")content3', 'content2$.mage.__("hello4")content4'];
     $translateMap = [[['hello1'], [], 'hello1translated'], [['hello2'], [], 'hello2translated'], [['hello3'], [], 'hello3translated'], [['hello4'], [], 'hello4translated']];
     $patterns = ['~\\$\\.mage\\.__\\(([\'"])(.+?)\\1\\)~'];
     $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->filesUtilityMock->expects($this->any())->method('getJsFiles')->willReturnMap($jsFilesMap);
     $this->filesUtilityMock->expects($this->any())->method('getStaticHtmlFiles')->willReturnMap($staticFilesMap);
     foreach ($contentsMap as $index => $content) {
         $this->fileReadMock->expects($this->at($index))->method('readAll')->willReturn($content);
     }
     $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
     $this->translateMock->expects($this->any())->method('render')->willReturnMap($translateMap);
     $this->assertEquals($expectedResult, $this->model->getData($themePath));
 }