/** * @param bool $cacheState * @param bool $varnishIsEnabled * @param bool $scopeIsPrivate * @param int|null $blockTtl * @param string $expectedOutput * @dataProvider processLayoutRenderDataProvider */ public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput) { $eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false); $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); $eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock)); $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState)); if ($cacheState) { $eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName')); $eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport)); $this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf()); $this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([])); $this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock)); if ($varnishIsEnabled) { $this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl)); $this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff')); } if ($scopeIsPrivate) { $this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName')); $this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate)); } $this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled)); } $this->_model->execute($this->_observerMock); $this->assertEquals($expectedOutput, $this->_transport['output']); }
public function testAfterExecuteInvalidate() { $subject = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass(); $result = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass(); $this->config->expects($this->once())->method('isEnabled')->willReturn(true); $this->typeList->expects($this->once())->method('invalidate')->with('full_page'); $this->assertEquals($result, $this->execute->afterExecute($subject, $result)); }
/** * @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); }
/** * @dataProvider invalidateCacheDataProvider * @param bool $cacheState */ public function testExecute($cacheState) { $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState)); if ($cacheState) { $this->_typeListMock->expects($this->once())->method('invalidate')->with($this->equalTo('full_page')); } $this->_model->execute($this->observerMock); }
/** * Test of adding design exceptions to the kay of cache hash * * @param string $cacheType * @param bool $isPageCacheEnabled * @param string|false $result * @param string $uaException * @param string $expected * @dataProvider testAfterGetValueDataProvider */ public function testAfterGetValue($cacheType, $isPageCacheEnabled, $result, $uaException, $expected) { $identifierMock = $this->getMock('Magento\\Framework\\App\\PageCache\\Identifier', [], [], '', false); $this->pageCacheConfigMock->expects($this->once())->method('getType')->will($this->returnValue($cacheType)); $this->pageCacheConfigMock->expects($this->any())->method('isEnabled')->will($this->returnValue($isPageCacheEnabled)); $this->designExceptionsMock->expects($this->any())->method('getThemeByRequest')->will($this->returnValue($uaException)); $this->assertEquals($expected, $this->plugin->afterGetValue($identifierMock, $result)); }
/** * @dataProvider invalidateCacheDataProvider * @param bool $cacheState */ public function testExecuteNoChanged($cacheState) { $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState)); $this->typeListMock->expects($this->never())->method('invalidate'); if ($cacheState) { $this->objectMock->expects($this->once())->method('getIdentities')->will($this->returnValue([])); } $this->model->execute($this->observerMock); }
public function testExportVarnishConfigAction() { $fileContent = 'some conetnt'; $filename = 'varnish.vcl'; $responseMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->disableOriginalConstructor()->getMock(); $this->configMock->expects($this->once())->method('getVclFile')->will($this->returnValue($fileContent)); $this->fileFactoryMock->expects($this->once())->method('create')->with($this->equalTo($filename), $this->equalTo($fileContent), $this->equalTo(DirectoryList::VAR_DIR))->will($this->returnValue($responseMock)); $result = $this->action->executeInternal(); $this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $result); }
/** * Test method afterGenerateXml */ public function testAfterGenerateXml() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->checkoutSessionMock->expects($this->once())->method('clearStorage')->will($this->returnValue($expectedResult)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
/** * @param array $requestResult * @param bool $moduleManagerResult * @param bool $cacheConfigResult * @param bool $layoutResult * @param bool $can Depersonalize * @dataProvider checkIfDepersonalizeDataProvider */ public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize) { $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']); $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']); $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']); $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false); $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult); $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock); $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock)); }
public function testAroundSave() { $subject = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Attribute')->disableOriginalConstructor()->getMock(); $attribute = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->disableOriginalConstructor()->getMock(); $self = $this; $proceed = function ($object) use($self, $attribute) { $self->assertEquals($object, $attribute); }; $this->config->expects($this->once())->method('isEnabled')->willReturn(true); $this->typeList->expects($this->once())->method('invalidate')->with('full_page'); $this->save->aroundSave($subject, $proceed, $attribute); }
public function testExecuteWithEmptyTags() { $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue(true)); $observerObject = $this->getMock('Magento\\Framework\\Event\\Observer'); $observedObject = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $tags = []; $eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false); $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($observedObject)); $observerObject->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)); $observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags)); $this->_cacheMock->expects($this->never())->method('clean'); $this->_model->execute($observerObject); }
/** * Run test afterGenerateXml method * * @param bool $result * * @dataProvider dataProviderAfterGenerateXml */ public function testAfterGenerateXml($result) { /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $subjectMock */ $subjectMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, ['isCacheable']); /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, []); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn($result); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($result); $this->requestMock->expects($this->any())->method('isAjax')->willReturn(!$result); $subjectMock->expects($this->any())->method('isCacheable')->willReturn($result); if ($result) { $this->persistentSessionMock->expects($this->once())->method('setCustomerId')->with(null); } else { $this->persistentSessionMock->expects($this->never())->method('setCustomerId')->with(null); } $this->assertEquals($resultMock, $this->plugin->afterGenerateXml($subjectMock, $resultMock)); }
/** * Test case for cache invalidation * * @dataProvider flushCacheByTagsDataProvider * @param $cacheState */ public function testExecute($cacheState) { $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState)); $observerObject = $this->getMock('Magento\\Framework\\Event\\Observer'); $observedObject = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); if ($cacheState) { $tags = ['cache_1', 'cache_group']; $expectedTags = ['cache_1', 'cache_group', 'cache']; $eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false); $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($observedObject)); $observerObject->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)); $observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags)); $this->_cacheMock->expects($this->once())->method('clean')->with($this->equalTo($expectedTags)); } $this->_model->execute($observerObject); }
public function testAfterAddressSave() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setIsPrimaryBilling(true); $address->setIsPrimaryShipping(true); $address->setCountryId(1); $address->setData('postcode', 11111); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->observerMock->expects($this->once())->method('getCustomerAddress')->willReturn($address); $this->session->afterAddressSave($this->observerMock); }
public function testAroundDispatch() { $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxBillingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('getCustomerTaxClassId')->willReturn(1); $this->taxCalculationMock->expects($this->once())->method('getTaxRates')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111], ['country_id' => 1, 'region_id' => null, 'postcode' => 11111], 1)->willReturn([]); $this->httpContextMock->expects($this->once())->method('setValue')->with('tax_rates', [], 0); $action = $this->objectManager->getObject('Magento\\Framework\\App\\Action\\Action'); $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundDispatch($action, $proceed, $request); }
public function testExecute() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->any())->method('isEnabled')->willReturn(true); $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock(); $this->observerMock->expects($this->once())->method('getData')->with('customer')->willReturn($customerMock); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setCountryId(1); $address->setPostCode(11111); $addresses = [$address]; $customerMock->expects($this->once())->method('getAddresses')->willReturn($addresses); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->session->execute($this->observerMock); }
public function testLayoutIsNotCacheable() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->willReturn(false); $this->layoutMock->expects($this->once())->method('isCacheable')->willReturn(false); $this->catalogSessionMock->expects($this->never())->method('clearStorage'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout); $this->assertEquals($this->resultLayout, $actualResult); }
/** * Test afterGenerateXml method with enabled module PageCache and request is Ajax and Layout is not cacheable */ public function testAfterGenerateXmlLayoutIsNotCacheable() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(false)); $this->visitorMock->expects($this->never())->method('setSkipRequestLogging'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
public function testAroundDispatchBasedOnShipping() { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->once())->method('getTaxBasedOn')->willReturn('shipping'); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn('US'); $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(0); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 'US', 'region_id' => 1]); $this->weeeTaxMock->expects($this->once())->method('isWeeeInLocation')->with('US', 1, 1)->willReturn(true); $this->httpContextMock->expects($this->once())->method('setValue')->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0); $action = $this->objectManager->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\Stub\\ActionStub'); $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundDispatch($action, $proceed, $request); }
/** * Test case for flushing all the cache */ public function testExecute() { $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)); $this->fullPageCacheMock->expects($this->once())->method('clean'); $this->_model->execute($this->observerMock); }