Beispiel #1
0
 /**
  * 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));
 }
 /**
  * @dataProvider getStoreValuesForFormDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function testGetStoreValuesForForm($empty, $all, $storeId, $groupId, $websiteId, $storeName, $groupName, $websiteName, $storeGroupId, $groupWebsiteId, $expectedResult)
 {
     $this->websiteMock->expects($this->any())->method('getId')->willReturn($websiteId);
     $this->websiteMock->expects($this->any())->method('getName')->willReturn($websiteName);
     $this->groupMock->expects($this->any())->method('getId')->willReturn($groupId);
     $this->groupMock->expects($this->any())->method('getName')->willReturn($groupName);
     $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn($groupWebsiteId);
     $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId);
     $this->storeMock->expects($this->any())->method('getName')->willReturn($storeName);
     $this->storeMock->expects($this->any())->method('getGroupId')->willReturn($storeGroupId);
     $this->model->setIsAdminScopeAllowed(true);
     $this->assertEquals($this->model->getStoreValuesForForm($empty, $all), $expectedResult);
 }
 /**
  * Set up
  */
 public function setUp()
 {
     $this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['getCurrencyCode'], [], '', false);
     $this->httpContextMock = $this->getMock('Magento\\Framework\\App\\Http\\Context', [], [], '', false);
     $this->httpRequestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeCookieManager = $this->getMock('Magento\\Store\\Api\\StoreCookieManagerInterface');
     $this->storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->currentStoreMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getDefaultStore', '__wakeup'], [], '', false);
     $this->closureMock = function () {
         return 'ExpectedValue';
     };
     $this->subjectMock = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $this->requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->plugin = (new ObjectManager($this))->getObject('Magento\\Store\\App\\Action\\Plugin\\Context', ['session' => $this->sessionMock, 'httpContext' => $this->httpContextMock, 'httpRequest' => $this->httpRequestMock, 'storeManager' => $this->storeManager, 'storeCookieManager' => $this->storeCookieManager]);
     $this->storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($this->websiteMock));
     $this->storeManager->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeManager->method('getStore')->willReturn($this->currentStoreMock);
     $this->websiteMock->expects($this->once())->method('getDefaultStore')->will($this->returnValue($this->storeMock));
     $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');
     $this->storeCookieManager->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
     $this->currentStoreMock->expects($this->any())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
 }
Beispiel #4
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSendPasswordResetConfirmationEmail()
 {
     $storeId = 1;
     $storeIds = array(1);
     $email = '*****@*****.**';
     $firstName = 'Foo';
     $lastName = 'Bar';
     $this->_model->setStoreId(0);
     $this->_model->setWebsiteId(1);
     $this->_model->setEmail($email);
     $this->_model->setFirstname($firstName);
     $this->_model->setLastname($lastName);
     $this->_config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->_attribute));
     $this->_attribute->expects($this->any())->method('isVisible')->will($this->returnValue(false));
     $this->_storeManager->expects($this->once())->method('getWebsite')->with($this->equalTo(1))->will($this->returnValue($this->_website));
     $this->_storeManager->expects($this->once())->method('getStore')->with(0)->will($this->returnValue($this->_storetMock));
     $this->_website->expects($this->once())->method('getStoreIds')->will($this->returnValue($storeIds));
     $this->_scopeConfigMock->expects($this->at(0))->method('getValue')->with(\Magento\Customer\Model\Customer::XML_PATH_RESET_PASSWORD_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('templateId'));
     $this->_scopeConfigMock->expects($this->at(1))->method('getValue')->with(\Magento\Customer\Model\Customer::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('sender'));
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(array('customer' => $this->_model, 'store' => $this->_storetMock))->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('addTo')->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName))->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setFrom')->with('sender')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with('templateId')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transportMock));
     $this->_transportMock->expects($this->once())->method('sendMessage');
     $this->_model->sendPasswordResetNotificationEmail();
 }
Beispiel #5
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->assignedWebsites = [self::SECOND_WEBSITE_ID];
     $this->websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->secondWebsiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->websiteRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\WebsiteRepositoryInterface')->setMethods(['getList', 'getDefault'])->getMockForAbstractClass();
     $this->websiteRepositoryMock->expects($this->any())->method('getDefault')->willReturn($this->websiteMock);
     $this->websiteRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
     $this->groupRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\GroupRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->storeRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\StoreRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->locatorMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Locator\\LocatorInterface')->setMethods(['getProduct', 'getWebsiteIds'])->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getWebsiteIds')->willReturn($this->assignedWebsites);
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['isSingleStoreMode'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('isSingleStoreMode')->willReturn(false);
     $this->groupMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Group\\Collection')->setMethods(['getId', 'getName', 'getWebsiteId'])->disableOriginalConstructor()->getMock();
     $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn(self::WEBSITE_ID);
     $this->groupMock->expects($this->any())->method('getId')->willReturn(self::GROUP_ID);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->groupMock]);
     $this->storeViewMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getName', 'getId', 'getStoreGroupId'])->disableOriginalConstructor()->getMock();
     $this->storeViewMock->expects($this->any())->method('getName')->willReturn(self::STORE_VIEW_NAME);
     $this->storeViewMock->expects($this->any())->method('getStoreGroupId')->willReturn(self::GROUP_ID);
     $this->storeViewMock->expects($this->any())->method('getId')->willReturn(self::STORE_VIEW_ID);
     $this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->storeViewMock]);
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->secondWebsiteMock->expects($this->any())->method('getId')->willReturn($this->assignedWebsites[0]);
     $this->websiteMock->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
 }
Beispiel #6
0
 public function testGetStoreIds()
 {
     $expectedStoreIds = [1, 2, 3];
     $websiteIds = ['test'];
     $this->resource->expects($this->once())->method('getWebsiteIds')->will($this->returnValue($websiteIds));
     $this->website->expects($this->once())->method('getStoreIds')->will($this->returnValue($expectedStoreIds));
     $this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
 }
Beispiel #7
0
 public function testToOptionArray()
 {
     $websiteCollection = [$this->websiteMock];
     $groupCollection = [$this->groupMock];
     $storeCollection = [$this->storeMock];
     $expectedOptions = [['label' => __('All Store Views'), 'value' => '0'], ['label' => 'Main Website', 'value' => [['label' => '    Main Website Store', 'value' => [['label' => '        Default Store View', 'value' => '1']]]]]];
     $this->systemStoreMock->expects($this->once())->method('getWebsiteCollection')->willReturn($websiteCollection);
     $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn($groupCollection);
     $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn($storeCollection);
     $this->websiteMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
     $this->websiteMock->expects($this->any())->method('getName')->willReturn('Main Website');
     $this->groupMock->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn('1');
     $this->groupMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
     $this->groupMock->expects($this->atLeastOnce())->method('getName')->willReturn('Main Website Store');
     $this->storeMock->expects($this->atLeastOnce())->method('getGroupId')->willReturn('1');
     $this->storeMock->expects($this->atLeastOnce())->method('getName')->willReturn('Default Store View');
     $this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
     $this->escaperMock->expects($this->atLeastOnce())->method('escapeHtml')->willReturnMap([['Default Store View', null, 'Default Store View'], ['Main Website Store', null, 'Main Website Store'], ['Main Website', null, 'Main Website']]);
     $this->assertEquals($expectedOptions, $this->options->toOptionArray());
 }
Beispiel #8
0
 /**
  * @dataProvider dataProviderCallbackValidateProduct
  * @param bool $validate
  *
  * @return void
  */
 public function testCallbackValidateProduct($validate)
 {
     $args['product'] = $this->productModel;
     $args['attributes'] = [];
     $args['idx'] = 0;
     $args['row'] = ['entity_id' => '1', 'entity_type_id' => '4', 'attribute_set_id' => '4', 'type_id' => 'simple', 'sku' => 'Product', 'has_options' => '0', 'required_options' => '0', 'created_at' => '2014-06-25 13:14:30', 'updated_at' => '2014-06-25 14:37:15'];
     $this->storeManager->expects($this->any())->method('getWebsites')->with(false)->will($this->returnValue([$this->websiteModel, $this->websiteModel]));
     $this->websiteModel->expects($this->at(0))->method('getId')->will($this->returnValue('1'));
     $this->websiteModel->expects($this->at(2))->method('getId')->will($this->returnValue('2'));
     $this->websiteModel->expects($this->any())->method('getDefaultStore')->will($this->returnValue($this->storeModel));
     $this->storeModel->expects($this->at(0))->method('getId')->will($this->returnValue('1'));
     $this->storeModel->expects($this->at(1))->method('getId')->will($this->returnValue('2'));
     $this->combineFactory->expects($this->any())->method('create')->will($this->returnValue($this->condition));
     $this->condition->expects($this->any())->method('validate')->will($this->returnValue($validate));
     $this->condition->expects($this->any())->method('setRule')->will($this->returnSelf());
     $this->productModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->rule->callbackValidateProduct($args);
     $matchingProducts = $this->rule->getMatchingProductIds();
     foreach ($matchingProducts['1'] as $matchingRules) {
         $this->assertEquals($validate, $matchingRules);
     }
 }
Beispiel #9
0
 /**
  * Test get Value
  */
 public function testGetValue()
 {
     $coreStoreId = 1;
     $coreWebsiteId = 1;
     $productId = 1;
     $customerGroupId = 1;
     $dateTime = time();
     $expectedValue = 55.12;
     $this->coreStoreMock->expects($this->once())->method('getId')->will($this->returnValue($coreStoreId));
     $this->coreStoreMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue($coreWebsiteId));
     $this->dataTimeMock->expects($this->once())->method('scopeTimeStamp')->with($this->equalTo($coreStoreId))->will($this->returnValue($dateTime));
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($customerGroupId));
     $this->catalogRuleResourceMock->expects($this->once())->method('getRulePrice')->will($this->returnValue($expectedValue));
     $this->saleableItemMock->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $this->assertEquals($expectedValue, $this->object->getValue());
 }
Beispiel #10
0
 /**
  * testGetTierPrices
  * testSetTierPrices
  *
  * @dataProvider pricesDataProvider
  */
 public function testTierPrices($priceScope, $expectedWebsiteId)
 {
     // establish the behavior of the mocks
     $this->scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue($priceScope));
     $this->websiteMock->expects($this->any())->method('getId')->will($this->returnValue($expectedWebsiteId));
     $this->tpFactory->expects($this->any())->method('create')->will($this->returnCallback(function () {
         return $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
     }));
     // create sample TierPrice objects that would be coming from a REST call
     $tp1 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
     $tp1->setValue(10);
     $tp1->setCustomerGroupId(1);
     $tp1->setQty(11);
     $tp2 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
     $tp2->setValue(20);
     $tp2->setCustomerGroupId(2);
     $tp2->setQty(22);
     $tps = [$tp1, $tp2];
     // force the product to have null tier prices
     $this->product->setData($this::KEY_TIER_PRICE, null);
     $this->assertNull($this->product->getData($this::KEY_TIER_PRICE));
     // set the product with the TierPrice objects
     $this->model->setTierPrices($this->product, $tps);
     // test the data actually set on the product
     $tpArray = $this->product->getData($this::KEY_TIER_PRICE);
     $this->assertNotNull($tpArray);
     $this->assertTrue(is_array($tpArray));
     $this->assertEquals(sizeof($tps), sizeof($tpArray));
     for ($i = 0; $i < sizeof($tps); $i++) {
         $tpData = $tpArray[$i];
         $this->assertEquals($expectedWebsiteId, $tpData['website_id'], 'Website Id does not match');
         $this->assertEquals($tps[$i]->getValue(), $tpData['price'], 'Price/Value does not match');
         $this->assertEquals($tps[$i]->getValue(), $tpData['website_price'], 'WebsitePrice/Value does not match');
         $this->assertEquals($tps[$i]->getCustomerGroupId(), $tpData['cust_group'], 'Customer group Id does not match');
         $this->assertEquals($tps[$i]->getQty(), $tpData['price_qty'], 'Qty does not match');
     }
     // test with the data retrieved as a REST object
     $tpRests = $this->model->getTierPrices($this->product);
     $this->assertNotNull($tpRests);
     $this->assertTrue(is_array($tpRests));
     $this->assertEquals(sizeof($tps), sizeof($tpRests));
     for ($i = 0; $i < sizeof($tps); $i++) {
         $this->assertEquals($tps[$i]->getValue(), $tpRests[$i]->getValue(), 'REST: Price/Value does not match');
         $this->assertEquals($tps[$i]->getCustomerGroupId(), $tpRests[$i]->getCustomerGroupId(), 'REST: Customer group Id does not match');
         $this->assertEquals($tps[$i]->getQty(), $tpRests[$i]->getQty(), 'REST: Qty does not match');
     }
 }