public function testDelete() { $categoryId = 5; $parentId = 7; $this->request->expects($this->any())->method('getParam')->with('id')->willReturn($categoryId); $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getParentId', 'getPath'], [], '', false); $category->expects($this->once())->method('getParentId')->willReturn($parentId); $category->expects($this->once())->method('getPath')->willReturn('category-path'); $this->categoryRepository->expects($this->once())->method('get')->with($categoryId)->willReturn($category); $this->authStorage->expects($this->once())->method('setDeletedPath')->with('category-path'); $this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/', ['_current' => true, 'id' => $parentId]); $this->unit->execute(); }
public function testGetRssData() { $category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->setMethods(['__sleep', '__wakeup', 'load', 'getId', 'getUrl', 'getName'])->disableOriginalConstructor()->getMock(); $category->expects($this->once())->method('getName')->will($this->returnValue('Category Name')); $category->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/category-name.html')); $this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category)); $product = $this->getMockBuilder('\\Magento\\catalog\\Model\\Product')->setMethods(['__sleep', '__wakeup', 'getName', 'getAllowedInRss', 'getProductUrl', 'getDescription', 'getAllowedPriceInRss'])->disableOriginalConstructor()->getMock(); $product->expects($this->once())->method('getName')->will($this->returnValue('Product Name')); $product->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true)); $product->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue('http://magento.com/product.html')); $product->expects($this->once())->method('getDescription')->will($this->returnValue('Product Description')); $product->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue(true)); $this->rssModel->expects($this->once())->method('getProductCollection')->will($this->returnValue([$product])); $this->imageHelper->expects($this->once())->method('init')->with($product, 'thumbnail')->will($this->returnSelf()); $this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link')); $data = $this->block->getRssData(); $this->assertEquals($this->rssFeed['link'], $data['link']); $this->assertEquals($this->rssFeed['title'], $data['title']); $this->assertEquals($this->rssFeed['description'], $data['description']); $this->assertEquals($this->rssFeed['entries'][0]['title'], $data['entries'][0]['title']); $this->assertEquals($this->rssFeed['entries'][0]['link'], $data['entries'][0]['link']); $this->assertContains('<a href="http://magento.com/product.html">', $data['entries'][0]['description']); $this->assertContains('<img src="image_link" border="0" align="left" height="75" width="75">', $data['entries'][0]['description']); $this->assertContains('<td style="text-decoration:none;">Product Description </td>', $data['entries'][0]['description']); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteWithException() { $productId = 11; $categoryId = 5; $sender = 'sender'; $recipients = 'recipients'; $formData = ['sender' => $sender, 'recipients' => $recipients]; $redirectUrl = 'redirect_url'; /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock); $this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true); $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]); /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */ $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass(); $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock); $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true); $this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.'))); $productMock->expects($this->never())->method('setCategory'); $this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]); $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData); $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]); $this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf(); $this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf(); $this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf(); $exception = new \Exception(__('Exception.')); $this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception); $this->sendFriendMock->expects($this->never())->method('send'); $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf(); $this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData); $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl); $this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0); $redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf(); $this->assertEquals($redirectMock, $this->model->execute()); }
/** * @dataProvider getUrlPathWithParentDataProvider * @param string $urlKey * @param bool $isCategoryNew * @param bool $level * @param int $parentCategoryParentId * @param string $parentUrlPath * @param string $result */ public function testGetUrlPathWithParent( $urlKey, $isCategoryNew, $level, $parentCategoryParentId, $parentUrlPath, $result ) { $urlPath = null; $parentLevel = CategoryUrlPathGenerator::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING - 1; $this->category->expects($this->any())->method('getParentId') ->will($this->returnValue('parent_id')); $this->category->expects($this->any())->method('getLevel') ->will($this->returnValue($level)); $this->category->expects($this->any())->method('getUrlPath')->will($this->returnValue($urlPath)); $this->category->expects($this->any())->method('getUrlKey')->will($this->returnValue($urlKey)); $this->category->expects($this->any())->method('isObjectNew')->will($this->returnValue($isCategoryNew)); $methods = ['__wakeup', 'getUrlPath', 'getParentId', 'getLevel', 'dataHasChangedFor', 'load']; $parentCategory = $this->getMock('Magento\Catalog\Model\Category', $methods, [], '', false); $parentCategory->expects($this->any())->method('getParentId') ->will($this->returnValue($parentCategoryParentId)); $parentCategory->expects($this->any())->method('getLevel')->will($this->returnValue($parentLevel)); $parentCategory->expects($this->any())->method('getUrlPath')->will($this->returnValue($parentUrlPath)); $parentCategory->expects($this->any())->method('dataHasChangedFor') ->will($this->returnValueMap([['url_key', false], ['path_ids', false]])); $this->categoryRepository->expects($this->any())->method('get')->with('parent_id') ->will($this->returnValue($parentCategory)); $this->assertEquals($result, $this->categoryUrlPathGenerator->getUrlPath($this->category)); }
/** * Test method */ public function testGenerationForGlobalScope() { $this->category->expects($this->any())->method('getStoreId')->will($this->returnValue(null)); $this->category->expects($this->any())->method('getStoreIds')->will($this->returnValue([1])); $this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore')->will($this->returnValue(false)); $canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite(); $canonical->setTargetPath('category-1')->setStoreId(1); $this->canonicalUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([$canonical])); $children = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite(); $children->setTargetPath('category-2')->setStoreId(2); $this->childrenUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([$children])); $current = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite(); $current->setTargetPath('category-3')->setStoreId(3); $this->currentUrlRewritesRegenerator->expects($this->any())->method('generate')->will($this->returnValue([$current])); $categoryForSpecificStore = $this->getMock('Magento\\Catalog\\Model\\Category', ['getUrlKey', 'getUrlPath'], [], '', false); $this->categoryRepository->expects($this->once())->method('get')->willReturn($categoryForSpecificStore); $this->assertEquals([$canonical, $children, $current], $this->categoryUrlRewriteGenerator->generate($this->category)); }
public function testGetCurrentCategoryIfCurrentCategoryIsNotSet() { $rootCategoryId = 333; $this->currentCategory->getData('current_category', null); $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->willReturn(null); $this->categoryRepository->expects($this->once())->method('get')->with($rootCategoryId)->willReturn($this->category); $this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId)); $this->assertEquals($this->currentCategory, $this->model->getCurrentCategory()); $this->assertEquals($this->currentCategory, $this->model->getData('current_category')); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not move category */ public function testMoveWithCouldNotMoveException() { $categoryId = 2; $parentId = 1; $afterId = null; $categoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'categoryMock', false); $parentCategoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'parentCategoryMock', false); $this->categoryRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap([[$categoryId, null, $categoryMock], [$parentId, null, $parentCategoryMock]])); $categoryMock->expects($this->once())->method('move')->with($parentId, $afterId)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message'))); $this->model->move($categoryId, $parentId, $afterId); }
public function testApplyCustomLayoutUpdate() { $categoryId = 123; $pageLayout = 'page_layout'; $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Catalog\\Helper\\Category', $this->categoryHelper], ['Magento\\Theme\\Helper\\Layout', $this->layoutHelper]])); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([[Action::PARAM_NAME_URL_ENCODED], ['id', false, $categoryId]])); $this->categoryRepository->expects($this->any())->method('get')->with($categoryId)->will($this->returnValue($this->category)); $this->categoryHelper->expects($this->any())->method('canShow')->will($this->returnValue(true)); $settings = $this->getMock('Magento\\Framework\\Object', ['getPageLayout'], [], '', false); $settings->expects($this->atLeastOnce())->method('getPageLayout')->will($this->returnValue($pageLayout)); $this->catalogDesign->expects($this->any())->method('getDesignSettings')->will($this->returnValue($settings)); $this->action->execute(); }
public function testMovePrimaryWorkflow() { $indexer = $this->getMock('stdClass', ['isScheduled']); $indexer->expects($this->once())->method('isScheduled')->will($this->returnValue(true)); $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_product')->will($this->returnValue($indexer)); $parentCategory = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId', 'setStoreId', 'load'], [], '', false); $parentCategory->expects($this->any())->method('getId')->will($this->returnValue(5)); $parentCategory->expects($this->any())->method('setStoreId')->will($this->returnSelf()); $parentCategory->expects($this->any())->method('load')->will($this->returnSelf()); $this->categoryRepository->expects($this->any())->method('get')->will($this->returnValue($parentCategory)); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->category->setId(3); $this->category->move(5, 7); }
public function testGetCategory() { $this->category->expects($this->any())->method('getId')->will($this->returnValue(10)); $this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->category)); $this->categoryRepository->expects($this->any())->method('get')->will($this->returnValue($this->category)); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Category', $this->model->getCategory()); }