Exemplo n.º 1
0
 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->managerInterfaceMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->resourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->entityFactoryMock2 = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false);
     $this->helperMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Helper', [], [], '', false);
     $entity = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false);
     $entity->expects($this->any())->method('getReadConnection')->will($this->returnValue($adapter));
     $entity->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
     $this->universalFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false);
     $this->universalFactoryMock->expects($this->any())->method('create')->will($this->returnValue($entity));
     $this->storeManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\Store\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnCallback(function ($store) {
         return is_object($store) ? $store : new \Magento\Framework\Object(['id' => 42]);
     }));
     $this->catalogHelperMock = $this->getMock('Magento\\Catalog\\Helper\\Data', [], [], '', false);
     $this->stateMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State', [], [], '', false);
     $this->scopeConfigInterfaceMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->optionFactoryMock = $this->getMock('Magento\\Catalog\\Model\\Product\\OptionFactory', [], [], '', false);
     $this->urlMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Url', [], [], '', false);
     $this->timezoneInterfaceMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->sessionMock = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->dateTimeMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->collection = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Resource\\Product\\Link\\Product\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->managerInterfaceMock, 'eavConfig' => $this->configMock, 'resource' => $this->resourceMock, 'eavEntityFactory' => $this->entityFactoryMock2, 'resourceHelper' => $this->helperMock, 'universalFactory' => $this->universalFactoryMock, 'storeManager' => $this->storeManagerMock, 'catalogData' => $this->catalogHelperMock, 'catalogProductFlatState' => $this->stateMock, 'scopeConfig' => $this->scopeConfigInterfaceMock, 'productOptionFactory' => $this->optionFactoryMock, 'catalogUrl' => $this->urlMock, 'localeDate' => $this->timezoneInterfaceMock, 'customerSession' => $this->sessionMock, 'dateTime' => $this->dateTimeMock]);
 }
Exemplo n.º 2
0
 public function testProcessWithoutStoreCode()
 {
     $path = 'rest/V1/customerAccounts/createCustomer';
     $result = $this->pathProcessor->process($path);
     $this->assertEquals('/V1/customerAccounts/createCustomer', $result);
     $this->assertEquals('default', $this->storeManager->getStore()->getCode());
 }
Exemplo n.º 3
0
 /**
  * @param bool $isWebsiteScope
  * @param array $websites
  * @param int $quoteId
  * @dataProvider dispatchDataProvider
  */
 public function testDispatch($isWebsiteScope, $websites, $quoteId)
 {
     $this->configMock->expects($this->once())->method('isWebsiteScope')->will($this->returnValue($isWebsiteScope));
     $customerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $customerDataObjectMock->expects($this->any())->method('getGroupId')->will($this->returnValue(1));
     $customerDataObjectMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue(2));
     if ($isWebsiteScope) {
         $websites = $websites[0];
         $this->storeManagerMock->expects($this->once())->method('getWebsite')->with(2)->will($this->returnValue($websites));
     } else {
         $this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
     }
     $origCustomerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $origCustomerDataObjectMock->expects($this->any())->method('getGroupId')->will($this->returnValue(2));
     $this->eventMock->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($customerDataObjectMock));
     $this->eventMock->expects($this->any())->method('getOrigCustomerDataObject')->will($this->returnValue($origCustomerDataObjectMock));
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote $quoteMock */
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['setWebsite', 'setCustomerGroupId', 'collectTotals', '__wakeup'])->disableOriginalConstructor()->getMock();
     $websiteCount = count($websites);
     if ($quoteId) {
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('getForCustomer')->will($this->returnValue($quoteMock));
         $quoteMock->expects($this->exactly($websiteCount))->method('setWebsite');
         $quoteMock->expects($this->exactly($websiteCount))->method('setCustomerGroupId');
         $quoteMock->expects($this->exactly($websiteCount))->method('collectTotals');
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('save')->with($quoteMock);
     } else {
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('getForCustomer')->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException());
         $quoteMock->expects($this->never())->method('setCustomerGroupId');
         $quoteMock->expects($this->never())->method('collectTotals');
         $this->quoteRepositoryMock->expects($this->never())->method('save');
     }
     $this->customerQuote->dispatch($this->observerMock);
 }
Exemplo n.º 4
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]);
 }
Exemplo n.º 5
0
 public function testGetRssData()
 {
     $rssData = ['title' => 'Pending product review(s)', 'description' => 'Pending product review(s)', 'link' => 'http://rss.magento.com', 'charset' => 'UTF-8', 'entries' => ['title' => 'Product: "Product Name" reviewed by: Product Nick', 'link' => 'http://product.magento.com', 'description' => ['rss_url' => 'http://rss.magento.com', 'name' => 'Product Name', 'summary' => 'Product Title', 'review' => 'Product Detail', 'store' => 'Store Name']]];
     $rssUrl = 'http://rss.magento.com';
     $productModel = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product', ['getStoreId', 'getId', 'getReviewId', 'getName', 'getDetail', 'getTitle', 'getNickname', 'getProductUrl'], [], '', false);
     $storeModel = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManagerInterface->expects($this->once())->method('getStore')->will($this->returnValue($storeModel));
     $storeModel->expects($this->once())->method('getName')->will($this->returnValue($rssData['entries']['description']['store']));
     $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue($rssUrl));
     $this->urlBuilder->expects($this->once())->method('setScope')->will($this->returnSelf());
     $productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $productModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $productModel->expects($this->once())->method('getReviewId')->will($this->returnValue(1));
     $productModel->expects($this->any())->method('getNickName')->will($this->returnValue('Product Nick'));
     $productModel->expects($this->any())->method('getName')->will($this->returnValue($rssData['entries']['description']['name']));
     $productModel->expects($this->once())->method('getDetail')->will($this->returnValue($rssData['entries']['description']['review']));
     $productModel->expects($this->once())->method('getTitle')->will($this->returnValue($rssData['entries']['description']['summary']));
     $productModel->expects($this->any())->method('getProductUrl')->will($this->returnValue('http://product.magento.com'));
     $this->rss->expects($this->once())->method('getProductCollection')->will($this->returnValue([$productModel]));
     $data = $this->block->getRssData();
     $this->assertEquals($rssData['title'], $data['title']);
     $this->assertEquals($rssData['description'], $data['description']);
     $this->assertEquals($rssData['link'], $data['link']);
     $this->assertEquals($rssData['charset'], $data['charset']);
     $this->assertEquals($rssData['entries']['title'], $data['entries'][0]['title']);
     $this->assertEquals($rssData['entries']['link'], $data['entries'][0]['link']);
     $this->assertContains($rssData['entries']['description']['rss_url'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['name'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['summary'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['review'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['store'], $data['entries'][0]['description']);
 }
Exemplo n.º 6
0
 public function testSetNotIntStoreId()
 {
     $this->_storeManagerInterface->expects($this->once())->method('getStore');
     $store = $this->_model->setStoreId('test');
     $storeId = $store->getStoreId();
     $this->assertEquals(0, $storeId);
 }
Exemplo n.º 7
0
 /**
  * Run test getStoreWebsiteId method
  *
  * @return void
  */
 public function testGetStoreWebsiteId()
 {
     $storeId = 20;
     $storeMock = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($storeMock));
     $storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue('return-value'));
     $this->assertEquals('return-value', $this->attribute->getStoreWebsiteId($storeId));
 }
Exemplo n.º 8
0
 /**
  * @param int $storeId
  * @param bool $withAdmin
  * @param array $condition
  * @dataProvider dataProviderForTestAddStoreFilterIfStoreIsInt
  * @covers \Magento\UrlRewrite\Model\Resource\UrlRewriteCollection
  */
 public function testAddStoreFilterIfStoreIsInt($storeId, $withAdmin, $condition)
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->adapter->expects($this->once())->method('prepareSqlCondition')->with('store_id', ['in' => $condition]);
     $this->collection->addStoreFilter($storeId, $withAdmin);
 }
Exemplo n.º 9
0
 /**
  * Test for getAllOptions method
  *
  * @param $cachedDataSrl
  * @param $cachedDataUnsrl
  *
  * @dataProvider testGetAllOptionsDataProvider
  */
 public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl)
 {
     $this->storeMock->expects($this->once())->method('getCode')->will($this->returnValue('store_code'));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->cacheConfig->expects($this->once())->method('load')->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))->will($this->returnValue($cachedDataSrl));
     $countryOfManufacture = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture', ['storeManager' => $this->storeManagerMock, 'configCacheType' => $this->cacheConfig]);
     $this->assertEquals($cachedDataUnsrl, $countryOfManufacture->getAllOptions());
 }
Exemplo n.º 10
0
 protected function setUp()
 {
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Framework\\Store\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->filter = $objectManager->getObject('Magento\\Cms\\Model\\Template\\Filter', ['storeManager' => $this->storeManagerMock]);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
 }
Exemplo n.º 11
0
 public function testGetUrlPathWithSuffixAndCategoryAnsStore()
 {
     $storeId = 1;
     $this->product->expects($this->once())->method('getData')->with('url_path')->will($this->returnValue('product-path'));
     $this->categoryUrlPathGenerator->expects($this->once())->method('getUrlPath')->will($this->returnValue('category-url-path'));
     $this->storeManager->expects($this->never())->method('getStore');
     $this->scopeConfig->expects($this->once())->method('getValue')->with(ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('.html'));
     $this->assertEquals('category-url-path/product-path.html', $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product, $storeId, $this->category));
 }
Exemplo n.º 12
0
 /**
  * @dataProvider testIsStoreInUrlDataProvider
  */
 public function testIsStoreInUrl($isUseStoreInUrl)
 {
     $storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $storeMock->expects($this->once())->method('isUseStoreInUrl')->will($this->returnValue($isUseStoreInUrl));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $this->assertEquals($this->switcher->isStoreInUrl(), $isUseStoreInUrl);
     // check value is cached
     $this->assertEquals($this->switcher->isStoreInUrl(), $isUseStoreInUrl);
 }
Exemplo n.º 13
0
 public function testGetWebsiteId()
 {
     $websiteId = 10;
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $websiteMock->expects($this->once())->method('getId')->willReturn($websiteId);
     $this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
     $this->assertEquals($websiteId, $this->model->getWebsiteId());
     $this->storeManagerMock->expects($this->never())->method('getWebsite')->willReturn($websiteMock);
     $this->assertEquals($websiteId, $this->model->getWebsiteId());
 }
Exemplo n.º 14
0
 /**
  * Log out user and redirect him to new admin custom url
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function afterCustomUrlChanged()
 {
     if (is_null($this->_coreRegistry->registry('custom_admin_path_redirect'))) {
         return;
     }
     $this->_authSession->destroy();
     $route = $this->_backendData->getAreaFrontName();
     $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
     exit(0);
 }
Exemplo n.º 15
0
 public function testGetCollection()
 {
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(['id' => 42])));
     $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242));
     $this->collection->expects($this->any())->method('addStoreFilter')->with(42)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addCustomerFilter')->with(4242)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setDateOrder')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setPageSize')->with(5)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addReviewSummary')->with()->will($this->returnValue($this->collection));
     $this->assertSame($this->collection, $this->object->getCollection());
 }
Exemplo n.º 16
0
 public function testBeforeSave()
 {
     $websiteId = 1;
     $object = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->setMethods(['hasData', 'setData'])->getMock();
     $store = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getWebsiteId'])->getMock();
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $object->expects($this->once())->method('hasData')->with('website_id')->will($this->returnValue(false));
     $object->expects($this->once())->method('setData')->with($this->logicalOr('website_id', $websiteId))->will($this->returnSelf());
     /** @var \Magento\Framework\Object $object */
     $this->assertInstanceOf('Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Website', $this->testable->beforeSave($object));
 }
Exemplo n.º 17
0
 public function testParseGdataExceptionMessageWithProduct()
 {
     $message = "some message\n\nother message";
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getName', 'getStoreId'], [], '', false);
     $product->expects($this->any())->method('getName')->will($this->returnValue("product name"));
     $storeId = 1;
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManagerInterface->expects($this->any())->method('getStore')->with($storeId)->will($this->returnValue($store));
     $store->expects($this->any())->method('getName')->will($this->returnValue('store name'));
     $result = $this->data->parseGdataExceptionMessage($message, $product);
     $this->assertEquals("some message for product 'product name' (in 'store name' store). " . "other message for product 'product name' (in 'store name' store)", $result);
 }
Exemplo n.º 18
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if (!$input->getOption('format')) {
         $this->writeSection($output, 'Magento Stores - Base URLs');
     }
     $this->initMagento();
     foreach ($this->storeManager->getStores() as $store) {
         $table[$store->getId()] = array($store->getId(), $store->getCode(), $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB), $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true));
     }
     ksort($table);
     $this->getHelper('table')->setHeaders(array('id', 'code', 'unsecure_baseurl', 'secure_baseurl'))->renderByFormat($output, $table, $input->getOption('format'));
 }
Exemplo n.º 19
0
 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Framework\Store\StoreManagerInterface $storeManager
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param array $data
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Store\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, array $data = [])
 {
     parent::__construct($context);
     $this->_scopeConfig = $scopeConfig;
     $this->_currentStore = isset($data['current_store']) ? $data['current_store'] : $storeManager->getStore();
     if (!$this->_currentStore instanceof \Magento\Store\Model\Store) {
         throw new \InvalidArgumentException('Required store object is invalid');
     }
     $this->_website = isset($data['website']) ? $data['website'] : $storeManager->getWebsite();
     if (!$this->_website instanceof \Magento\Store\Model\Website) {
         throw new \InvalidArgumentException('Required website object is invalid');
     }
 }
Exemplo n.º 20
0
 public function testGetConfigCanShowConfig()
 {
     $result = ['key1' => 'value1', 'key2' => 'value2'];
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getWebsiteId')->will($this->returnValue('1'));
     $this->scopeConfig->expects($this->once())->method('getValue')->with('customer/address', \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, $store)->will($this->returnValue($result));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->assertNull($this->helper->getConfig('unavailable_key'));
     $this->assertFalse($this->helper->canShowConfig('unavailable_key'));
     $this->assertEquals($result['key1'], $this->helper->getConfig('key1'));
     $this->assertEquals($result['key2'], $this->helper->getConfig('key2'));
     $this->assertTrue($this->helper->canShowConfig('key1'));
     $this->assertTrue($this->helper->canShowConfig('key2'));
 }
Exemplo n.º 21
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $this->_options = [];
         foreach ($this->_storeManager->getWebsites() as $website) {
             $id = $website->getId();
             $name = $website->getName();
             if ($id != 0) {
                 $this->_options[] = ['value' => $id, 'label' => $name];
             }
         }
     }
     return $this->_options;
 }
Exemplo n.º 22
0
 /**
  * Process path info
  *
  * @param string $pathInfo
  * @return string
  * @throws NoSuchEntityException
  */
 public function process($pathInfo)
 {
     $pathParts = $this->stripPathBeforeStorecode($pathInfo);
     $storeCode = $pathParts[0];
     $stores = $this->storeManager->getStores(false, true);
     if (isset($stores[$storeCode])) {
         $this->storeManager->setCurrentStore($storeCode);
         $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
     } else {
         $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::DEFAULT_CODE);
         $path = '/' . implode('/', $pathParts);
     }
     return $path;
 }
Exemplo n.º 23
0
 public function testGetCacheKeyInfo()
 {
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $store->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->once())->method('getId')->will($this->returnValue('blank'));
     $this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme));
     $this->httpContext->expects($this->once())->method('getValue')->will($this->returnValue('context_group'));
     $this->productsList->setData('conditions', 'some_serialized_conditions');
     $this->request->expects($this->once())->method('getParam')->with('np')->will($this->returnValue(1));
     $cacheKey = ['CATALOG_PRODUCTS_LIST_WIDGET', 1, 'blank', 'context_group', 1, 5, 'some_serialized_conditions'];
     $this->assertEquals($cacheKey, $this->productsList->getCacheKeyInfo());
 }
Exemplo n.º 24
0
 protected function setUp()
 {
     $this->_storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->disableOriginalConstructor()->getMock();
     $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->_areaListMock = $this->getMock('Magento\\Framework\\App\\AreaList', [], [], '', false);
     $this->_configScopeMock = $this->getMock('Magento\\Framework\\Config\\ScopeInterface');
     $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock));
     $this->_requestMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Soap\\Request')->disableOriginalConstructor()->getMock();
     $this->_domDocumentFactory = $this->getMockBuilder('Magento\\Framework\\DomDocument\\Factory')->disableOriginalConstructor()->getMock();
     $this->_soapServerFactory = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Server\\Factory')->disableOriginalConstructor()->getMock();
     $this->_typeProcessor = $this->getMock('Magento\\Framework\\Reflection\\TypeProcessor', [], [], '', false);
     $this->_configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     parent::setUp();
 }
Exemplo n.º 25
0
 public function testStop()
 {
     // Test data
     $initArea = 'initial area';
     $initTheme = 'initial design theme';
     $initLocale = 'initial locale code';
     $initialStore = 1;
     $initTranslateInline = false;
     $this->inlineTranslationMock->expects($this->once())->method('isEnabled')->willReturn($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('getArea')->willReturn($initArea);
     $this->viewDesignMock->expects($this->once())->method('getDesignTheme')->willReturn($initTheme);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore);
     $this->localeResolverMock->expects($this->once())->method('getLocaleCode')->willReturn($initLocale);
     $this->model->storeCurrentEnvironmentInfo();
     // Expectations
     $this->inlineTranslationMock->expects($this->once())->method('resume')->with($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('setDesignTheme')->with($initTheme, $initArea);
     $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with($initialStore);
     $this->localeResolverMock->expects($this->once())->method('setLocaleCode')->with($initLocale);
     $this->translateMock->expects($this->once())->method('setLocale')->with($initLocale);
     $this->translateMock->expects($this->once())->method('loadData')->with($initArea);
     // Test
     $this->model->stopEnvironmentEmulation();
 }
Exemplo n.º 26
0
 public function testGetOptionsByIds()
 {
     $optionsIds = [1, 2, 3];
     $usedOptionsIds = [4, 5, 6];
     $productId = 3;
     $storeId = 2;
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $usedOptionsMock = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Option\\Collection')->setMethods(['getResourceCollection'])->disableOriginalConstructor()->getMock();
     $dbResourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Collection\\AbstractCollection')->setMethods(['setProductIdFilter', 'setPositionOrder', 'joinValues', 'setIdFilter'])->disableOriginalConstructor()->getMock();
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $productMock->expects($this->at(0))->method('getData')->with('_cache_instance_used_options')->will($this->returnValue(null));
     $productMock->expects($this->at(1))->method('getData')->with('_cache_instance_used_options_ids')->will($this->returnValue($usedOptionsIds));
     $productMock->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($usedOptionsMock));
     $usedOptionsMock->expects($this->once())->method('getResourceCollection')->will($this->returnValue($dbResourceMock));
     $dbResourceMock->expects($this->once())->method('setProductIdFilter')->with($productId)->will($this->returnSelf());
     $dbResourceMock->expects($this->once())->method('setPositionOrder')->will($this->returnSelf());
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $dbResourceMock->expects($this->once())->method('joinValues')->will($this->returnSelf());
     $dbResourceMock->expects($this->once())->method('setIdFilter')->with($optionsIds)->will($this->returnSelf());
     $productMock->expects($this->at(3))->method('setData')->with('_cache_instance_used_options', $dbResourceMock)->will($this->returnSelf());
     $productMock->expects($this->at(4))->method('setData')->with('_cache_instance_used_options_ids', $optionsIds)->will($this->returnSelf());
     $this->model->getOptionsByIds($optionsIds, $productMock);
 }
Exemplo n.º 27
0
 protected function setUp()
 {
     $this->storeManagerInterface = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface');
     $this->requestInterface = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->rssBuilderInterface = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface');
     $this->urlBuilderInterface = $this->getMock('Magento\\Framework\\UrlInterface');
     $this->scopeConfigInterface = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->timezoneInterface = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->discounts = $this->getMock('Magento\\SalesRule\\Model\\Rss\\Discounts', [], [], '', false);
     $this->rssModel = $this->getMock('Magento\\SalesRule\\Model\\Rss\\Discounts', ['__wakeup', 'getDiscountCollection'], [], '', false);
     $this->storeModel = $this->getMock('Magento\\Store\\Model\\Store', ['__wakeUp', 'getId', 'getWebsiteId', 'getName', 'getFrontendName'], [], '', false);
     $this->storeManagerInterface->expects($this->any())->method('getStore')->will($this->returnValue($this->storeModel));
     $this->storeModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->block = $this->objectManagerHelper->getObject('Magento\\SalesRule\\Block\\Rss\\Discounts', ['storeManager' => $this->storeManagerInterface, 'rssModel' => $this->discounts, 'rssUrlBuilder' => $this->rssBuilderInterface, 'urlBuilder' => $this->urlBuilderInterface, 'request' => $this->requestInterface, 'scopeConfig' => $this->scopeConfigInterface, 'rssModel' => $this->rssModel, 'localeDate' => $this->timezoneInterface]);
 }
Exemplo n.º 28
0
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->category = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->setMethods(['getId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->setMethods(['registry'])->disableOriginalConstructor()->getMock();
     $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getRootCategoryId', 'getFilters', '__wakeup'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->storeManager = $this->getMockBuilder('Magento\\Framework\\Store\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->stateKeyGenerator = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\StateKey')->setMethods(['toString'])->disableOriginalConstructor()->getMock();
     $this->collectionFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\CollectionFilter')->setMethods(['filter'])->disableOriginalConstructor()->getMock();
     $this->collectionProvider = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ItemCollectionProviderInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->filter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\Item')->setMethods(['getFilter', 'getValueString'])->disableOriginalConstructor()->getMock();
     $this->abstractFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\AbstractFilter')->setMethods(['getRequestVar'])->disableOriginalConstructor()->getMock();
     $this->context = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ContextInterface')->setMethods(['getStateKey', 'getCollectionFilter'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->context->expects($this->any())->method('getStateKey')->will($this->returnValue($this->stateKeyGenerator));
     $this->context->expects($this->any())->method('getCollectionFilter')->will($this->returnValue($this->collectionFilter));
     $this->context->expects($this->any())->method('getCollectionProvider')->will($this->returnValue($this->collectionProvider));
     $this->state = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->getMock();
     $this->stateFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\StateFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->stateFactory->expects($this->any())->method('create')->will($this->returnValue($this->state));
     $this->collection = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $this->categoryRepository = $this->getMock('Magento\\Catalog\\Api\\CategoryRepositoryInterface');
     $this->currentCategory = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId', '__wakeup'], [], '', false);
     $this->model = $helper->getObject('Magento\\Catalog\\Model\\Layer', ['registry' => $this->registry, 'storeManager' => $this->storeManager, 'context' => $this->context, 'layerStateFactory' => $this->stateFactory, 'categoryRepository' => $this->categoryRepository]);
 }
Exemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function postToConsumer($consumerId, $endpointUrl)
 {
     try {
         $consumer = $this->_consumerFactory->create()->load($consumerId);
         if (!$consumer->getId()) {
             throw new \Magento\Framework\Oauth\Exception(__('A consumer with ID %1 does not exist', $consumerId), OauthInterface::ERR_PARAMETER_REJECTED);
         }
         $consumerData = $consumer->getData();
         $verifier = $this->_tokenFactory->create()->createVerifierToken($consumerId);
         $storeBaseUrl = $this->_storeManager->getStore()->getBaseUrl();
         $this->_httpClient->setUri($endpointUrl);
         $this->_httpClient->setParameterPost(['oauth_consumer_key' => $consumerData['key'], 'oauth_consumer_secret' => $consumerData['secret'], 'store_base_url' => $storeBaseUrl, 'oauth_verifier' => $verifier->getVerifier()]);
         $maxredirects = $this->_dataHelper->getConsumerPostMaxRedirects();
         $timeout = $this->_dataHelper->getConsumerPostTimeout();
         $this->_httpClient->setConfig(['maxredirects' => $maxredirects, 'timeout' => $timeout]);
         $this->_httpClient->request(\Magento\Framework\HTTP\ZendClient::POST);
         return $verifier->getVerifier();
     } catch (\Magento\Framework\Model\Exception $exception) {
         throw $exception;
     } catch (\Magento\Framework\Oauth\Exception $exception) {
         throw $exception;
     } catch (\Exception $exception) {
         $this->_logger->critical($exception);
         throw new \Magento\Framework\Oauth\Exception('Unable to post data to consumer due to an unexpected error');
     }
 }
Exemplo n.º 30
0
 /**
  * Run test toOptionIdArray method
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testToOptionIdArray()
 {
     $itemsByPageId = array_fill(0, 4, 123);
     $data = ['item1' => ['test' => 'test'], 'item2' => ['test' => 'test'], 'item3' => ['test' => 'test'], 'item4' => ['test' => 'test']];
     $objectMock = $this->getMock('Magento\\Framework\\Object', ['getData', 'getId', 'setData', 'getTitle', 'getIdentifier'], [], '', false);
     $criteriaMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CriteriaInterface');
     $connectionMock = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getTable']);
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $storeMock = $this->getMock('Magento\\Store\\Model\\Store', ['getCode'], [], '', false);
     $this->queryMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->searchResultProcessorMock->expects($this->once())->method('getColumnValues')->with('page_id')->will($this->returnValue($itemsByPageId));
     $this->queryMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id_field_name'));
     $objectMock->expects($this->any())->method('getData')->will($this->returnValueMap([['id_field_name', null, null], ['page_id', null, 123]]));
     $this->entityFactoryMock->expects($this->any())->method('create')->with('Magento\\Cms\\Model\\Page', ['data' => ['test' => 'test']])->will($this->returnValue($objectMock));
     $this->queryMock->expects($this->once())->method('getCriteria')->will($this->returnValue($criteriaMock));
     $criteriaMock->expects($this->once())->method('getPart')->with('first_store_flag')->will($this->returnValue(true));
     $this->queryMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->queryMock->expects($this->once())->method('getResource')->will($this->returnValue($resourceMock));
     $connectionMock->expects($this->once())->method('select')->will($this->returnValue($selectMock));
     $selectMock->expects($this->once())->method('from')->with(['cps' => 'query_table'])->will($this->returnSelf());
     $resourceMock->expects($this->once())->method('getTable')->with('cms_page_store')->will($this->returnValue('query_table'));
     $selectMock->expects($this->once())->method('where')->with('cps.page_id IN (?)', array_fill(0, 4, 123))->will($this->returnSelf());
     $connectionMock->expects($this->once())->method('fetchPairs')->with($selectMock)->will($this->returnValue([123 => 999]));
     $objectMock->expects($this->any())->method('getId')->will($this->returnValue(123));
     $this->storeManagerMock->expects($this->any())->method('getStore')->with(999)->will($this->returnValue($storeMock));
     $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code'));
     $objectMock->expects($this->any())->method('setData');
     $objectMock->expects($this->any())->method('getTitle')->will($this->returnValue('item-value'));
     $objectMock->expects($this->any())->method('getIdentifier')->will($this->returnValue('identifier-value'));
     $expected = [['value' => 'identifier-value', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value']];
     $this->assertEquals($expected, $this->collection->toOptionIdArray());
 }