/**
  * @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 testAddStockStatusToCollection()
 {
     $productCollection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $this->event->expects($this->once())->method('getCollection')->will($this->returnValue($productCollection));
     $this->stockHelper->expects($this->once())->method('addStockStatusToProducts')->with($productCollection)->will($this->returnSelf());
     $this->observer->execute($this->eventObserver);
 }
 public function testAddInventoryData()
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $this->stockHelper->expects($this->once())->method('assignStatusToProduct')->with($product)->will($this->returnSelf());
     $this->observer->execute($this->eventObserver);
 }
 public function testExecute()
 {
     $block = $this->getMock('Magento\\Backend\\Block\\Template', array('getFormExcludedFieldList', 'setFormExcludedFieldList'), array(), '', false);
     $block->expects($this->once())->method('getFormExcludedFieldList')->will($this->returnValue(array('field')));
     $block->expects($this->once())->method('setFormExcludedFieldList')->with(array('field', 'recurring_payment'));
     $this->_event->expects($this->once())->method('getObject')->will($this->returnValue($block));
     $this->_testModel->execute($this->_observer);
 }
Example #5
0
 /**
  * @param \Magento\Framework\Event $event
  * @return void
  */
 public function observe($event)
 {
     /** @var \Magento\Framework\Data\Form\AbstractForm $form */
     $form = $event->getForm();
     /** @var  $fieldset */
     $fieldset = $form->getElement('advanced_fieldset');
     $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => __('Use To Create Configurable Product'), 'values' => $this->optionList->toOptionArray()));
 }
 public function testCheckoutAllSubmitAfter()
 {
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getInventoryProcessed'], [], '', false);
     $quote->expects($this->once())->method('getInventoryProcessed')->will($this->returnValue(false));
     $this->event->expects($this->once())->method('getQuote')->will($this->returnValue($quote));
     $this->subtractQuoteInventoryObserver->expects($this->once())->method('execute')->with($this->eventObserver);
     $this->reindexQuoteInventoryObserver->expects($this->once())->method('execute')->with($this->eventObserver);
     $this->observer->execute($this->eventObserver);
 }
Example #7
0
 /**
  * @param \Magento\Framework\Event $event
  * @return void
  */
 public function observe($event)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) {
         return;
     }
     /** @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid $grid */
     $grid = $event->getGrid();
     $grid->addColumnAfter('is_filterable', array('header' => __('Use in Layered Navigation'), 'sortable' => true, 'index' => 'is_filterable', 'type' => 'options', 'options' => array('1' => __('Filterable (with results)'), '2' => __('Filterable (no results)'), '0' => __('No')), 'align' => 'center'), 'is_searchable');
 }
 public function testUpdateItemsStockUponConfigChange()
 {
     $websiteId = 1;
     $this->resourceStock->expects($this->once())->method('updateSetOutOfStock');
     $this->resourceStock->expects($this->once())->method('updateSetInStock');
     $this->resourceStock->expects($this->once())->method('updateLowStockDate');
     $this->event->expects($this->once())->method('getWebsite')->will($this->returnValue($websiteId));
     $this->observer->execute($this->eventObserver);
 }
 /**
  * @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));
 }
 public function testUpdateOrderStatusForPaymentMethodsNewState()
 {
     $this->_prepareEventMockWithMethods(['getState', 'getStatus']);
     $this->eventMock->expects($this->once())->method('getState')->will($this->returnValue(\Magento\Sales\Model\Order::STATE_NEW));
     $this->eventMock->expects($this->once())->method('getStatus')->will($this->returnValue(self::ORDER_STATUS));
     $defaultStatus = 'defaultStatus';
     $this->orderConfigMock->expects($this->once())->method('getStateDefaultStatus')->with(\Magento\Sales\Model\Order::STATE_NEW)->will($this->returnValue($defaultStatus));
     $this->paymentConfigMock->expects($this->once())->method('getActiveMethods')->will($this->returnValue($this->_getPreparedActiveMethods()));
     $this->coreResourceConfigMock->expects($this->once())->method('saveConfig')->with('payment/' . self::METHOD_CODE . '/order_status', $defaultStatus, 'default', 0);
     $this->updateOrderStatusForPaymentMethodsObserver->execute($this->observerMock);
 }
 /**
  * @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]);
 }
Example #12
0
 /**
  * @param \Magento\Framework\Event $event
  * @return void
  */
 public function observe($event)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) {
         return;
     }
     /** @var \Magento\Framework\Data\Form\AbstractForm $form */
     $form = $event->getForm();
     $fieldset = $form->getElement('front_fieldset');
     $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => __("Use In Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => __('No')), array('value' => '1', 'label' => __('Filterable (with results)')), array('value' => '2', 'label' => __('Filterable (no results)')))));
     $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => __("Use In Search Results Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $this->optionList->toOptionArray()));
     $fieldset->addField('position', 'text', array('name' => 'position', 'label' => __('Position'), 'title' => __('Position in Layered Navigation'), 'note' => __('Position of attribute in layered navigation block'), 'class' => 'validate-digits'));
 }
 /**
  * @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]);
 }
 public function testSalesOrderBeforeSaveSetForced()
 {
     // check closed state at second
     $this->_prepareEventMockWithMethods(['getOrder']);
     $order = $this->_getPreparedOrderMethod('free', ['canUnhold', 'isCanceled', 'getState', 'setForcedCanCreditmemo', 'hasForcedCanCreditmemo']);
     $this->eventMock->expects($this->once())->method('getOrder')->will($this->returnValue($order));
     $order->expects($this->once())->method('canUnhold')->will($this->returnValue(false));
     $order->expects($this->once())->method('isCanceled')->will($this->returnValue(false));
     $order->expects($this->once())->method('getState')->will($this->returnValue('not_closed_state'));
     $order->expects($this->once())->method('hasForcedCanCreditmemo')->will($this->returnValue(false));
     $order->expects($this->once())->method('setForcedCanCreditmemo')->will($this->returnValue(true));
     $this->salesOrderBeforeSaveObserver->execute($this->observerMock);
 }
Example #15
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]);
 }
 public function testCurrencyDisplayOptions()
 {
     $sampleCurrencyOptionObject = new \Magento\Framework\DataObject();
     $sampleCurrency = 'USD';
     $sampleCurrencySymbol = '$';
     $expectedCurrencyOptions = [\Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol, \Magento\Framework\Locale\Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL];
     //Return invalid value
     $this->mockEvent->expects($this->once())->method('getBaseCode')->willReturn($sampleCurrency);
     $this->mockEvent->expects($this->once())->method('getCurrencyOptions')->willReturn($sampleCurrencyOptionObject);
     $this->mockSymbol->expects($this->once())->method('getCurrencySymbol')->with($sampleCurrency)->willReturn($sampleCurrencySymbol);
     $this->observer->execute($this->mockEventObserver);
     // Check if option set is empty
     $this->assertEquals($expectedCurrencyOptions, $sampleCurrencyOptionObject->getData());
 }
Example #18
0
 /**
  * Builds event body for API
  * @param \Magento\Framework\Event $event
  * @return \Koklu\Event\Model\Event
  */
 public function buildEventBody(\Magento\Framework\Event $event)
 {
     $product = $this->_productResource->getProduct($event->getProduct()->getId(), false);
     // we do not need to send an event if product is disabled or invisible
     $allowedVisibility = [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH];
     if ($product->getStatus() != Status::STATUS_ENABLED || !in_array($product->getVisibility(), $allowedVisibility)) {
         // however if the changes involved status or visibility, then we need to send a delete event
         //            if ($event->getProduct()->dataHasChangedFor('status')
         //                || $event->getProduct()->dataHasChangedFor('visibility')
         //            ) {
         $this->_eventManager->dispatch('koklu_masterdata_not_salable_product_save', ['product' => $product]);
         //            }
         return null;
     }
     return new Event(self::EVENT_SUBJECT, $this->_productBuilder->create($product));
 }
 public function testExecute()
 {
     $payment = $this->getMock('Magento\\Framework\\Object', array('setStory', 'importBuyRequest', 'importProduct', 'exportStartDatetime', 'exportScheduleInfo', 'getFieldLabel'), array(), '', false);
     $payment->expects($this->once())->method('exportStartDatetime')->will($this->returnValue('date'));
     $payment->expects($this->any())->method('setStore')->will($this->returnValue($payment));
     $payment->expects($this->once())->method('importBuyRequest')->will($this->returnValue($payment));
     $payment->expects($this->once())->method('exportScheduleInfo')->will($this->returnValue(array(new \Magento\Framework\Object(array('title' => 'Title', 'schedule' => 'schedule')))));
     $this->_fieldsBlock->expects($this->once())->method('getFieldLabel')->will($this->returnValue('Field Label'));
     $this->_recurringPaymentFactory->expects($this->once())->method('create')->will($this->returnValue($payment));
     $product = $this->getMock('Magento\\Framework\\Object', array('getIsRecurring', 'addCustomOption'), array(), '', false);
     $product->expects($this->once())->method('getIsRecurring')->will($this->returnValue(true));
     $infoOptions = array(array('label' => 'Field Label', 'value' => 'date'), array('label' => 'Title', 'value' => 'schedule'));
     $product->expects($this->at(2))->method('addCustomOption')->with('additional_options', serialize($infoOptions));
     $this->_event->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $this->_testModel->execute($this->_observer);
 }
Example #20
0
 /**
  * @param bool $isWebsiteScope
  * @param array $websites
  * @param int $quoteId
  * @dataProvider dispatchDataProvider
  */
 public function testDispatch($isWebsiteScope, $websites, $quoteId)
 {
     $this->configMock->expects($this->once())->method('isWebsiteScope')->will($this->returnValue($isWebsiteScope));
     $customerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\Data\\Customer')->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\\Service\\V1\\Data\\Customer')->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\Sales\Model\Quote $quoteMock */
     $quoteMock = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->setMethods(array('setWebsite', 'loadByCustomer', 'getId', 'setCustomerGroupId', 'collectTotals', 'save', '__wakeup'))->disableOriginalConstructor()->getMock();
     $websiteCount = count($websites);
     $this->quoteFactoryMock->expects($this->exactly($websiteCount))->method('create')->will($this->returnValue($quoteMock));
     $quoteMock->expects($this->exactly($websiteCount))->method('setWebsite');
     $quoteMock->expects($this->exactly($websiteCount))->method('loadByCustomer');
     $quoteMock->expects($this->exactly($websiteCount))->method('getId')->will($this->returnValue($quoteId));
     if ($quoteId) {
         $quoteMock->expects($this->exactly($websiteCount))->method('setCustomerGroupId');
         $quoteMock->expects($this->exactly($websiteCount))->method('collectTotals');
         $quoteMock->expects($this->exactly($websiteCount))->method('save');
     } else {
         $quoteMock->expects($this->never())->method('setCustomerGroupId');
         $quoteMock->expects($this->never())->method('collectTotals');
         $quoteMock->expects($this->never())->method('save');
     }
     $this->customerQuote->dispatch($this->observerMock);
 }
 /**
  * @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]);
 }
Example #22
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]);
 }
Example #23
0
 protected function _prepareRecurringPayments()
 {
     $product = $this->getMock('Magento\\RecurringPayment\\Model\\Payment', array('getIsRecurring', '__sleep', '__wakeup'), array(), '', false);
     $product->expects($this->any())->method('getIsRecurring')->will($this->returnValue(true));
     $this->_payment = $this->getMock('Magento\\RecurringPayment\\Model\\Payment', array('__sleep', '__wakeup', 'isValid', 'importQuote', 'importQuoteItem', 'submit', 'getId', 'setMethodCode'), array(), '', false);
     $quote = $this->getMock('Magento\\Sales\\Model\\Quote', array('getTotalsCollectedFlag', '__sleep', '__wakeup', 'getAllVisibleItems'), array(), '', false);
     $this->_event->expects($this->any())->method('getQuote')->will($this->returnValue($quote));
 }
 public function testSaveInventoryData()
 {
     $productId = 4;
     $websiteId = 5;
     $stockData = null;
     $websitesChanged = true;
     $statusChanged = true;
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getStockData', 'getIsChangedWebsites', 'dataHasChangedFor', 'getId', 'getStore'], [], '', false);
     $product->expects($this->once())->method('getStockData')->will($this->returnValue($stockData));
     $product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($websitesChanged));
     $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue($statusChanged));
     $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->stockIndex->expects($this->once())->method('rebuild')->will($this->returnValue(true));
     $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $this->observer->execute($this->eventObserver);
 }
Example #25
0
 public function testPreventExpressCheckoutEmpty()
 {
     $this->_customerSession->expects($this->any())->method('isLoggedIn')->will($this->returnValue(false));
     $this->_persistentSession->expects($this->any())->method('isPersistent')->will($this->returnValue(true));
     $this->_event->setControllerAction(null);
     $this->_model->execute($this->_observer);
     $this->_event->setControllerAction(new \StdClass());
     $this->_model->execute($this->_observer);
     $expectedActionName = 'realAction';
     $unexpectedActionName = 'notAction';
     $request = new \Magento\Framework\Object();
     $request->setActionName($unexpectedActionName);
     $expressRedirectMock = $this->getMockBuilder('Magento\\Checkout\\Controller\\Express\\RedirectLoginInterface')->disableOriginalConstructor()->setMethods(['getActionFlagList', 'getResponse', 'getCustomerBeforeAuthUrl', 'getLoginUrl', 'getRedirectActionName', 'getRequest'])->getMock();
     $expressRedirectMock->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $expressRedirectMock->expects($this->any())->method('getRedirectActionName')->will($this->returnValue($expectedActionName));
     $this->_event->setControllerAction($expressRedirectMock);
     $this->_model->execute($this->_observer);
     $expectedAuthUrl = 'expectedAuthUrl';
     $request->setActionName($expectedActionName);
     $this->_url->expects($this->once())->method('getUrl')->will($this->returnValue($expectedAuthUrl));
     $this->_expressRedirectHelper->expects($this->once())->method('redirectLogin')->with($expressRedirectMock, $expectedAuthUrl);
     $this->_model->execute($this->_observer);
 }
Example #26
0
 public function refundOrderInventory()
 {
     $ids = ['1', '14'];
     $items = [];
     foreach ($ids as $id) {
         $items[] = $this->getCreditMemoItem($id);
     }
     $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
     $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue($items));
     $this->event->expects($this->once())->method('getCreditmemo')->will($this->returnValue($creditMemo));
     $this->catalogInventoryData->expects($this->once())->method('isAutoReturnEnabled')->will($this->returnValue(true));
     $this->stock->expects($this->once())->method('revertProductsSale')->with($items);
     $this->stockIndexProcessor->expects($this->once())->method('reidexList')->with($ids);
     $this->model->refundOrderInventory($this->eventObserver);
 }
 public function testRefundOrderInventory()
 {
     $websiteId = 0;
     $ids = ['1', '14'];
     $items = [];
     $isAutoReturnEnabled = true;
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $itemsToUpdate = [];
     foreach ($ids as $id) {
         $item = $this->getCreditMemoItem($id);
         $items[] = $item;
         $itemsToUpdate[$item->getProductId()] = $item->getQty();
     }
     $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
     $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue($items));
     $creditMemo->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->stockConfiguration->expects($this->any())->method('isAutoReturnEnabled')->will($this->returnValue($isAutoReturnEnabled));
     $this->stockManagement->expects($this->once())->method('revertProductsSale')->with($itemsToUpdate, $websiteId);
     $this->stockIndexerProcessor->expects($this->once())->method('reindexList')->with($ids);
     $this->priceIndexer->expects($this->once())->method('reindexList')->with($ids);
     $this->event->expects($this->once())->method('getCreditmemo')->will($this->returnValue($creditMemo));
     $this->observer->execute($this->eventObserver);
 }
Example #28
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]);
 }
Example #29
0
 /**
  * Checkes the observer's event_regex against event's name
  *
  * @param \Magento\Framework\Event $event
  * @return boolean
  */
 public function isValidFor(\Magento\Framework\Event $event)
 {
     return preg_match($this->getEventRegex(), $event->getName());
 }
Example #30
0
 /**
  * Register an event for this collection
  *
  * @param Event $event
  * @return $this
  */
 public function addEvent(Event $event)
 {
     $this->events[$event->getName()] = $event;
     return $this;
 }