/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $mockName = 'Test Product Name'; $mockVersion = '0.0.0'; $mockEdition = 'Test Edition'; $mockUrl = 'http://test-url'; $this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName); $this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion); $this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition); $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl); $configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl]; $lastUpdate = 0; $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf(); $this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
public function testGetStoreLabelsByAttributeIdWithCacheSave() { $attributeId = 1; $cacheId = \Magento\Eav\Plugin\Model\ResourceModel\Entity\Attribute::STORE_LABEL_ATTRIBUTE . $attributeId; $this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false); $this->cache->expects($this->any())->method('save')->with(serialize([$attributeId]), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]); $this->assertEquals([$attributeId], $this->getAttribute(true)->aroundGetStoreLabelsByAttributeId($this->subject, $this->mockPluginProceed([$attributeId]), $attributeId)); }
public function testCleanType() { $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will($this->returnValue(serialize($this->_typesArray))); $this->_config->expects($this->once())->method('getType')->with(self::TYPE_KEY)->will($this->returnValue(['instance' => self::CACHE_TYPE])); unset($this->_typesArray[self::TYPE_KEY]); $this->_cache->expects($this->once())->method('save')->with(serialize($this->_typesArray), TypeList::INVALIDATED_TYPES); $this->_typeList->cleanType(self::TYPE_KEY); }
/** * Test afterUpdateMview * * @return void */ public function testAfterUpdateMview() { $tags = ['tag_name1', 'tag_name2']; $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock])); $this->contextMock->expects($this->atLeastOnce())->method('getIdentities')->willReturn($tags); $this->cacheMock->expects($this->once())->method('clean')->with($tags); $this->plugin->afterUpdateMview($this->subjectMock); }
public function testGetFeedsWithCache() { $dataProvider = $this->getMock('Magento\\Framework\\App\\Rss\\DataProviderInterface'); $dataProvider->expects($this->any())->method('getCacheKey')->will($this->returnValue('cache_key')); $dataProvider->expects($this->any())->method('getCacheLifetime')->will($this->returnValue(100)); $dataProvider->expects($this->never())->method('getRssData'); $this->rss->setDataProvider($dataProvider); $this->cacheInterface->expects($this->once())->method('load')->will($this->returnValue(serialize($this->feedData))); $this->cacheInterface->expects($this->never())->method('save'); $this->assertEquals($this->feedData, $this->rss->getFeeds()); }
public function testExecuteRandom() { $newKey = 'RSASHA9000VERYSECURESUPERMANKEY'; $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1); $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey); $this->managerMock->expects($this->once())->method('addSuccessMessage'); $this->managerMock->expects($this->once())->method('addNoticeMessage'); $this->cacheMock->expects($this->once())->method('clean'); $this->responseMock->expects($this->once())->method('setRedirect'); $this->model->execute(); }
public function testGetAttributesUsedForSortByWithCacheSave() { $entityTypeId = 'type'; $storeId = 'store'; $attributes = ['attributes']; $this->subject->expects($this->any())->method('getEntityTypeId')->willReturn($entityTypeId); $this->subject->expects($this->any())->method('getStoreId')->willReturn($storeId); $cacheId = \Magento\Catalog\Plugin\Model\ResourceModel\Config::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $entityTypeId . '_' . $storeId; $this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false); $this->cache->expects($this->any())->method('save')->with(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]); $this->assertEquals($attributes, $this->getConfig(true)->aroundGetAttributesUsedForSortBy($this->subject, $this->mockPluginProceed($attributes))); }
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()); }
/** * Run test toHtml method * * @param bool $customerId * @return void * * @dataProvider dataProviderToHtml */ public function testToHtml($customerId) { $cacheData = false; $idQueryParam = 'id-query-param'; $sessionId = 'session-id'; $this->additional->setData('cache_lifetime', 789); $this->additional->setData('cache_key', 'cache-key'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false); // get cache $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true); // save cache $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false); $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData); $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam); $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId); // call protected _toHtml method $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false); $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock); $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId); if ($customerId) { $this->assertEquals('<span><a >Not you?</a></span>', $this->additional->toHtml()); } else { $this->assertEquals('', $this->additional->toHtml()); } }
/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $lastUpdate = 1410121748; $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->any())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->deploymentConfig->expects($this->once())->method('get')->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * @test * @return void * @covers \Magento\Theme\Model\Design::loadChange * @covers \Magento\Theme\Model\Design::__construct * @covers \Magento\Theme\Model\Design::_construct */ public function testLoadChangeFromCache() { $storeId = 1; $localDate = '2\\28\\2000'; $date = '28-02-2000'; $cacheId = 'design_change_' . md5($storeId . $date); $this->localeDate->expects($this->once())->method('scopeTimeStamp')->with($storeId)->willReturn($localDate); $this->dateTime->expects($this->once())->method('formatDate')->with($localDate, false)->willReturn($date); $this->cacheManager->expects($this->once())->method('load')->with($cacheId)->willReturn(serialize(['test' => 'data'])); $this->assertInstanceOf(get_class($this->model), $this->model->loadChange($storeId)); }
public function testSave() { $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock); $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(1); $this->quoteMock->expects($this->once())->method('getIsVirtual')->willReturn(false); $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock); $this->messageMock->expects($this->any())->method('setCustomerId'); $this->messageMock->expects($this->any())->method('setGiftMessageId'); $this->cacheMock->expects($this->once())->method('save'); $this->assertTrue($this->cartRepository->save($this->cartId, $this->messageMock)); }
public function testSave() { $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock); $this->quoteItemMock->expects($this->once())->method('getItemId')->willReturn($this->itemId); $this->quoteItemMock->expects($this->once())->method('getProductType')->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock); $this->messageMock->expects($this->any())->method('setCustomerId'); $this->messageMock->expects($this->any())->method('setGiftMessageId'); $this->cacheMock->expects($this->once())->method('save'); $this->assertTrue($this->itemRepository->save($this->cartId, $this->messageMock, $this->itemId)); }
public function testClear() { $this->cacheMock->expects($this->once())->method('clean')->with($this->equalTo([\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG])); $this->config->clear(); }