public function testIsSingleStoreModeWhenSingleStoreModeDisabledAndHasSingleStore() { $this->_configMock->expects($this->once())->method('getValue')->with(\Magento\Store\Model\StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE)->will($this->returnValue(false)); $this->_storage->expects($this->once())->method('hasSingleStore')->will($this->returnValue(true)); $this->_factoryMock->expects($this->any())->method('get')->will($this->returnValue($this->_storage)); $this->assertFalse($this->_model->isSingleStoreMode()); }
public function __construct(Context $context, array $data = [], StoreManager $sManager, Webtracking $webtracking, Session $session) { parent::__construct($context, $data); $this->_activeStore = $sManager->getStore(); $this->_webtracking = $webtracking; $this->_session = $session; }
public function __construct(Session $customerSession, CheckoutSession $CheckoutSession, Registry $registry, Subscriber $subscriber, Group $customerGroupModel, Queue $remarketyQueue, Store $store, ScopeConfigInterface $scopeConfig, StoreManager $sManager) { parent::__construct($registry, $subscriber, $customerGroupModel, $remarketyQueue, $store, $scopeConfig); $this->session = $customerSession; $this->_checkoutSession = $CheckoutSession; $this->_store = $sManager->getStore(); }
/** * Returns catalog rule value * * @return float|boolean */ public function getValue() { if (null === $this->value) { $this->value = $this->resourceRuleFactory->create()->getRulePrice($this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId()); $this->value = $this->value ? floatval($this->value) : false; } return $this->value; }
/** * Delete Expired Captcha Images * * @return \Magento\Captcha\Model\Observer */ public function deleteExpiredImages() { foreach ($this->_storeManager->getWebsites() as $website) { $this->_deleteExpiredImagesForWebsite($this->_helper, $website, $website->getDefaultStore()); } $this->_deleteExpiredImagesForWebsite($this->_adminHelper); return $this; }
public function testGetRelayUrl() { $baseUrl = 'http://base.url/'; $defaultStoreMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $defaultStoreMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)->willReturn($baseUrl); $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn(null); $this->storeManagerMock->expects($this->once())->method('getStores')->willReturn([$defaultStoreMock]); $this->assertSame('http://base.url/authorizenet/directpost_payment/backendResponse', $this->dataHelper->getRelayUrl()); }
/** * Get urls of all the stores in the magento install. * * @return array */ public function getAllUrls() { $urls = []; $stores = $this->storeManager->getStores(false); foreach ($stores as $store) { $urls[] = $store->getBaseUrl(); } return $urls; }
public function testGetPreviewImageUrl() { /** @var $theme \Magento\Theme\Model\Theme|\PHPUnit_Framework_MockObject_MockObject */ $theme = $this->getMock('Magento\\Theme\\Model\\Theme', ['getPreviewImage', 'isPhysical', '__wakeup'], [], '', false); $theme->expects($this->any())->method('getPreviewImage')->will($this->returnValue('image.png')); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $store->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://localhost/')); $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->assertEquals('http://localhost/theme/preview/image.png', $this->model->getPreviewImageUrl($theme)); }
/** * 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 getStoreDataProvider * @param $websiteId * @param $websiteStoreId * @param $storeId * @param $result */ public function testGetStoreId($websiteId, $websiteStoreId, $storeId, $result) { if ($websiteId * 1) { $this->_model->setWebsiteId($websiteId); $website = new \Magento\Framework\DataObject(['store_ids' => [$websiteStoreId]]); $this->_storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($website)); } else { $this->_model->setStoreId($storeId); $this->_storeManager->expects($this->never())->method('getWebsite'); } $this->assertEquals($result, $this->_model->getStoreId()); }
/** * Returns catalog rule value * * @return float|boolean */ public function getValue() { if (null === $this->value) { if ($this->product->hasData(self::PRICE_CODE)) { $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false; } else { $this->value = $this->getRuleResource()->getRulePrice($this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId()); $this->value = $this->value ? floatval($this->value) : false; if ($this->value) { $this->value = $this->priceCurrency->convertAndRound($this->value); } } } return $this->value; }
public function setUp() { $objectManager = new ObjectManager($this); $this->productRepository = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductRepository')->setMethods(['get'])->disableOriginalConstructor()->getMock(); $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getId', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->setMethods(['getStore'])->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->optionConverter = $this->getMockBuilder('Magento\\Bundle\\Service\\V1\\Data\\Product\\OptionConverter')->setMethods(['createModelFromData', 'createDataFromModel', 'getModelFromData'])->disableOriginalConstructor()->getMock(); $this->productType = $this->getMockBuilder('Magento\\Bundle\\Model\\Product\\Type')->setMethods(['getOptionsCollection'])->disableOriginalConstructor()->getMock(); $this->option = $this->getMockBuilder('Magento\\Bundle\\Service\\V1\\Data\\Product\\Option')->disableOriginalConstructor()->getMock(); $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getTypeId', 'getSku'])->disableOriginalConstructor()->getMock(); $this->optionModel = $this->getMockBuilder('Magento\\Bundle\\Model\\Option')->setMethods(['__wakeup', 'getId', 'delete', 'setStoreId', 'save'])->disableOriginalConstructor()->getMock(); $this->optionCollection = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Option\\Collection')->setMethods(['setIdFilter', 'getFirstItem'])->disableOriginalConstructor()->getMock(); $this->model = $objectManager->getObject('Magento\\Bundle\\Service\\V1\\Product\\Option\\WriteService', ['productRepository' => $this->productRepository, 'type' => $this->productType, 'storeManager' => $this->storeManager, 'optionConverter' => $this->optionConverter]); }
/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', array('getEntityType', 'getEntityTypeId'), array(), '', false); $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityType')->with($this->equalTo('catalog_product'))->will($this->returnSelf()); $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityTypeId')->will($this->returnValue('1')); $this->_optionModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Option', array(), array(), '', false); $this->_optionFactory = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\OptionFactory', array('create'), array(), '', false); $this->_optionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_optionModel)); $this->_storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManager', array('getWebsites', 'getStores'), array(), '', false); $this->_storeManager->expects($this->atLeastOnce())->method('getWebsites')->will($this->returnValue(array())); $this->_storeManager->expects($this->atLeastOnce())->method('getStores')->will($this->returnValue(array())); $this->_setCol = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', array('setEntityTypeFilter'), array(), '', false); $this->_setCol->expects($this->atLeastOnce())->method('setEntityTypeFilter')->with($this->equalTo('1'))->will($this->returnValue(array())); $this->_setColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', array('create'), array(), '', false); $this->_setColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_setCol)); $this->_importConfig = $this->getMock('\\Magento\\ImportExport\\Model\\Import\\Config', array('getEntityTypes'), array(), '', false); $this->_importConfig->expects($this->atLeastOnce())->method('getEntityTypes')->with('catalog_product')->will($this->returnValue(array())); $this->_categoryCol = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\Collection', array('addNameToResult'), array(), '', false); $this->_categoryCol->expects($this->atLeastOnce())->method('addNameToResult')->will($this->returnValue(array())); $this->_categoryColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', array('create'), array(), '', false); $this->_categoryColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_categoryCol)); $this->_product = $this->getMock('\\Magento\\Catalog\\Model\\Product', array('getProductEntitiesInfo', '__wakeup'), array(), '', false); $this->_product->expects($this->atLeastOnce())->method('getProductEntitiesInfo')->with($this->equalTo(array('entity_id', 'type_id', 'attribute_set_id', 'sku')))->will($this->returnValue(array())); $this->_productFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', array('create'), array(), '', false); $this->_productFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_product)); $this->_customerGroupService = $this->getMock('Magento\\Customer\\Service\\V1\\CustomerGroupService', array('getGroups'), array(), '', false); $this->_customerGroupService->expects($this->atLeastOnce())->method('getGroups')->will($this->returnValue(array())); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_model = $objectManager->getObject('\\Magento\\CatalogImportExport\\Model\\Import\\Product', array('config' => $this->_eavConfig, 'optionFactory' => $this->_optionFactory, 'storeManager' => $this->_storeManager, 'setColFactory' => $this->_setColFactory, 'importConfig' => $this->_importConfig, 'categoryColFactory' => $this->_categoryColFactory, 'productFactory' => $this->_productFactory, 'customerGroupService' => $this->_customerGroupService)); }
/** * Update/create store (frontname: "Store View"). * * @param int $storeId ID to update existing store or 'null' to create new one * @param string $name * @param string $code * @param int $websiteId * @param int $groupId (frontname: "Store") * @param int $sortOrder * @param bool $isActive * @return \Magento\Store\Model\Store */ private function saveStore($storeId = null, $isActive = false, $name = null, $code = null, $websiteId = null, $groupId = null, $sortOrder = null) { $event = 'store_add'; /** @var \Magento\Store\Model\Store $store */ $store = $this->_manObj->create(\Magento\Store\Model\Store::class); $store->load($storeId); /* 'code' is required attr. and should be set for existing store */ $event = is_null($store->getCode()) ? 'store_add' : 'store_edit'; $store->setIsActive($isActive); if (!is_null($name)) { $store->setName($name); } if (!is_null($code)) { $store->setCode($code); } if (!is_null($websiteId)) { $store->setWebsiteId($websiteId); } if (!is_null($websiteId)) { $store->setGroupId($groupId); } if (!is_null($sortOrder)) { $store->setSortOrder($sortOrder); } $store->save(); /** @var \Magento\Store\Model\StoreManager */ $this->manStore->reinitStores(); /** @var \Magento\Framework\Event\ManagerInterface */ $this->manEvent->dispatch($event, ['store' => $store]); return $store; }
/** * 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)); }
/** * {@inheritdoc} */ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option) { $option->setStoreId($this->storeManager->getStore()->getId()); $option->setParentId($product->getId()); $optionId = $option->getOptionId(); $linksToAdd = []; if (!$optionId) { $option->setDefaultTitle($option->getTitle()); if (is_array($option->getProductLinks())) { $linksToAdd = $option->getProductLinks(); } } else { $optionCollection = $this->type->getOptionsCollection($product); /** @var \Magento\Bundle\Model\Option $existingOption */ $existingOption = $optionCollection->getItemById($option->getOptionId()); if (!isset($existingOption) || !$existingOption->getOptionId()) { throw new NoSuchEntityException(__('Requested option doesn\'t exist')); } $option->setData(array_merge($existingOption->getData(), $option->getData())); $this->updateOptionSelection($product, $option); } try { $this->optionResource->save($option); } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not save option'), $e); } /** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */ foreach ($linksToAdd as $linkedProduct) { $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct); } return $option->getOptionId(); }
public function testGetSwatchMediaUrl() { $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', ['getBaseUrl'], [], '', false); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->once())->method('getBaseUrl')->with('media')->willReturn('http://url/pub/media/'); $result = $this->mediaHelperObject->getSwatchMediaUrl(); $this->assertEquals($result, 'http://url/pub/media/attribute/swatch'); }
public function testAroundDispatchNoStoreCookie() { $storeCode = null; $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock); $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode); $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode'); $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock); $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)); }
public function testBeforeDispatchNoStoreCookie() { $storeCode = null; $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode); $this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock); $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode'); $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock); $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock); }
public function testSendNewAccountEmailWithoutStoreId() { $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $website->expects($this->once())->method('getStoreIds')->will($this->returnValue([1, 2, 3, 4])); $this->_storeManager->expects($this->once())->method('getWebsite')->with(1)->will($this->returnValue($website)); $this->_storeManager->expects($this->once())->method('getStore')->with(1)->will($this->returnValue($store)); $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->_attribute)); $this->_attribute->expects($this->exactly(3))->method('getIsVisible')->will($this->returnValue(true)); $methods = ['setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', 'setFrom', 'addTo']; foreach ($methods as $method) { $this->_transportBuilderMock->expects($this->once())->method($method)->will($this->returnSelf()); } $transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $transportMock->expects($this->once())->method('sendMessage')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($transportMock)); $this->_model->setData(['website_id' => 1, 'store_id' => 1, 'email' => '*****@*****.**', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'middlename' => 'MiddleName', 'prefix' => 'Prefix']); $this->_model->sendNewAccountEmail('registered'); }
/** * Set up */ public function setUp() { $this->saleableItemMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', '__wakeup', 'getPriceInfo'], [], '', false); $this->dataTimeMock = $this->getMockForAbstractClass('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface', [], '', false, true, true, []); $this->coreStoreMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->coreStoreMock)); $this->customerSessionMock = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->priceInfoMock = $this->getMock('\\Magento\\Framework\\Pricing\\PriceInfo', ['getAdjustments'], [], '', false); $this->catalogRuleResourceFactoryMock = $this->getMock('\\Magento\\CatalogRule\\Model\\Resource\\RuleFactory', ['create'], [], '', false); $this->catalogRuleResourceMock = $this->getMock('\\Magento\\CatalogRule\\Model\\Resource\\Rule', [], [], '', false); $this->coreWebsiteMock = $this->getMock('\\Magento\\Core\\Model\\Website', [], [], '', false); $this->priceInfoMock->expects($this->any())->method('getAdjustments')->will($this->returnValue([])); $this->saleableItemMock->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->catalogRuleResourceFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->catalogRuleResourceMock)); $this->calculator = $this->getMockBuilder('Magento\\Framework\\Pricing\\Adjustment\\Calculator')->disableOriginalConstructor()->getMock(); $qty = 1; $this->object = new CatalogRulePrice($this->saleableItemMock, $qty, $this->calculator, $this->dataTimeMock, $this->storeManagerMock, $this->customerSessionMock, $this->catalogRuleResourceFactoryMock); }
/** * Execute method. */ public function execute() { $code = $this->getRequest()->getParam('code', false); $userId = $this->getRequest()->getParam('state'); //load admin user $adminUser = $this->adminUser->create()->load($userId); //app code and admin user must be present if ($code && $adminUser->getId()) { $clientId = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID); $clientSecret = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID); //callback uri if not set custom $redirectUri = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true); $redirectUri .= 'connector/email/callback'; $data = 'client_id=' . $clientId . '&client_secret=' . $clientSecret . '&redirect_uri=' . $redirectUri . '&grant_type=authorization_code' . '&code=' . $code; //callback url $url = $this->config->getTokenUrl(); //@codingStandardsIgnoreStart $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POST, count($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']); $response = json_decode(curl_exec($ch)); if ($response === false) { $this->helper->error('Error Number: ' . curl_errno($ch), []); } if (isset($response->error)) { $this->helper->error('OAUTH failed ' . $response->error, []); } elseif (isset($response->refresh_token)) { //save the refresh token to the admin user $adminUser->setRefreshToken($response->refresh_token)->save(); } //@codingStandardsIgnoreEnd } //redirect to automation index page $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio')); }
/** * @dataProvider getExpiredImages */ public function testDeleteExpiredImages($website, $isFile, $filename, $mTime, $timeout, $mustDelete) { $this->_storeManager->expects($this->once())->method('getWebsites')->will($this->returnValue(isset($website) ? [$website] : [])); if (isset($website)) { $this->_helper->expects($this->once())->method('getConfig')->with($this->equalTo('timeout'), new \PHPUnit_Framework_Constraint_IsIdentical($website->getDefaultStore()))->will($this->returnValue($timeout)); } else { $this->_helper->expects($this->never())->method('getConfig'); } $this->_adminHelper->expects($this->once())->method('getConfig')->with($this->equalTo('timeout'), new \PHPUnit_Framework_Constraint_IsNull())->will($this->returnValue($timeout)); $timesToCall = isset($website) ? 2 : 1; $this->_directory->expects($this->exactly($timesToCall))->method('read')->will($this->returnValue([$filename])); $this->_directory->expects($this->exactly($timesToCall))->method('isFile')->will($this->returnValue($isFile)); $this->_directory->expects($this->any())->method('stat')->will($this->returnValue(['mtime' => $mTime])); if ($mustDelete) { $this->_directory->expects($this->exactly($timesToCall))->method('delete')->with($filename); } else { $this->_directory->expects($this->never())->method('delete'); } $this->_model->deleteExpiredImages(); }
/** * Create mock object for context */ private function initContextMock() { $this->store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock(); $this->storeManager = $this->getMockBuilder(StoreManager::class)->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock(); $this->storeManager->expects(static::any())->method('getStore')->willReturn($this->store); $this->urlBuilder = $this->getMockBuilder('Magento\\Framework\\UrlInterface')->getMockForAbstractClass(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMockForAbstractClass(); $this->context = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template\\Context')->disableOriginalConstructor()->getMock(); $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); $this->context->expects($this->any())->method('getStoreManager')->willReturn($this->storeManager); }
public function testLoadAttributesCollection() { $entityType = 'entityType'; $formCode = 'formCode'; $store = $this->getMockBuilder('Magento\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->attrFormCollection->expects($this->once())->method('setStore')->with($store)->will($this->returnSelf()); $this->attrFormCollection->expects($this->once())->method('setEntityType')->with($entityType)->will($this->returnSelf()); $this->attrFormCollection->expects($this->once())->method('addFormCodeFilter')->with($formCode)->will($this->returnSelf()); $this->attrFormCollection->expects($this->once())->method('setSortOrder')->will($this->returnSelf()); $actualValue = $this->attributeMetadataProvider->loadAttributesCollection($entityType, $formCode); $this->assertEquals($this->attrFormCollection, $actualValue); }
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); }
/** * {@inheritdoc} */ public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option) { $product = $this->getProduct($productSku); $optionCollection = $this->type->getOptionsCollection($product); $optionCollection->setIdFilter($optionId); /** @var \Magento\Bundle\Model\Option $optionModel */ $optionModel = $optionCollection->getFirstItem(); $updateOption = $this->optionConverter->getModelFromData($option, $optionModel); if (!$updateOption->getId()) { throw new NoSuchEntityException('Requested option doesn\'t exist'); } $updateOption->setStoreId($this->storeManager->getStore()->getId()); /** * @var Link[] $existingProductLinks */ $existingProductLinks = $optionModel->getProductLinks(); if (!is_array($existingProductLinks)) { $existingProductLinks = array(); } /** * @var Link[] $newProductLinks */ $newProductLinks = $option->getProductLinks(); if (is_null($newProductLinks)) { $newProductLinks = array(); } /** * @var Link[] $linksToDelete */ $linksToDelete = array_udiff($existingProductLinks, $newProductLinks, array($this, 'compareLinks')); foreach ($linksToDelete as $link) { $this->linkWriteService->removeChild($productSku, $option->getId(), $link->getSku()); } /** * @var Link[] $linksToAdd */ $linksToAdd = array_udiff($newProductLinks, $existingProductLinks, array($this, 'compareLinks')); foreach ($linksToAdd as $link) { $this->linkWriteService->addChild($productSku, $option->getId(), $link); } try { $updateOption->save(); } catch (\Exception $e) { throw new CouldNotSaveException('Could not save option', [], $e); } return true; }
/** * @param $customerId * @param $key * @param $backUrl * @param $successUrl * @param $resultUrl * @param $isSetFlag * @param $successMessage * * @dataProvider getSuccessRedirectDataProvider */ public function testSuccessRedirect($customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['id', false, $customerId], ['key', false, $key], ['back_url', false, $backUrl]]); $this->customerRepositoryMock->expects($this->any())->method('getById')->with($customerId)->will($this->returnValue($this->customerDataMock)); $email = '*****@*****.**'; $this->customerDataMock->expects($this->once())->method('getEmail')->will($this->returnValue($email)); $this->customerAccountManagementMock->expects($this->once())->method('activate')->with($this->equalTo($email), $this->equalTo($key))->will($this->returnValue($this->customerDataMock)); $this->customerSessionMock->expects($this->any())->method('setCustomerDataAsLoggedIn')->with($this->equalTo($this->customerDataMock))->willReturnSelf(); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->willReturnSelf(); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->urlMock->expects($this->any())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($successUrl)); $this->redirectMock->expects($this->never())->method('success')->with($this->equalTo($resultUrl))->willReturn($resultUrl); $this->scopeConfigMock->expects($this->never())->method('isSetFlag')->with(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE)->willReturn($isSetFlag); $this->model->execute(); }
public function testGetSwatchesByOptionsIdIf3() { $swatchMock = $this->getMock('\\Magento\\Swatches\\Model\\Swatch', [], [], '', false); $optionsData = ['type' => 0, 'store_id' => 0, 'value' => 'test_test', 'option_id' => 35, 'id' => 423]; $swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn(0); $swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(0); $swatchMock->expects($this->at(2))->method('offsetGet')->with('store_id')->willReturn(0); $swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35); $swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData); $swatchCollectionMock = $this->objectManager->getCollectionMock('\\Magento\\Swatches\\Model\\ResourceModel\\Swatch\\Collection', [$swatchMock]); $this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock); $swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf()); $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManagerMock->method('getStore')->willReturn($storeMock); $storeMock->method('getId')->willReturn(1); $this->swatchHelperObject->getSwatchesByOptionsId([35]); }
/** * {@inheritdoc} */ public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option) { $product = $this->getProduct($productSku); $optionCollection = $this->type->getOptionsCollection($product); $optionCollection->setIdFilter($optionId); /** @var \Magento\Bundle\Model\Option $optionModel */ $optionModel = $optionCollection->getFirstItem(); $updateOption = $this->optionConverter->getModelFromData($option, $optionModel); if (!$updateOption->getId()) { throw new NoSuchEntityException('Requested option doesn\'t exist'); } $updateOption->setStoreId($this->storeManager->getStore()->getId()); try { $updateOption->save(); } catch (\Exception $e) { throw new CouldNotSaveException('Could not save option', [], $e); } return true; }