public function testSyncRemove()
 {
     $this->eventObserverMock->expects($this->once())->method('getDataObject')->willReturn($this->salesModelMock);
     $this->salesModelMock->expects($this->once())->method('getId')->willReturn('sales-id-value');
     $this->gridAggregatorMock->expects($this->once())->method('purge')->with('sales-id-value');
     $this->unit->execute($this->eventObserverMock);
 }
 protected function setUp()
 {
     $this->_observer = $this->getMock('Magento\\Framework\\Event\\Observer', array(), array(), '', false);
     $this->_testModel = new \Magento\RecurringPayment\Model\Observer\AddFormExcludedAttribute();
     $this->_event = $this->getMock('Magento\\Framework\\Event', array('getProductElement', 'getProduct', 'getResult', 'getBuyRequest', 'getQuote', 'getApi', 'getObject'), array(), '', false);
     $this->_observer->expects($this->any())->method('getEvent')->will($this->returnValue($this->_event));
 }
 /**
  * @param bool $cacheState
  * @param bool $varnishIsEnabled
  * @param bool $scopeIsPrivate
  * @param int|null $blockTtl
  * @param string $expectedOutput
  * @dataProvider processLayoutRenderDataProvider
  */
 public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
 {
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false);
     $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
     $eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock));
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     if ($cacheState) {
         $eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
         $eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
         $this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
         $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
         $this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
         $this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock));
         if ($varnishIsEnabled) {
             $this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl));
             $this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
         }
         if ($scopeIsPrivate) {
             $this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName'));
             $this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate));
         }
         $this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
     }
     $this->_model->execute($this->_observerMock);
     $this->assertEquals($expectedOutput, $this->_transport['output']);
 }
 protected function setUp()
 {
     $this->stockHelper = $this->getMock('Magento\\CatalogInventory\\Helper\\Stock', [], [], '', false);
     $this->event = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getProduct'])->getMock();
     $this->eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods(['getEvent'])->getMock();
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\CatalogInventory\\Observer\\AddInventoryDataObserver', ['stockHelper' => $this->stockHelper]);
 }
 public function testSyncInsert()
 {
     $this->eventObserverMock->expects($this->once())->method('getObject')->willReturn($this->salesModelMock);
     $this->salesModelMock->expects($this->once())->method('getId')->willReturn('sales-id-value');
     $this->scopeConfigurationMock->expects($this->once())->method('getValue')->with('dev/grid/async_indexing', 'default', null)->willReturn(false);
     $this->gridAggregatorMock->expects($this->once())->method('refresh')->with('sales-id-value');
     $this->unit->execute($this->eventObserverMock);
 }
 protected function setUp()
 {
     $this->resourceStock = $this->getMock('Magento\\CatalogInventory\\Model\\ResourceModel\\Stock', [], [], '', false);
     $this->event = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getWebsite'])->getMock();
     $this->eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods(['getEvent'])->getMock();
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\CatalogInventory\\Observer\\UpdateItemsStockUponConfigChangeObserver', ['resourceStock' => $this->resourceStock]);
 }
 protected function setUp()
 {
     $this->subtractQuoteInventoryObserver = $this->getMock('Magento\\CatalogInventory\\Observer\\SubtractQuoteInventoryObserver', [], [], '', false);
     $this->reindexQuoteInventoryObserver = $this->getMock('Magento\\CatalogInventory\\Observer\\ReindexQuoteInventoryObserver', [], [], '', false);
     $this->event = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getProduct', 'getCollection', 'getCreditmemo', 'getQuote', 'getWebsite'])->getMock();
     $this->eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods(['getEvent'])->getMock();
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\CatalogInventory\\Observer\\CheckoutAllSubmitAfterObserver', ['subtractQuoteInventoryObserver' => $this->subtractQuoteInventoryObserver, 'reindexQuoteInventoryObserver' => $this->reindexQuoteInventoryObserver]);
 }
 /**
  * @dataProvider dataAddFields
  */
 public function testAddFields($expected)
 {
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($expected['isOutputEnabled']);
     $this->eventObserverMock->expects($this->exactly($expected['methods_count']))->method('getForm')->willReturn($this->formMock);
     $element = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false);
     $this->formMock->expects($this->exactly($expected['methods_count']))->method('getElement')->with('base_fieldset')->willReturn($element);
     $element->expects($this->exactly($expected['addField_count']))->method('addField');
     $this->yesNoMock->expects($this->exactly($expected['yesno_count']))->method('toOptionArray');
     $this->observerMock->execute($this->eventObserverMock);
 }
 public function setUp()
 {
     $this->mockSymbolFactory = $this->getMock('Magento\\CurrencySymbol\\Model\\System\\CurrencysymbolFactory', ['create'], [], '', false);
     $this->mockSymbol = $this->getMock('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol', ['getCurrencySymbol'], [], '', false);
     $this->mockEventObserver = $this->getMock('Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->mockEvent = $this->getMock('Magento\\Framework\\Event', ['getBaseCode', 'getCurrencyOptions'], [], '', false);
     $this->mockEventObserver->expects($this->any())->method('getEvent')->willReturn($this->mockEvent);
     $this->mockSymbolFactory->expects($this->any())->method('create')->willReturn($this->mockSymbol);
     $this->observer = new \Magento\CurrencySymbol\Observer\CurrencyDisplayOptions($this->mockSymbolFactory);
 }
 /**
  * @covers \Magento\Cms\Observer\NoRouteObserver::execute
  */
 public function testNoRoute()
 {
     $this->observerMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($this->eventMock);
     $this->eventMock->expects($this->atLeastOnce())->method('getStatus')->willReturn($this->objectMock);
     $this->objectMock->expects($this->atLeastOnce())->method('setLoaded')->with(true)->willReturnSelf();
     $this->objectMock->expects($this->atLeastOnce())->method('setForwardModule')->with('cms')->willReturnSelf();
     $this->objectMock->expects($this->atLeastOnce())->method('setForwardController')->with('index')->willReturnSelf();
     $this->objectMock->expects($this->atLeastOnce())->method('setForwardAction')->with('noroute')->willReturnSelf();
     $this->assertEquals($this->noRouteObserver, $this->noRouteObserver->execute($this->observerMock));
 }
 /**
  * @dataProvider dataAddSwatch
  */
 public function testAddSwatchAttributeType($exp)
 {
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($exp['isOutputEnabled']);
     $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getResponse'], [], '', false);
     $this->eventObserverMock->expects($this->exactly($exp['methods_count']))->method('getEvent')->willReturn($eventMock);
     $response = $this->getMock('\\Magento\\Framework\\DataObject', ['getTypes'], [], '', false);
     $eventMock->expects($this->exactly($exp['methods_count']))->method('getResponse')->willReturn($response);
     $response->expects($this->exactly($exp['methods_count']))->method('getTypes')->willReturn($exp['outputArray']);
     $this->observerMock->execute($this->eventObserverMock);
 }
 protected function setUp()
 {
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->configMock = $this->getMockBuilder('Magento\\Customer\\Model\\Config\\Share')->disableOriginalConstructor()->getMock();
     $this->quoteRepositoryMock = $this->getMock('\\Magento\\Quote\\Api\\CartRepositoryInterface');
     $this->observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getCustomerDataObject'])->getMock();
     $this->observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->eventMock));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->customerQuote = $objectManager->getObject('Magento\\Quote\\Observer\\Backend\\CustomerQuoteObserver', ['storeManager' => $this->storeManagerMock, 'config' => $this->configMock, 'quoteRepository' => $this->quoteRepositoryMock]);
 }
 protected function setUp()
 {
     $this->stockIndexerProcessor = $this->getMock('Magento\\CatalogInventory\\Model\\Indexer\\Stock\\Processor', ['reindexList'], [], '', false);
     $this->stockManagement = $this->getMock('Magento\\CatalogInventory\\Model\\StockManagement', [], [], '', false);
     $this->stockConfiguration = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockConfigurationInterface', ['isAutoReturnEnabled', 'isDisplayProductStockStatus'], '', false);
     $this->priceIndexer = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Product\\Price\\Processor')->disableOriginalConstructor()->getMock();
     $this->event = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getProduct', 'getCollection', 'getCreditmemo', 'getQuote', 'getWebsite'])->getMock();
     $this->eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods(['getEvent'])->getMock();
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\CatalogInventory\\Observer\\RefundOrderInventoryObserver', ['stockConfiguration' => $this->stockConfiguration, 'stockManagement' => $this->stockManagement, 'stockIndexerProcessor' => $this->stockIndexerProcessor, 'priceIndexer' => $this->priceIndexer]);
 }
 /**
  * Set up all mocks and data for test
  */
 public function setUp()
 {
     $this->configMock = $this->getMock('Magento\\PageCache\\Model\\Config', ['getType', 'isEnabled'], [], '', false);
     $this->typeListMock = $this->getMock('Magento\\Framework\\App\\Cache\\TypeList', [], [], '', false);
     $this->model = new \Magento\PageCache\Observer\InvalidateCacheIfChanged($this->configMock, $this->typeListMock);
     $this->observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false);
     $this->objectMock = $this->getMockForAbstractClass('Magento\\Framework\\DataObject\\IdentityInterface', [], '', false);
     $eventMock->expects($this->any())->method('getObject')->willReturn($this->objectMock);
     $this->observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock);
 }
示例#15
0
 protected function setUp()
 {
     $this->_observer = $this->getMock('Magento\\Framework\\Event\\Observer', array(), array(), '', false);
     $this->_fieldsBlock = $this->getMock('\\Magento\\RecurringPayment\\Block\\Fields', array('getFieldLabel'), array(), '', false);
     $this->_recurringPaymentFactory = $this->getMock('\\Magento\\RecurringPayment\\Model\\RecurringPaymentFactory', array('create'), array(), '', false);
     $this->_paymentFactory = $this->getMock('\\Magento\\RecurringPayment\\Model\\PaymentFactory', array('create', 'importProduct'), array(), '', false);
     $helper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_testModel = $helper->getObject('Magento\\RecurringPayment\\Model\\Observer', array('recurringPaymentFactory' => $this->_recurringPaymentFactory, 'fields' => $this->_fieldsBlock, 'paymentFactory' => $this->_paymentFactory));
     $this->_event = $this->getMock('Magento\\Framework\\Event', array('getProductElement', 'getProduct', 'getResult', 'getBuyRequest', 'getQuote', 'getApi', 'getObject'), array(), '', false);
     $this->_observer->expects($this->any())->method('getEvent')->will($this->returnValue($this->_event));
     $this->_payment = $this->getMock('Magento\\RecurringPayment\\Model\\Payment', array('__sleep', '__wakeup', 'isValid', 'importQuote', 'importQuoteItem', 'submit', 'getId', 'setMethodCode'), array(), '', false);
 }
 /**
  * @return void
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->urlPersistMock = $this->getMockBuilder(UrlPersistInterface::class)->getMockForAbstractClass();
     $this->cmsPageUrlRewriteGeneratorMock = $this->getMockBuilder(CmsPageUrlRewriteGenerator::class)->disableOriginalConstructor()->getMock();
     $this->pageMock = $this->getMockBuilder(Page::class)->setMethods(['getId', 'dataHasChangedFor'])->disableOriginalConstructor()->getMock();
     $this->eventMock = $this->getMockBuilder(Event::class)->setMethods(['getObject'])->disableOriginalConstructor()->getMock();
     $this->eventObserverMock = $this->getMockBuilder(EventObserver::class)->disableOriginalConstructor()->getMock();
     $this->eventObserverMock->expects($this->once())->method('getEvent')->willReturn($this->eventMock);
     $this->eventMock->expects($this->once())->method('getObject')->willReturn($this->pageMock);
     $this->observer = $this->objectManagerHelper->getObject(ProcessUrlRewriteSavingObserver::class, ['cmsPageUrlRewriteGenerator' => $this->cmsPageUrlRewriteGeneratorMock, 'urlPersist' => $this->urlPersistMock]);
 }
 /**
  * @SuppressWarnings(PHPMD.TooManyFields)
  */
 public function setUp()
 {
     $this->importProduct = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getProductCategories', 'getProductWebsites', 'getStoreIdByCode', 'getCategoryProcessor'], [], '', false);
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->importProduct);
     $this->event->expects($this->any())->method('getBunch')->willReturn($this->products);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->clearProductUrlsObserver = $this->objectManagerHelper->getObject('\\Magento\\CatalogUrlRewrite\\Observer\\ClearProductUrlsObserver', ['urlPersist' => $this->urlPersist]);
 }
示例#18
0
 /**
  * @covers \Magento\Cms\Model\Observer::noCookies
  * @param string $pageUrl
  * @dataProvider noCookiesDataProvider
  */
 public function testNoCookies($pageUrl)
 {
     $pageId = 1;
     $this->observerMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($this->eventMock);
     $this->eventMock->expects($this->atLeastOnce())->method('getRedirect')->willReturn($this->objectMock);
     $this->scopeConfigMock->expects($this->atLeastOnce())->method('getValue')->with('web/default/cms_no_cookies', 'store')->willReturn($pageId);
     $this->cmsPageMock->expects($this->atLeastOnce())->method('getPageUrl')->with($pageId)->willReturn($pageUrl);
     $this->objectMock->expects($this->any())->method('setRedirectUrl')->with($pageUrl)->willReturnSelf();
     $this->objectMock->expects($this->any())->method('setRedirect')->with(true)->willReturnSelf();
     $this->objectMock->expects($this->any())->method('setPath')->with('cms/index/noCookies')->willReturnSelf();
     $this->objectMock->expects($this->any())->method('setArguments')->with([])->willReturnSelf();
     $this->assertEquals($this->this, $this->this->noCookies($this->observerMock));
 }
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->urlPersist = $this->getMock(\Magento\UrlRewrite\Model\UrlPersistInterface::class, [], [], '', false);
     $this->product = $this->getMock(\Magento\Catalog\Model\Product::class, ['getId', 'dataHasChangedFor', 'isVisibleInSiteVisibility', 'getIsChangedWebsites', 'getIsChangedCategories', 'getStoreId'], [], '', false);
     $this->product->expects($this->any())->method('getId')->will($this->returnValue(3));
     $this->event = $this->getMock(\Magento\Framework\Event::class, ['getProduct'], [], '', false);
     $this->event->expects($this->any())->method('getProduct')->willReturn($this->product);
     $this->observer = $this->getMock(\Magento\Framework\Event\Observer::class, ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->productUrlRewriteGenerator = $this->getMock(\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::class, ['generate'], [], '', false);
     $this->productUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([3 => 'rewrite']));
     $this->objectManager = new ObjectManager($this);
     $this->model = $this->objectManager->getObject(\Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver::class, ['productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, 'urlPersist' => $this->urlPersist]);
 }
示例#20
0
 protected function setUp()
 {
     $this->stockItemRegistry = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Stock\\ItemRegistry')->disableOriginalConstructor()->getMock();
     $this->stockStatus = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Stock\\Status')->disableOriginalConstructor()->getMock();
     $this->stockFactory = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\StockFactory')->setMethods(['create'])->getMock();
     $this->catalogInventoryData = $this->getMock('Magento\\CatalogInventory\\Helper\\Data', [], [], '', false);
     $this->stock = $this->getMock('Magento\\CatalogInventory\\Model\\Stock', [], [], '', false);
     $this->stockIndexProcessor = $this->getMock('\\Magento\\Catalog\\Model\\Indexer\\Product\\Stock\\Processor', [], [], '', false);
     $this->priceIndexer = $this->getMock('\\Magento\\Catalog\\Model\\Indexer\\Product\\Price\\Processor', [], [], '', false);
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->model = $objectManagerHelper->getObject('Magento\\CatalogInventory\\Model\\Observer', ['stockItemRegistry' => $this->stockItemRegistry, 'stockStatus' => $this->stockStatus, 'stockFactory' => $this->stockFactory]);
     $this->event = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getProduct', 'getCollection', 'getCreditmemo'])->getMock();
     $this->eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods(['getEvent'])->getMock();
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
 }
 protected function setUp()
 {
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->orderMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false);
     $this->orderSenderMock = $this->getMock('Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderSender', [], [], '', false);
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getQuote', 'getOrder'])->getMock();
     $this->observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock);
     $eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock);
     $this->model = new \Magento\Quote\Observer\Webapi\SubmitObserver($this->loggerMock, $this->orderSenderMock);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.TooManyFields)
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function setUp()
 {
     $this->importProduct = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getProductCategories', 'getProductWebsites', 'getStoreIdByCode', 'getCategoryProcessor'], [], '', false);
     $this->catalogProductFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods(['getWebsite'])->getMockForAbstractClass();
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->importProduct);
     $this->event->expects($this->any())->method('getBunch')->willReturn($this->products);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->productUrlRewriteGenerator = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlRewriteGenerator')->disableOriginalConstructor()->setMethods(['generate'])->getMock();
     $this->productRepository = $this->getMockBuilder('\\Magento\\Catalog\\Api\\ProductRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->objectRegistryFactory = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistryFactory', [], [], '', false);
     $this->productUrlPathGenerator = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlPathGenerator', [], [], '', false);
     $this->storeViewService = $this->getMock('\\Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', [], [], '', false);
     $this->urlRewriteFactory = $this->getMock('\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewriteFactory', ['create'], [], '', false);
     $this->urlFinder = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlFinderInterface')->setMethods(['findAllByData'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->urlRewrite = $this->getMockBuilder('Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->disableOriginalConstructor()->getMock();
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $this->objectRegistry = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistry')->disableOriginalConstructor()->getMock();
     $categoryProcessor = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\CategoryProcessor', ['getCategoryById'], [], '', false);
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId'], [], '', false);
     $category->expects($this->any())->method('getId')->willReturn($this->categoryId);
     $categoryProcessor->expects($this->any())->method('getCategoryById')->with($this->categoryId)->willReturn($category);
     $this->importProduct->expects($this->any())->method('getCategoryProcessor')->willReturn($categoryProcessor);
     $this->objectManager = new ObjectManager($this);
     $this->import = $this->objectManager->getObject('\\Magento\\CatalogUrlRewrite\\Observer\\AfterImportDataObserver', ['catalogProductFactory' => $this->catalogProductFactory, 'objectRegistryFactory' => $this->objectRegistryFactory, 'productUrlPathGenerator' => $this->productUrlPathGenerator, 'storeViewService' => $this->storeViewService, 'storeManager' => $this->storeManager, 'urlPersist' => $this->urlPersist, 'urlRewriteFactory' => $this->urlRewriteFactory, 'urlFinder' => $this->urlFinder]);
 }
 public function testExecute()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true);
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true);
     $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Address');
     $address->setIsDefaultShipping(true);
     $address->setIsDefaultBilling(true);
     $address->setIsPrimaryBilling(true);
     $address->setIsPrimaryShipping(true);
     $address->setCountryId(1);
     $address->setData('postcode', 11111);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->observerMock->expects($this->once())->method('getCustomerAddress')->willReturn($address);
     $this->session->execute($this->observerMock);
 }
示例#24
0
 public function setUp()
 {
     $this->object = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['getOldSku', '_populateToUrlGeneration'], [], '', false);
     $this->adapter->expects($this->any())->method('_populateToUrlGeneration')->willReturn($this->object);
     $this->adapter->expects($this->any())->method('getOldSku')->willReturn(['sku' => ['sku' => 'sku', 'url_key' => 'value1', 'entity_id' => '1'], 'sku2' => ['sku' => 'sku2', 'url_key' => 'value2', 'entity_id' => '2']]);
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->adapter);
     $this->event->expects($this->any())->method('getBunch')->willReturn([['sku' => 'sku', 'url_key' => 'value1'], ['sku' => 'sku3', 'url_key' => 'value3']]);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->productUrlRewriteGenerator = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlRewriteGenerator')->disableOriginalConstructor()->setMethods(['generate'])->getMock();
     $this->productRepository = $this->getMockBuilder('\\Magento\\Catalog\\Api\\ProductRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->import = $this->objectManagerHelper->getObject('\\Magento\\CatalogUrlRewrite\\Model\\Product\\Plugin\\Import', ['urlPersist' => $this->urlPersist, 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, 'productRepository' => $this->productRepository]);
 }
示例#25
0
 public function testExecute()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true);
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->weeeHelperMock->expects($this->any())->method('isEnabled')->willReturn(true);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock();
     $this->observerMock->expects($this->once())->method('getData')->with('customer')->willReturn($customerMock);
     $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address');
     $address->setIsDefaultShipping(true);
     $address->setIsDefaultBilling(true);
     $address->setCountryId(1);
     $address->setPostCode(11111);
     $addresses = [$address];
     $customerMock->expects($this->once())->method('getAddresses')->willReturn($addresses);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->session->execute($this->observerMock);
 }
示例#26
0
 public function testUpdateItemsStockUponConfigChange()
 {
     $websiteId = 1;
     $this->resourceStock->expects($this->once())->method('updateSetOutOfStock')->willReturn(null);
     $this->resourceStock->expects($this->once())->method('updateSetInStock')->willReturn(null);
     $this->resourceStock->expects($this->once())->method('updateLowStockDate')->willReturn(null);
     $this->event->expects($this->once())->method('getWebsite')->will($this->returnValue($websiteId));
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer->updateItemsStockUponConfigChange($this->eventObserver);
 }
 /**
  * @return void
  */
 protected function setUp()
 {
     /** @var Random|MockObject $encryptorRandomGenerator */
     $encryptorRandomGenerator = $this->getMock(Random::class, [], [], '', false);
     /** @var DeploymentConfig|MockObject $deploymentConfigMock */
     $deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
     $this->encryptorModel = new Encryptor($encryptorRandomGenerator, $deploymentConfigMock);
     $this->paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->paymentTokenManagementMock = $this->getMockBuilder(PaymentTokenManagement::class)->setMethods(['saveTokenWithPaymentLink'])->disableOriginalConstructor()->getMock();
     $this->paymentTokenMock = $this->getMockBuilder(PaymentToken::class)->setMethods(null)->disableOriginalConstructor()->getMock();
     $this->paymentExtension->setVaultPaymentToken($this->paymentTokenMock);
     // Sales Order Model
     $this->salesOrderMock = $this->getMock(Order::class, null, [], '', false);
     // Sales Order Payment Model
     $this->salesOrderPaymentMock = $this->getMockBuilder(Payment::class)->setMethods(null)->disableOriginalConstructor()->getMock();
     $this->salesOrderPaymentMock->setOrder($this->salesOrderMock);
     $this->salesOrderPaymentMock->setExtensionAttributes($this->paymentExtension);
     // Arguments to observer container
     $this->eventObserverArgMock = $this->getMockBuilder(Observer::class)->setMethods(['getDataByKey'])->disableOriginalConstructor()->getMock();
     $this->eventObserverArgMock->expects($this->any())->method('getDataByKey')->with(AfterPaymentSaveObserver::PAYMENT_OBJECT_DATA_KEY)->willReturn($this->salesOrderPaymentMock);
     // Observer class
     $this->observer = new AfterPaymentSaveObserver($this->paymentTokenManagementMock, $this->encryptorModel);
 }
示例#28
0
 /**
  * Test case for cache invalidation
  *
  * @dataProvider flushCacheByTagsDataProvider
  * @param $cacheState
  */
 public function testFlushCacheByTags($cacheState)
 {
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     if ($cacheState) {
         $tags = array('cache_1', 'cache_group');
         $expectedTags = array('cache_1', 'cache_group', 'cache');
         $eventMock = $this->getMock('Magento\\Framework\\Event', array('getObject'), array(), '', false);
         $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->_observerObject));
         $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
         $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
         $this->_observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
         $this->_cacheMock->expects($this->once())->method('clean')->with($this->equalTo($expectedTags));
     }
     $this->_model->flushCacheByTags($this->_observerMock);
 }
示例#29
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.TooManyFields)
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function setUp()
 {
     $this->importProduct = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getProductCategories', 'getProductWebsites', 'getStoreIdByCode', 'getCategoryProcessor'], [], '', false);
     $this->catalogProductFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods(['getWebsite'])->getMockForAbstractClass();
     $this->adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->importProduct);
     $this->event->expects($this->any())->method('getBunch')->willReturn($this->products);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->productUrlRewriteGenerator = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlRewriteGenerator')->disableOriginalConstructor()->setMethods(['generate'])->getMock();
     $this->productRepository = $this->getMockBuilder('\\Magento\\Catalog\\Api\\ProductRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->eavConfig = $this->getMock('\\Magento\\Eav\\Model\\Config', ['getAttribute'], [], '', false);
     $attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['getBackendTable'])->disableOriginalConstructor()->getMockForAbstractClass();
     $beTable = 'backend table';
     $attribute->expects($this->any())->method('getBackendTable')->willReturn($beTable);
     $this->eavConfig->expects($this->any())->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::URL_KEY_ATTRIBUTE_CODE)->willReturn($attribute);
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['quoteInto', 'select', 'fetchAll'])->getMockForAbstractClass();
     $this->resource->expects($this->any())->method('getConnection')->with(Resource::DEFAULT_READ_RESOURCE)->willReturn($this->connection);
     $this->select = $this->getMock('\\Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $this->connection->expects($this->any())->method('select')->willReturn($this->select);
     $this->objectRegistryFactory = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistryFactory', [], [], '', false);
     $this->productUrlPathGenerator = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlPathGenerator', [], [], '', false);
     $this->storeViewService = $this->getMock('\\Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', [], [], '', false);
     $this->urlRewriteFactory = $this->getMock('\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewriteFactory', ['create'], [], '', false);
     $this->urlFinder = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlFinderInterface')->setMethods(['findAllByData'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->urlRewrite = $this->getMockBuilder('Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->disableOriginalConstructor()->getMock();
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $this->objectRegistry = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistry')->disableOriginalConstructor()->getMock();
     $categoryProcessor = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\CategoryProcessor', ['getCategoryById'], [], '', false);
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId'], [], '', false);
     $category->expects($this->any())->method('getId')->willReturn($this->categoryId);
     $categoryProcessor->expects($this->any())->method('getCategoryById')->with($this->categoryId)->willReturn($category);
     $this->importProduct->expects($this->any())->method('getCategoryProcessor')->willReturn($categoryProcessor);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->import = $this->objectManagerHelper->getObject('\\Magento\\CatalogUrlRewrite\\Model\\Product\\Plugin\\Import', ['catalogProductFactory' => $this->catalogProductFactory, 'eavConfig' => $this->eavConfig, 'objectRegistryFactory' => $this->objectRegistryFactory, 'productUrlPathGenerator' => $this->productUrlPathGenerator, 'resource' => $this->resource, 'storeViewService' => $this->storeViewService, 'storeManager' => $this->storeManager, 'urlPersist' => $this->urlPersist, 'urlRewriteFactory' => $this->urlRewriteFactory, 'urlFinder' => $this->urlFinder]);
 }
 /**
  * Prepares EventMock with set of methods
  *
  * @param $methodsList
  */
 private function _prepareEventMockWithMethods($methodsList)
 {
     $this->eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods($methodsList)->getMock();
     $this->observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->eventMock));
 }