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]); }
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]); }
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']); }
public function testSetNotIntStoreId() { $this->_storeManagerInterface->expects($this->once())->method('getStore'); $store = $this->_model->setStoreId('test'); $storeId = $store->getStoreId(); $this->assertEquals(0, $storeId); }
/** * @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); }
/** * 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()); }
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); }
/** * @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); }
/** * 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)); }
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)); }
/** * @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); }
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()); }
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)); }
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()); }
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); }
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()); }
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(); }
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')); }
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]); }
/** * 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()); }
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(); }
protected function setUp() { $this->context = $this->getMock('\\Magento\\Framework\\Model\\Context', ['getEventDispatcher'], [], '', false); $this->registry = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false); $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getId', '__wakeup'], [], '', false); $store->expects($this->any())->method('getId')->willReturn($this->storeId); $this->storeManager = $this->getMockForAbstractClass('Magento\\Framework\\Store\\StoreManagerInterface', ['getStore']); $this->storeManager->expects($this->any())->method('getStore')->willReturn($store); $this->stockConfiguration = $this->getMock('\\Magento\\CatalogInventory\\Api\\StockConfigurationInterface', [], [], '', false); $this->stockItemRepository = $this->getMockForAbstractClass('\\Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface'); $this->resource = $this->getMock('Magento\\CatalogInventory\\Model\\Resource\\Stock\\Item', [], [], '', false); $this->resourceCollection = $this->getMock('Magento\\CatalogInventory\\Model\\Resource\\Stock\\Item\\Collection', [], [], '', false); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->item = $this->objectManagerHelper->getObject('Magento\\CatalogInventory\\Model\\Stock\\Item', ['context' => $this->context, 'registry' => $this->registry, 'customerSession' => $this->customerSession, 'storeManager' => $this->storeManager, 'stockConfiguration' => $this->stockConfiguration, 'stockItemRepository' => $this->stockItemRepository, 'resource' => $this->resource, 'stockItemRegistry' => $this->resourceCollection]); }
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]); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPrepareJsonAttributes() { $options = []; $attributeId = 1; $attributeCode = 'test_attribute'; $attributeLabel = 'Test'; $pricingValue = 100; $amount = 120; $modifiedValue = 140; $valueIndex = 2; $optionId = 1; $expected = ['priceOptions' => [$attributeId => ['id' => $attributeId, 'code' => $attributeCode, 'label' => $attributeLabel, 'options' => [0 => ['id' => $valueIndex, 'label' => $attributeLabel, 'prices' => ['oldPrice' => ['amount' => $modifiedValue], 'basePrice' => ['amount' => $pricingValue], 'finalPrice' => ['amount' => $modifiedValue]], 'products' => []]]]], 'defaultValues' => [$attributeId => $optionId]]; $attributePrices = [['is_percent' => false, 'pricing_value' => $pricingValue, 'value_index' => $valueIndex, 'label' => $attributeLabel]]; $configurableAttributes = [$this->getAttributeMock($attributeId, $attributeCode, $attributeLabel, $attributePrices)]; $configuredValueMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock(); $configuredValueMock->expects($this->any())->method('getData')->will($this->returnValue($optionId)); $configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock(); $configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue($configurableAttributes)); $this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($configurableProduct)); $this->saleableItemMock->expects($this->any())->method('setParentId'); $this->saleableItemMock->expects($this->any())->method('hasPreconfiguredValues')->will($this->returnValue(true)); $this->saleableItemMock->expects($this->any())->method('getPreconfiguredValues')->will($this->returnValue($configuredValueMock)); $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo($pricingValue), $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount)); $this->calculatorMock->expects($this->any())->method('getAmount')->will($this->returnValue($this->getModifiedAmountMock($modifiedValue, $pricingValue))); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); // don't do any actual conversions; just return whatever was passed in $this->priceCurrency->expects($this->any())->method('convertAndRound')->will($this->returnArgument(0)); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $result = $this->attribute->prepareAttributes($options); $this->assertEquals($expected, $result); }
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); }
/** * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore */ public function testIsThemeAssignedToDefaultStore() { $this->_storeManager->expects($this->once())->method('getStores')->will($this->returnValue([$this->_getStore()])); $this->_designPackage->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue($this->_getAssignedTheme()->getId())); $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(\Magento\Framework\App\Area::AREA_FRONTEND)->will($this->returnValue([$this->_getAssignedTheme(), $this->_getUnassignedTheme()])); $themeAssigned = $this->_model->isThemeAssignedToStore($this->_getAssignedTheme()); $this->assertEquals(true, $themeAssigned); }
protected function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->request->expects($this->any())->method('getParam')->with('store_id')->will($this->returnValue(null)); $this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false); $this->imageHelper = $this->getMock('Magento\\Catalog\\Helper\\Image', [], [], '', false); $this->newProducts = $this->getMock('Magento\\Catalog\\Model\\Rss\\Product\\NewProducts', [], [], '', false); $this->rssUrlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface'); $this->scopeConfig = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $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->objectManagerHelper = new ObjectManagerHelper($this); $this->block = $this->objectManagerHelper->getObject('Magento\\Catalog\\Block\\Rss\\Product\\NewProducts', ['request' => $this->request, 'imageHelper' => $this->imageHelper, 'rssModel' => $this->newProducts, 'rssUrlBuilder' => $this->rssUrlBuilder, 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig]); }
public function setUp() { $this->registry = $this->getMock('Magento\\Framework\\Registry'); $this->sessionManagerInterface = $this->getMock('Magento\\Framework\\Session\\SessionManagerInterface'); $this->storeManagerInterface = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface'); $this->header = $this->getMock('Magento\\Framework\\HTTP\\Header', [], [], '', false); $this->remoteAddress = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\RemoteAddress', [], [], '', false); $this->serverAddress = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\ServerAddress', [], [], '', false); $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime'); $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false, false); $this->storeManagerInterface->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->resource = $this->getMockBuilder('Magento\\Customer\\Model\\Resource\\Visitor')->setMethods(['beginTransaction', '__sleep', '__wakeup', 'getIdFieldName', 'save', 'addCommitCallback', 'commit'])->disableOriginalConstructor()->getMock(); $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('visitor_id')); $this->resource->expects($this->any())->method('addCommitCallback')->will($this->returnSelf()); $objectManagerHelper = new ObjectManagerHelper($this); $arguments = $objectManagerHelper->getConstructArguments('Magento\\Log\\Model\\Visitor', ['registry' => $this->registry, 'session' => $this->sessionManagerInterface, 'storeManager' => $this->storeManagerInterface, 'httpHeader' => $this->header, 'remoteAddress' => $this->remoteAddress, 'serverAddress' => $this->serverAddress, 'dateTime' => $this->dateTime, 'resource' => $this->resource]); $this->visitor = $objectManagerHelper->getObject('Magento\\Log\\Model\\Visitor', $arguments); }
protected function setUp() { $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer\\Factory')->disableOriginalConstructor()->getMock(); $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->getMock(); $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock)); $this->_tokenFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\TokenFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->getMock(); $this->_tokenFactory->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock)); $this->_storeManagerMock = $this->getMockBuilder('Magento\\Framework\\Store\\StoreManagerInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock)); $this->_dataHelper = $this->getMockBuilder('Magento\\Integration\\Helper\\Oauth\\Data')->disableOriginalConstructor()->getMock(); $oauthHelperMock = $this->getMockBuilder('Magento\\Framework\\Oauth\\Helper\\Oauth')->disableOriginalConstructor()->getMock(); $tokenProviderMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Provider')->disableOriginalConstructor()->getMock(); $this->_httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->getMock(); $this->_loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $this->_oauthService = new \Magento\Integration\Service\V1\Oauth($this->_storeManagerMock, $this->_consumerFactory, $this->_tokenFactory, $this->_dataHelper, $this->_httpClientMock, $this->_loggerMock, $oauthHelperMock, $tokenProviderMock); }
public function testGetProductsCollection() { $storeId = 1; $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($store)); $websiteId = 1; $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Collection', [], [], '', false); $this->product->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollection)); $customerGroupId = 1; $productCollection->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addPriceData')->with($storeId, $customerGroupId)->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $products = $this->special->getProductsCollection($storeId, $customerGroupId); $this->assertEquals($productCollection, $products); }