protected function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('quoteInto')->willReturnCallback(function ($query, $expression) {
         return str_replace('?', $expression, $query);
     });
     $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->resource->method('getTableName')->willReturnCallback(function ($table) {
         return 'prefix_' . $table;
     });
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->website = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\WebsiteInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->website->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->store->expects($this->any())->method('getId')->willReturn(self::STORE_ID);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($this->website);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
     $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory->expects($this->once())->method('create')->willReturn($this->attributeCollection);
     $this->target = $objectManager->getObject('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper', ['resource' => $this->resource, 'storeManager' => $this->storeManager, 'attributeCollectionFactory' => $attributeCollectionFactory]);
     $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMock();
 }
 /**
  * @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);
 }
 public function testSetNotIntStoreId()
 {
     $this->_storeManagerInterface->expects($this->once())->method('getStore');
     $store = $this->_model->setStoreId('test');
     $storeId = $store->getStoreId();
     $this->assertEquals(0, $storeId);
 }
Exemple #4
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\\ResourceModel\\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 testSearch()
 {
     $requestName = 'requestName';
     $storeId = 333;
     $filterField = 'filterField';
     $filterValue = 'filterValue';
     $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->disableOriginalConstructor()->getMock();
     $filter->expects($this->once())->method('getField')->willReturn($filterField);
     $filter->expects($this->once())->method('getValue')->willReturn($filterValue);
     $filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->disableOriginalConstructor()->getMock();
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchCriteriaInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $searchCriteria->expects($this->once())->method('getRequestName')->willReturn($requestName);
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($storeId);
     $searchResult = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchResult')->disableOriginalConstructor()->getMockForAbstractClass();
     $request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $response = $this->getMockBuilder('Magento\\Framework\\Search\\ResponseInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->requestBuilder->expects($this->once())->method('setRequestName')->with($requestName);
     $this->requestBuilder->expects($this->once())->method('bindDimension')->with('scope', $storeId);
     $this->requestBuilder->expects($this->any())->method('bind');
     $this->requestBuilder->expects($this->once())->method('create')->willReturn($request);
     $this->searchEngine->expects($this->once())->method('search')->with($request)->willReturn($response);
     $this->searchResponseBuilder->expects($this->once())->method('build')->with($response)->willReturn($searchResult);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $searchResult = $this->model->search($searchCriteria);
     $this->assertInstanceOf('Magento\\Framework\\Api\\Search\\SearchResultInterface', $searchResult);
 }
 public function testWidgetDirectiveWithoutRequiredVariable()
 {
     $construction = '{{widget type="\\Magento\\Cms\\Block\\Widget\\Page\\Link" page_id="1"}}';
     $this->storeManager->expects($this->never())->method('getStore');
     $result = $this->filter->widgetDirective([0 => $construction, 1 => 'type="\\Magento\\Cms\\Block\\Widget\\Page\\Link" page_id="1"']);
     $this->assertEquals($construction, $result);
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->assignedWebsites = [self::SECOND_WEBSITE_ID];
     $this->websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->secondWebsiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->websiteRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\WebsiteRepositoryInterface')->setMethods(['getList', 'getDefault'])->getMockForAbstractClass();
     $this->websiteRepositoryMock->expects($this->any())->method('getDefault')->willReturn($this->websiteMock);
     $this->websiteRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
     $this->groupRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\GroupRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->storeRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\StoreRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->locatorMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Locator\\LocatorInterface')->setMethods(['getProduct', 'getWebsiteIds'])->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getWebsiteIds')->willReturn($this->assignedWebsites);
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['isSingleStoreMode'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('isSingleStoreMode')->willReturn(false);
     $this->groupMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Group\\Collection')->setMethods(['getId', 'getName', 'getWebsiteId'])->disableOriginalConstructor()->getMock();
     $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn(self::WEBSITE_ID);
     $this->groupMock->expects($this->any())->method('getId')->willReturn(self::GROUP_ID);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->groupMock]);
     $this->storeViewMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getName', 'getId', 'getStoreGroupId'])->disableOriginalConstructor()->getMock();
     $this->storeViewMock->expects($this->any())->method('getName')->willReturn(self::STORE_VIEW_NAME);
     $this->storeViewMock->expects($this->any())->method('getStoreGroupId')->willReturn(self::GROUP_ID);
     $this->storeViewMock->expects($this->any())->method('getId')->willReturn(self::STORE_VIEW_ID);
     $this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->storeViewMock]);
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->secondWebsiteMock->expects($this->any())->method('getId')->willReturn($this->assignedWebsites[0]);
     $this->websiteMock->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
 }
 /**
  * Initialize repository
  */
 public function setUp()
 {
     $this->blockResource = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block')->disableOriginalConstructor()->getMock();
     $this->dataObjectProcessor = $this->getMockBuilder('Magento\\Framework\\Reflection\\DataObjectProcessor')->disableOriginalConstructor()->getMock();
     $blockFactory = $this->getMockBuilder('Magento\\Cms\\Model\\BlockFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $blockDataFactory = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $blockSearchResultFactory = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockSearchResultsInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $collectionFactory = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getId')->willReturn(0);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($store);
     $this->block = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->getMock();
     $this->blockData = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockInterface')->getMock();
     $this->blockSearchResult = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockSearchResultsInterface')->getMock();
     $this->collection = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getSize', 'setCurPage', 'setPageSize', 'load', 'addOrder'])->getMock();
     $blockFactory->expects($this->any())->method('create')->willReturn($this->block);
     $blockDataFactory->expects($this->any())->method('create')->willReturn($this->blockData);
     $blockSearchResultFactory->expects($this->any())->method('create')->willReturn($this->blockSearchResult);
     $collectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
     /**
      * @var \Magento\Cms\Model\BlockFactory $blockFactory
      * @var \Magento\Cms\Api\Data\BlockInterfaceFactory $blockDataFactory
      * @var \Magento\Cms\Api\Data\BlockSearchResultsInterfaceFactory $blockSearchResultFactory
      * @var \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $collectionFactory
      */
     $this->dataHelper = $this->getMockBuilder('Magento\\Framework\\Api\\DataObjectHelper')->disableOriginalConstructor()->getMock();
     $this->repository = new BlockRepository($this->blockResource, $blockFactory, $blockDataFactory, $collectionFactory, $blockSearchResultFactory, $this->dataHelper, $this->dataObjectProcessor, $this->storeManager);
 }
 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\\Store\\Model\\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]);
 }
Exemple #10
0
 public function testGetTreeHasLevelField()
 {
     $rootId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
     $storeGroups = [];
     $storeId = 1;
     $rootLevel = 2;
     $level = 3;
     $this->collection->expects($this->any())->method('addAttributeToSelect')->willReturnMap([['url_key', false, $this->collection], ['is_anchor', false, $this->collection]]);
     $this->childNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($level);
     $this->rootNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($rootLevel);
     $this->rootNode->expects($this->once())->method('hasChildren')->willReturn(true);
     $this->rootNode->expects($this->once())->method('getChildren')->willReturn([$this->childNode]);
     $this->categoryTree->expects($this->once())->method('load')->with(null, 3)->willReturnSelf();
     $this->categoryTree->expects($this->atLeastOnce())->method('addCollectionData')->with($this->collection)->willReturnSelf();
     $this->categoryTree->expects($this->once())->method('getNodeById')->with($rootId)->willReturn($this->rootNode);
     $this->store->expects($this->atLeastOnce())->method('getId')->willReturn($storeId);
     $this->storeManager->expects($this->once())->method('getGroups')->willReturn($storeGroups);
     $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($this->store);
     $this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
     $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
     $this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper);
     $this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
     /** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */
     $chooser = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Widget\\Block\\Adminhtml\\Widget\\Catalog\\Category\\Chooser', ['categoryTree' => $this->categoryTree, 'context' => $this->context]);
     $chooser->setData('category_collection', $this->collection);
     $result = $chooser->getTree();
     $this->assertEquals($level, $result[0]['level']);
 }
 public function testLoadValidOrderNotEmptyPost()
 {
     $post = ['oar_order_id' => 1, 'oar_type' => 'email', 'oar_billing_lastname' => 'oar_billing_lastname', 'oar_email' => 'oar_email', 'oar_zip' => 'oar_zip'];
     $storeId = '1';
     $incrementId = $post['oar_order_id'];
     $protectedCode = 'protectedCode';
     $this->sessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
     $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $requestMock->expects($this->once())->method('getPostValue')->willReturn($post);
     $this->storeManagerInterfaceMock->expects($this->once())->method('getStore')->willReturn($this->storeModelMock);
     $this->storeModelMock->expects($this->once())->method('getId')->willReturn($storeId);
     $this->orderFactoryMock->expects($this->once())->method('create')->willReturn($this->salesOrderMock);
     $this->salesOrderMock->expects($this->once())->method('loadByIncrementIdAndStoreId')->willReturnSelf();
     $this->salesOrderMock->expects($this->any())->method('getId')->willReturn($incrementId);
     $billingAddressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['getLastname', 'getEmail', '__wakeup'], [], '', false);
     $billingAddressMock->expects($this->once())->method('getLastname')->willReturn($post['oar_billing_lastname']);
     $billingAddressMock->expects($this->once())->method('getEmail')->willReturn($post['oar_email']);
     $this->salesOrderMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddressMock);
     $this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
     $metaDataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata', [], [], '', false);
     $metaDataMock->expects($this->once())->method('setPath')->with(Guest::COOKIE_PATH)->willReturnSelf();
     $metaDataMock->expects($this->once())->method('setHttpOnly')->with(true)->willReturnSelf();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($metaDataMock);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(Guest::COOKIE_NAME, $this->anything(), $metaDataMock);
     $this->assertTrue($this->guest->loadValidOrder($requestMock));
 }
Exemple #12
0
 protected function setUp()
 {
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $objectManager = new \Magento\Framework\TestFramework\Unit\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);
 }
 /**
  * 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());
 }
 /**
  * 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 testAfterSaveDispatchWithStore()
 {
     $this->designConfig->expects($this->exactly(2))->method('getScope')->willReturn('store');
     $this->designConfig->expects($this->once())->method('getScopeId')->willReturn(1);
     $this->storeManager->expects($this->once())->method('getStore')->with(1)->willReturn($this->store);
     $this->eventManager->expects($this->once())->method('dispatch')->with('admin_system_config_changed_section_design', ['website' => '', 'store' => $this->store]);
     $this->plugin->afterSave($this->repository, $this->designConfig);
 }
 /**
  * @param int $storeId
  * @param bool $withAdmin
  * @param array $condition
  * @dataProvider dataProviderForTestAddStoreFilterIfStoreIsInt
  * @covers \Magento\UrlRewrite\Model\ResourceModel\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->connectionMock->expects($this->once())->method('prepareSqlCondition')->with('store_id', ['in' => $condition]);
     $this->collection->addStoreFilter($storeId, $withAdmin);
 }
 /**
  * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
  */
 public function testIsThemeAssignedToDefaultStore()
 {
     $this->storeManager->expects($this->once())->method('getStores')->willReturn([$this->getStore()]);
     $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId());
     $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(Area::AREA_FRONTEND)->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]);
     $themeAssigned = $this->model->isThemeAssignedToStore($this->getAssignedTheme());
     $this->assertEquals(true, $themeAssigned);
 }
Exemple #18
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);
 }
 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, ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('.html'));
     $this->assertEquals('category-url-path/product-path.html', $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product, $storeId, $this->category));
 }
 public function testPrepareWithSingleStore()
 {
     $this->storeManagerMock->expects($this->atLeastOnce())->method('isSingleStoreMode')->willReturn(true);
     $this->model->prepare();
     $config = $this->model->getDataByKey('config');
     $this->assertNotEmpty($config);
     $this->assertArrayHasKey('componentDisabled', $config);
     $this->assertTrue($config['componentDisabled']);
 }
 public function testGetRelayUrl()
 {
     $storeId = 10;
     $baseUrl = 'http://base.url/';
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)->willReturn($baseUrl);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
     $this->assertSame('http://base.url/authorizenet/directpost_payment/response', $this->dataHelper->getRelayUrl($storeId));
 }
Exemple #22
0
 public function testGetProductInfo()
 {
     $productId = 3;
     $storeId = 1;
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(['id' => $storeId])));
     $this->requestMock->expects($this->once())->method('getParam')->with('id', false)->willReturn($productId);
     $productMock = $this->getMock('Magento\\Catalog\\Api\\Data\\ProductInterface');
     $this->productRepository->expects($this->once())->method('getById')->with($productId, false, $storeId)->willReturn($productMock);
     $this->assertSame($productMock, $this->object->getProductInfo());
 }
Exemple #23
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());
 }
 public function testGetConfig()
 {
     $loginUrl = 'http://base-url.test/customer/login';
     $baseUrl = 'http://base-url.test';
     $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->with(Url::ROUTE_ACCOUNT_LOGIN)->willReturn($loginUrl);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
     $this->store->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
     $this->scopeConfig->expects($this->once())->method('getValue')->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE)->willReturn(0);
     $this->assertEquals(['customerLoginUrl' => $loginUrl, 'isRedirectRequired' => false, 'autocomplete' => 'off'], $this->provider->getConfig());
 }
 /**
  * @test
  */
 public function itShouldNotConvertWebsiteCodeValues()
 {
     $websiteCode = 'mywebsite';
     $scope = 'websites';
     $websiteId = 3;
     $storeStub = $this->getMockBuilder(WebsiteInterface::class)->getMock();
     $storeStub->expects($this->any())->method('getId')->willReturn($websiteId);
     $this->storeManagerMock->expects($this->once())->method('getWebsite')->with($websiteCode)->willReturn($storeStub);
     $this->assertEquals($websiteId, $this->converter->convert($websiteCode, $scope));
 }
Exemple #26
0
 /**
  * @param array $quoteDetailsData
  * @param array $taxDetailsData
  * @param string $calculateCallback Name of a function within this test class which will be executed to create
  *      a tax details item.
  * @return void
  * @dataProvider calculateTaxProvider
  */
 public function testCalculateTax($quoteDetailsData, $taxDetailsData, $calculateCallback = 'createTaxDetailsItem')
 {
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $calculatorMock = $this->getMockBuilder('\\Magento\\Tax\\Model\\Calculation\\AbstractCalculator')->disableOriginalConstructor()->setMethods(['calculate'])->getMockForAbstractClass();
     $this->calculatorFactory->expects($this->any())->method('create')->will($this->returnValue($calculatorMock));
     $calculatorMock->expects($this->any())->method('calculate')->will($this->returnCallback([$this, $calculateCallback]));
     $quoteDetails = $this->quoteDetailsBuilder->populateWithArray($quoteDetailsData)->create();
     $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails);
     $this->assertEquals($taxDetailsData, $taxDetails->__toArray());
 }
Exemple #27
0
 public function testConvertWithStoreCode()
 {
     $amount = 5.6;
     $storeCode = 2;
     $convertedAmount = 9.300000000000001;
     $currency = $this->getCurrentCurrencyMock();
     $baseCurrency = $this->getBaseCurrencyMock($amount, $convertedAmount, $currency);
     $store = $this->getStoreMock($baseCurrency);
     $this->storeManager->expects($this->once())->method('getStore')->with($storeCode)->will($this->returnValue($store));
     $this->assertEquals($convertedAmount, $this->priceCurrency->convert($amount, $storeCode, $currency));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->productOptionsConfigMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass();
     $this->productOptionsPriceMock = $this->getMockBuilder(ProductOptionsPrice::class)->disableOriginalConstructor()->getMock();
     $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass();
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['getBaseCurrency'])->getMockForAbstractClass();
     $this->priceCurrency = $this->getMockBuilder(PriceCurrencyInterface::class)->disableOriginalConstructor()->getMock();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getBaseCurrency')->willReturn($this->priceCurrency);
 }
Exemple #29
0
 public function testGetCacheKeyInfo()
 {
     $nodeFactory = $this->getMock('Magento\\Framework\\Data\\Tree\\NodeFactory', [], [], '', false);
     $treeFactory = $this->getMock('Magento\\Framework\\Data\\TreeFactory', [], [], '', false);
     $topmenu = new Topmenu($this->context, $nodeFactory, $treeFactory);
     $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn('123');
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getCode'])->getMock();
     $store->expects($this->once())->method('getCode')->willReturn('321');
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $this->assertEquals(['BLOCK_TPL', '321', null, 'template' => null, '123'], $topmenu->getCacheKeyInfo());
 }
 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->getReviews());
 }