/**
  * Test aroundDispatch
  */
 public function testAroundDispatch()
 {
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(1));
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
     $this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock], [Context::CONTEXT_AUTH, 0, $this->httpContextMock]]));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemple #2
0
 protected function setUp()
 {
     $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->request->expects($this->at(0))->method('getParam')->with('store_id')->will($this->returnValue(null));
     $this->request->expects($this->at(1))->method('getParam')->with('cid')->will($this->returnValue(null));
     $this->httpContext = $this->getMockBuilder('Magento\\Framework\\App\\Http\\Context')->setMethods(['getValue'])->disableOriginalConstructor()->getMock();
     $this->httpContext->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $this->imageHelper = $this->getMock('Magento\\Catalog\\Helper\\Image', [], [], '', false);
     $this->outputHelper = $this->getMock('Magento\\Catalog\\Helper\\Output', ['productAttribute'], [], '', false);
     $this->msrpHelper = $this->getMock('Magento\\Msrp\\Helper\\Data', ['canApplyMsrp'], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->rssModel = $this->getMock('Magento\\Catalog\\Model\\Rss\\Product\\Special', [], [], '', false);
     $this->rssUrlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface');
     $this->storeManager = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface');
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->setMethods(['getId', 'getFrontendName', '__wakeup'])->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getId')->will($this->returnValue(1));
     $store->expects($this->any())->method('getFrontendName')->will($this->returnValue('Store 1'));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->scopeConfig = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('en_US'));
     $this->localeDate = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->dateFactory = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateFactory', ['create'], [], '', false);
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->block = $objectManagerHelper->getObject('Magento\\Catalog\\Block\\Rss\\Product\\Special', ['request' => $this->request, 'httpContext' => $this->httpContext, 'imageHelper' => $this->imageHelper, 'outputHelper' => $this->outputHelper, 'msrpHelper' => $this->msrpHelper, 'priceCurrency' => $this->priceCurrency, 'rssModel' => $this->rssModel, 'rssUrlBuilder' => $this->rssUrlBuilder, 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'localeDate' => $this->localeDate, 'dateFactory' => $this->dateFactory]);
 }
Exemple #3
0
 public function testSendVary()
 {
     $data = ['some-vary-key' => 'some-vary-value'];
     $expectedCookieName = Http::COOKIE_VARY_STRING;
     $expectedCookieValue = sha1(serialize($data));
     $publicCookieMetadataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
     $publicCookieMetadataMock->expects($this->once())->method('setPath')->with('/')->will($this->returnSelf());
     $this->contextMock->expects($this->once())->method('getData')->with()->will($this->returnValue($data));
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadataMock));
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with($expectedCookieName, $expectedCookieValue, $publicCookieMetadataMock);
     $this->model->sendVary();
 }
Exemple #4
0
 public function testAroundDispatchHasSortDirection()
 {
     $this->toolbarModelMock->expects($this->exactly(1))->method('getDirection')->will($this->returnValue('asc'));
     $this->toolbarModelMock->expects($this->once())->method('getOrder')->will($this->returnValue('Name'));
     $this->toolbarModelMock->expects($this->once())->method('getMode')->will($this->returnValue('list'));
     $this->toolbarModelMock->expects($this->once())->method('getLimit')->will($this->returnValue(array(1 => 1, 2 => 2)));
     $this->productListHelperMock->expects($this->once())->method('getDefaultSortField')->will($this->returnValue('Field'));
     $this->productListHelperMock->expects($this->exactly(2))->method('getDefaultViewMode')->will($this->returnValue('grid'));
     $this->productListHelperMock->expects($this->once())->method('getDefaultLimitPerPageValue')->will($this->returnValue(array(10 => 10)));
     $this->httpContextMock->expects($this->exactly(4))->method('setValue')->will($this->returnValueMap(array(array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_DIRECTION, 'asc', \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION, $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_ORDER, 'Name', 'Field', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_DISPLAY_MODE, 'list', 'grid', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_LIMIT, array(1 => 1, 2 => 2), array(10 => 10)))));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemple #5
0
 public function testGetCacheKeyInfo()
 {
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $store->expects($this->once())->method('getId')->willReturn(1);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->once())->method('getId')->willReturn('blank');
     $this->design->expects($this->once())->method('getDesignTheme')->willReturn($theme);
     $this->httpContext->expects($this->once())->method('getValue')->willReturn('context_group');
     $this->productsList->setData('conditions', 'some_serialized_conditions');
     $this->request->expects($this->once())->method('getParam')->with('np')->willReturn(1);
     $cacheKey = ['CATALOG_PRODUCTS_LIST_WIDGET', 1, 'blank', 'context_group', 1, 5, 'some_serialized_conditions'];
     $this->assertEquals($cacheKey, $this->productsList->getCacheKeyInfo());
 }
 public function testGetCacheKeyInfo()
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->atLeastOnce())->method('getId')->willReturn(55);
     $store->expects($this->atLeastOnce())->method('getRootCategoryId')->willReturn(60);
     $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->atLeastOnce())->method('getId')->willReturn(65);
     $this->design->expects($this->atLeastOnce())->method('getDesignTheme')->willReturn($theme);
     $this->httpContext->expects($this->atLeastOnce())->method('getValue')->with(\Magento\Customer\Model\Context::CONTEXT_GROUP)->willReturn(70);
     $this->block->setTemplate('block_template');
     $this->block->setNameInLayout('block_name');
     $expectedResult = ['CATALOG_NAVIGATION', 55, 65, 70, 'template' => 'block_template', 'name' => 'block_name', 60, 'category_path' => 60, 'short_cache_id' => 'c3de6d1160d1e7730b04d6cad409a2b4'];
     $this->assertEquals($expectedResult, $this->block->getCacheKeyInfo());
 }
 public function testDispatchCurrentStoreCurrency()
 {
     $this->httpContextMock->expects($this->at(0))->method('setValue')->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
     /** Make sure that current currency is taken from current store if no value is provided in session */
     $this->httpContextMock->expects($this->at(1))->method('setValue')->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT);
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemple #8
0
 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);
 }
 /**
  * Test aroundDispatch
  */
 public function testAroundDispatch()
 {
     $this->storeManagerMock->expects($this->exactly(2))->method('getWebsite')->will($this->returnValue($this->websiteMock));
     $this->websiteMock->expects($this->exactly(2))->method('getDefaultStore')->will($this->returnValue($this->storeMock));
     $this->storeMock->expects($this->once())->method('getDefaultCurrency')->will($this->returnValue($this->currencyMock));
     $this->storeMock->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
     $this->currencyMock->expects($this->once())->method('getCode')->will($this->returnValue('UAH'));
     $this->sessionMock->expects($this->once())->method('getCurrencyCode')->will($this->returnValue('UAH'));
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
     $this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[\Magento\Core\Helper\Data::CONTEXT_CURRENCY, 'UAH', 'UAH', $this->httpContextMock], [\Magento\Core\Helper\Data::CONTEXT_STORE, 'default', 'default', $this->httpContextMock]]));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemple #10
0
 /**
  * Test setting public cache headers
  */
 public function testSetNoCacheHeaders()
 {
     $timestamp = 1000000;
     $pragma = 'no-cache';
     $cacheControl = 'max-age=0, must-revalidate, no-cache, no-store';
     $expiresResult = 'Thu, 01 Jan 1970 00:00:00 GMT';
     $this->dateTimeMock->expects($this->once())->method('strToTime')->with('-1 year')->willReturn($timestamp);
     $this->dateTimeMock->expects($this->once())->method('gmDate')->with(Http::EXPIRATION_TIMESTAMP_FORMAT, $timestamp)->willReturn($expiresResult);
     $this->model->setNoCacheHeaders();
     $this->assertEquals($pragma, $this->model->getHeader('Pragma')->getFieldValue());
     $this->assertEquals($cacheControl, $this->model->getHeader('Cache-Control')->getFieldValue());
     $this->assertEquals($expiresResult, $this->model->getHeader('Expires')->getFieldValue());
 }
 public function testDispatchStoreParameterIsArray()
 {
     $this->storeMock->expects($this->once())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_DEFAULT));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('default');
     $this->currentStoreMock->expects($this->once())->method('getCode')->willReturn('custom_store');
     $store = ['_data' => ['code' => 500]];
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue($store));
     $this->storeManager->expects($this->once())->method('getStore')->with('500')->willReturn($this->currentStoreMock);
     $this->httpContextMock->expects($this->at(0))->method('setValue')->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
     /** Make sure that current currency is taken from current store if no value is provided in session */
     $this->httpContextMock->expects($this->at(1))->method('setValue')->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT);
     $result = $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock);
     $this->assertEquals('ExpectedValue', $result);
 }
Exemple #12
0
 public function testInitOrders()
 {
     $customerId = 25;
     $attribute = ['customer_id', 'status'];
     $this->httpContext->expects($this->once())->method('getValue')->with($this->equalTo(Context::CONTEXT_AUTH))->will($this->returnValue(true));
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $statuses = ['pending', 'processing', 'complete'];
     $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses));
     $this->orderCollection->expects($this->at(0))->method('addAttributeToFilter')->with($attribute[0], $this->equalTo($customerId))->will($this->returnSelf());
     $this->orderCollection->expects($this->at(1))->method('addAttributeToFilter')->with($attribute[1], $this->equalTo(['in' => $statuses]))->will($this->returnSelf());
     $this->orderCollection->expects($this->at(2))->method('addAttributeToSort')->with('created_at', 'desc')->will($this->returnSelf());
     $this->orderCollection->expects($this->at(3))->method('setPage')->with($this->equalTo(1), $this->equalTo(1))->will($this->returnSelf());
     $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->orderCollection));
     $this->createBlockObject();
     $this->assertEquals($this->orderCollection, $this->block->getOrders());
 }
 /**
  * @covers \Magento\Store\Model\StorageFactory::_checkRequestStore
  * @covers \Magento\Store\Model\StorageFactory::getActiveStoreByCode
  * @covers \Magento\Store\Model\StorageFactory::setCurrentStore
  *
  * @dataProvider getFromRequestDataProvider
  *
  * @param bool $isActiveStore
  * @param bool $isDefault
  */
 public function testGetFromRequest($isActiveStore, $isDefault)
 {
     $this->_appStateMock->expects($this->once())->method('isInstalled')->will($this->returnValue(true));
     $storeDefault = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false);
     if (!$isDefault) {
         $storeDefault->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(22));
         $this->_httpContext->expects($this->once())->method('setValue')->with(\Magento\Store\Model\Store::ENTITY, 'store1', \Magento\Store\Model\Store::DEFAULT_CODE)->will($this->returnSelf());
     }
     $this->website->expects($this->any())->method('getDefaultStore')->will($this->returnValue(!$isDefault ? $storeDefault : $this->store));
     $this->website->expects($this->atLeastOnce())->method('getDefaultGroupId')->will($this->returnValue(11));
     $this->group->expects($this->any())->method('getDefaultStoreId')->will($this->returnValue(21));
     $this->store->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(21));
     $this->store->expects($this->once())->method('getIsActive')->will($this->returnValue($isActiveStore));
     $this->store->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->storage->expects($this->any())->method('setCurrentStore')->with('store1');
     $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($this->storage));
     $this->request->expects($this->atLeastOnce())->method('getParam')->with('___store')->will($this->returnValue('store1'));
     $this->assertEquals($this->storage, $this->_model->get($this->_arguments));
 }
Exemple #14
0
 /**
  * @covers \Magento\Store\Model\StorageFactory::_checkRequestStore
  * @covers \Magento\Store\Model\StorageFactory::getActiveStoreByCode
  * @covers \Magento\Store\Model\StorageFactory::setCurrentStore
  *
  * @dataProvider getFromRequestDataProvider
  *
  * @param bool $isActiveStore
  * @param bool $isDefault
  */
 public function testGetFromRequest($isActiveStore, $isDefault)
 {
     $this->_appStateMock->expects($this->once())->method('isInstalled')->will($this->returnValue(true));
     $storeDefault = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     if (!$isDefault) {
         $storeDefault->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(22));
         $this->_httpContext->expects($this->once())->method('setValue')->with(\Magento\Store\Model\Store::ENTITY, 'store1', \Magento\Store\Model\Store::DEFAULT_CODE)->will($this->returnSelf());
     }
     $this->website->expects($this->any())->method('getDefaultStore')->will($this->returnValue(!$isDefault ? $storeDefault : $this->store));
     $this->website->expects($this->atLeastOnce())->method('getDefaultGroupId')->will($this->returnValue(11));
     $this->group->expects($this->any())->method('getDefaultStoreId')->will($this->returnValue(21));
     $this->store->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(21));
     $this->store->expects($this->once())->method('getIsActive')->will($this->returnValue($isActiveStore));
     $this->store->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->storage->expects($this->any())->method('setCurrentStore')->with('store1');
     $numCreateCookieCalls = $isDefault ? 0 : 1;
     $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($this->storage));
     $cookieMetadata = $this->helper->getObject('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata', []);
     $this->cookieMetadataFactoryMock->expects($this->exactly($numCreateCookieCalls))->method('createPublicCookieMetadata')->will($this->returnValue($cookieMetadata));
     $this->request->expects($this->atLeastOnce())->method('getParam')->with('___store')->will($this->returnValue('store1'));
     $this->assertEquals($this->storage, $this->_model->get($this->_arguments));
 }
 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);
 }
 /**
  * @param $cookieExists
  *
  * @dataProvider trueFalseDataProvider
  */
 public function testVaryStringSource($cookieExists)
 {
     $this->requestMock->method('get')->willReturn($cookieExists ? 'vary-string-from-cookie' : null);
     $this->contextMock->expects($cookieExists ? $this->never() : $this->once())->method('getVaryString');
     $this->model->getValue();
 }