/** * afterUpdateMview with disabled PageCache module */ public function testAfterUpdateMviewPageCacheDisabled() { $this->moduleManager->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false)); $this->eventManagerMock->expects($this->never())->method('dispatch'); $actualResult = $this->plugin->afterUpdateMview($this->subjectMock); $this->assertNull($actualResult); }
public function testSave() { $this->item->setData('key', 'value'); $this->eventManager->expects($this->at(0))->method('dispatch')->with('model_save_before', ['object' => $this->item]); $this->eventManager->expects($this->at(1))->method('dispatch')->with('cataloginventory_stock_item_save_before', ['data_object' => $this->item, 'item' => $this->item]); $this->resource->expects($this->once())->method('addCommitCallback')->will($this->returnValue($this->resource)); $this->assertEquals($this->item, $this->item->save()); }
/** * Test afterUpdateMview * * @return void */ public function testAfterUpdateMview() { $tags = ['tag_name1', 'tag_name2']; $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock])); $this->contextMock->expects($this->atLeastOnce())->method('getIdentities')->willReturn($tags); $this->cacheMock->expects($this->once())->method('clean')->with($tags); $this->plugin->afterUpdateMview($this->subjectMock); }
/** * Test for method unassignState */ public function testUnassignStateSuccess() { $params = ['status' => $this->model->getStatus(), 'state' => 'test_state']; $this->resourceMock->expects($this->once())->method('checkIsStateLast')->with($this->equalTo($params['state']))->will($this->returnValue(false)); $this->resourceMock->expects($this->once())->method('checkIsStatusUsed')->with($this->equalTo($params['status']))->will($this->returnValue(false)); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('sales_order_status_unassign'), $this->equalTo($params)); $this->resourceMock->expects($this->once())->method('unassignState')->with($this->equalTo($params['status']), $this->equalTo($params['state'])); $this->assertEquals($this->model, $this->model->unassignState($params['state'])); }
public function testAfterGenerateXmlNoDepersonalize() { $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false); $this->eventManagerMock->expects($this->never())->method('dispatch'); $this->messageSessionMock->expects($this->never())->method('clearStorage'); $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
/** * Test method afterGenerateXml with enabled module PageCache */ public function testAfterGenerateXmlPageCacheEnabled() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('depersonalize_clear_session')); $this->messageSessionMock->expects($this->once())->method('clearStorage'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
/** * @param int $value * @param int $oldValue * @param string $eventName * @dataProvider testAfterSaveDataProvider * @return void */ public function testAfterSave($value, $oldValue, $eventName) { $path = 'dev/grid/async_indexing'; $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->object->setData(['value' => $value, 'path' => $path, 'scope' => $scope]); $this->config->expects($this->once())->method('getValue')->with($path, $scope)->willReturn($oldValue); if ($value == $oldValue) { $this->eventManager->expects($this->never())->method('dispatch'); } else { $this->eventManager->expects($this->once())->method('dispatch')->with($eventName); } $this->object->afterSave(); }
/** * Test execute add success critical exception * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteAddSuccessCriticalException() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false); $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false); $exception = new \Exception(); $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true); $helper->expects($this->exactly(2))->method('calculate')->willReturn(true); $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item); $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf(); $wishlist->expects($this->once())->method('save')->willReturn(null); $wishlist->expects($this->once())->method('getId')->willReturn(56); $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true); $product->expects($this->once())->method('getName')->willReturn('Test name'); $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2); $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3); $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product); $item->expects($this->once())->method('load')->with(3)->willReturnSelf(); $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12); $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist); $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item); $this->request->expects($this->once())->method('getParams')->willReturn([]); $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger); $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true); $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception); $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->getController()->execute()); }
/** * test for method getValue with type Fixed and selectionPriceType not null */ public function testGetValueTypeFixedWithSelectionPriceType() { $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->bundleMock->expects($this->atLeastOnce())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(RegularPrice::PRICE_CODE))->will($this->returnValue($this->regularPriceMock)); $this->regularPriceMock->expects($this->once())->method('getValue')->will($this->returnValue(100)); $this->bundleMock->expects($this->once())->method('setFinalPrice')->will($this->returnSelf()); $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->bundleMock->expects($this->exactly(2))->method('getData')->will($this->returnValueMap([['qty', null, 1], ['final_price', null, 100]])); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(true)); $this->productMock->expects($this->any())->method('getSelectionPriceValue')->will($this->returnValue(100)); $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo(100))->will($this->returnValue(70)); $this->assertEquals(70, $this->selectionPrice->getValue()); }
/** * test for method getValue with type Fixed and selectionPriceType not null * * @param bool $useRegularPrice * @dataProvider useRegularPriceDataProvider */ public function testGetValueTypeFixedWithSelectionPriceType($useRegularPrice) { $this->setupSelectionPrice($useRegularPrice); $regularPrice = 100.125; $discountedPrice = 70.453; $actualPrice = $useRegularPrice ? $regularPrice : $discountedPrice; $expectedPrice = $useRegularPrice ? round($regularPrice, 2) : round($discountedPrice, 2); $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->bundleMock->expects($this->atLeastOnce())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(RegularPrice::PRICE_CODE))->will($this->returnValue($this->regularPriceMock)); $this->regularPriceMock->expects($this->once())->method('getValue')->will($this->returnValue($actualPrice)); $this->bundleMock->expects($this->once())->method('setFinalPrice')->will($this->returnSelf()); $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->bundleMock->expects($this->exactly(2))->method('getData')->will($this->returnValueMap([['qty', null, 1], ['final_price', null, 100]])); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(true)); $this->productMock->expects($this->any())->method('getSelectionPriceValue')->will($this->returnValue($actualPrice)); if (!$useRegularPrice) { $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo($actualPrice))->will($this->returnValue($discountedPrice)); } $this->priceCurrencyMock->expects($this->once())->method('round')->with($actualPrice)->will($this->returnValue($expectedPrice)); $this->assertEquals($expectedPrice, $this->selectionPrice->getValue()); }
protected function generalGetProductCollection() { $this->eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true)); $this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()->willReturn(false); $this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters()->willReturn(false); $this->catalogConfig->expects($this->once())->method('getProductAttributes')->willReturn([]); $this->localDate->expects($this->any())->method('date')->willReturn(new \DateTime('now', new \DateTimeZone('UTC'))); $this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager); $this->context->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig); $this->context->expects($this->once())->method('getCacheState')->willReturn($this->cacheState); $this->context->expects($this->once())->method('getCatalogConfig')->willReturn($this->catalogConfig); $this->context->expects($this->once())->method('getLocaleDate')->willReturn($this->localDate); $this->productCollection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->setMethods(['setVisibility', 'addMinimalPrice', 'addFinalPrice', 'addTaxPercents', 'addAttributeToSelect', 'addUrlRewrite', 'addStoreFilter', 'addAttributeToSort', 'setPageSize', 'setCurPage', 'addAttributeToFilter'])->disableOriginalConstructor()->getMock(); $this->productCollection->expects($this->once())->method('setVisibility')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addMinimalPrice')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addFinalPrice')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addTaxPercents')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addUrlRewrite')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addStoreFilter')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addAttributeToSort')->willReturnSelf(); $this->productCollection->expects($this->atLeastOnce())->method('setCurPage')->willReturnSelf(); $this->productCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf(); }
/** * Run test loadByCode method */ public function testLoadByCode() { $this->eventManager->expects($this->any())->method('dispatch'); $this->resourceMock->expects($this->once())->method('load'); $this->assertEquals($this->couponModel, $this->couponModel->loadByCode('code-value')); }
/** * Test afterUpdateMview * * @return void */ public function testAfterUpdateMview() { $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock])); $this->plugin->afterUpdateMview($this->subjectMock); }