/** * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testLoadNoSuchEntityException() { $categoryId = 333; $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId)); $this->category->expects($this->once())->method('getId')->will($this->returnValue(false)); $this->model->load($categoryId); }
public function testAfterSave() { $productIds = [1, 2, 3]; $this->subject->expects($this->any())->method('getAffectedProductIds')->will($this->returnValue($productIds)); $this->productRuleProcessor->expects($this->once())->method('reindexList')->with($productIds); $this->assertEquals($this->subject, $this->plugin->afterSave($this->subject, $this->subject)); }
public function testAddCatalogToTopMenuItemsWithFlat() { $observer = $this->_preparationData(); $this->_category->expects($this->once())->method('getChildrenNodes')->will($this->returnValue([$this->_childrenCategory])); $this->_category->expects($this->once())->method('getUseFlatResource')->will($this->returnValue(true)); $this->_categoryFlatState->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true)); $this->_observer->execute($observer); }
/** * @dataProvider getUrlKeyDataProvider * @param string|null|bool $urlKey * @param string|null|bool $name * @param string $result */ public function testGetUrlKey($urlKey, $name, $result) { $this->category->expects($this->once())->method('getUrlKey')->will($this->returnValue($urlKey)); $this->category->expects($this->any())->method('getName')->will($this->returnValue($name)); $this->category->expects($this->once())->method('formatUrlKey')->will($this->returnArgument(0)); $this->assertEquals($result, $this->categoryUrlPathGenerator->getUrlKey($this->category)); }
public function testGetCategoryWithAppliedId() { $storeId = 1234; $categoryId = 4321; $this->store->expects($this->once())->method('getId')->will($this->returnValue($storeId)); $this->layer->expects($this->any())->method('getCurrentCategory')->will($this->returnValue($this->category)); $this->category->expects($this->once())->method('setStoreId')->with($this->equalTo($storeId))->will($this->returnSelf()); $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId))->will($this->returnSelf()); $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->category->expects($this->any())->method('getPathIds')->will($this->returnValue([20, 10])); $this->coreRegistry->expects($this->once())->method('register')->with($this->equalTo('current_category_filter'), $this->equalTo($this->category), $this->equalTo(true))->will($this->returnSelf()); $this->target->setCategoryId($categoryId); $this->assertSame($this->category, $this->target->getCategory()); $this->assertSame(20, $this->target->getResetValue()); return $this->target; }
/** * Run test execute method * * @param int|bool $categoryId * @param int $storeId * @return void * * @dataProvider dataProviderExecute * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecute($categoryId, $storeId) { $rootCategoryId = 2; $this->requestMock->expects($this->atLeastOnce())->method('getParam')->will($this->returnValueMap([['id', false, $categoryId], ['store', null, $storeId]])); $this->requestMock->expects($this->atLeastOnce())->method('getQuery')->with('isAjax')->will($this->returnValue(false)); $this->mockInitCategoryCall(); $this->sessionMock->expects($this->once())->method('__call')->will($this->returnValue([])); if (!$categoryId) { if ($storeId) { $this->storeManagerInterfaceMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnSelf()); } else { $this->storeManagerInterfaceMock->expects($this->once())->method('getDefaultStoreView')->will($this->returnSelf()); } $this->storeManagerInterfaceMock->expects($this->once())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId)); $categoryId = $rootCategoryId; } $this->requestMock->expects($this->atLeastOnce())->method('setParam')->with('id', $categoryId)->will($this->returnValue(true)); $this->categoryMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($categoryId)); /** * @var \Magento\Framework\View\Element\Template * |\PHPUnit_Framework_MockObject_MockObject $blockMock */ $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\Template', ['setStoreId'], [], '', false); $blockMock->expects($this->once())->method('setStoreId')->with($storeId); $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnSelf()); $this->resultPageMock->expects($this->once())->method('getBlock')->willReturn($blockMock); $this->edit->execute(); }
public function testInfo() { $id = 3; $this->category->expects($this->once())->method('load')->with($this->equalTo($id)); $this->category->expects($this->once())->method('getId')->will($this->returnValue(true)); $this->assertInstanceOf('Magento\\Catalog\\Service\\V1\\Data\\Eav\\Category\\Info\\Metadata', $this->model->info($id)); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGetItems() { $this->category->expects($this->any())->method('getIsActive')->will($this->returnValue(true)); $category1 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock(); $category1->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(120)); $category1->expects($this->once())->method('getName')->will($this->returnValue('Category 1')); $category1->expects($this->once())->method('getIsActive')->will($this->returnValue(true)); $category2 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock(); $category2->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(5641)); $category2->expects($this->once())->method('getName')->will($this->returnValue('Category 2')); $category2->expects($this->once())->method('getIsActive')->will($this->returnValue(true)); $category3 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock(); $category3->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(777)); $category3->expects($this->never())->method('getName'); $category3->expects($this->once())->method('getIsActive')->will($this->returnValue(true)); $categories = [$category1, $category2, $category3]; $this->category->expects($this->once())->method('getChildrenCategories')->will($this->returnValue($categories)); $facetedData = [120 => ['count' => 10], 5641 => ['count' => 45], 777 => ['count' => 80]]; $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50)); $this->fulltextCollection->expects($this->once())->method('getFacetedData')->with('category')->will($this->returnValue($facetedData)); $builtData = [['label' => 'Category 1', 'value' => 120, 'count' => 10], ['label' => 'Category 2', 'value' => 5641, 'count' => 45]]; $this->itemDataBuilder->expects($this->at(0))->method('addItemData')->with('Category 1', 120, 10)->will($this->returnSelf()); $this->itemDataBuilder->expects($this->at(1))->method('addItemData')->with('Category 2', 5641, 45)->will($this->returnSelf()); $this->itemDataBuilder->expects($this->once())->method('build')->will($this->returnValue($builtData)); $this->target->getItems(); }
public function testGenerate() { $requestPath = 'category.html'; $targetPath = 'target-path'; $storeId = 'store_id'; $categoryId = 'category_id'; $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath)); $this->categoryUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath)); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals(['category.html_store_id' => $this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->category)); }
/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ public function testUpdateValidateException() { $id = 3; $categorySdo = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Category')->disableOriginalConstructor()->getMock(); $this->category->expects($this->once())->method('getId')->will($this->returnValue($id)); $this->category->expects($this->once())->method('validate')->will($this->returnValue(['Validation error'])); $this->model->update($id, $categorySdo); }
public function testGetCategoryId() { $this->category->expects($this->once())->method('getId')->will($this->returnValue(10)); $this->registry->expects($this->at(0))->method('registry'); $this->registry->expects($this->at(1))->method('registry')->will($this->returnValue($this->category)); $this->assertFalse($this->model->getCategoryId()); $this->assertEquals(10, $this->model->getCategoryId()); }
/** * @dataProvider currentCategoryProvider */ public function testGetCurrentCategory($currentCategory) { $rootCategoryId = 333; $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->will($this->returnValue($currentCategory)); $this->category->expects($this->any())->method('load')->with($this->equalTo($rootCategoryId))->will($this->returnValue($this->category)); $this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId)); $result = $this->model->getCurrentCategory(); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Category', $result); }
public function testAssignedProducts() { $categoryId = 3; $productPosition = 1; $productId = $categoryId + 6; $productSku = "sku{$productId}"; $productDto = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Eav\\Category\\ProductLink')->disableOriginalConstructor()->getMock(); /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productObject */ $productObject = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productObject->expects($this->once())->method('getSku')->will($this->returnValue($productSku)); /** @var \Magento\Framework\Data\Collection\Db|\PHPUnit_Framework_MockObject_MockObject $productCollection */ $productCollection = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\Db')->disableOriginalConstructor()->getMock(); $productCollection->expects($this->any())->method('getItems')->will($this->returnValue([$productId => $productObject])); $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId)); $this->category->expects($this->once())->method('getId')->will($this->returnValue(true)); $this->category->expects($this->once())->method('getProductsPosition')->will($this->returnValue([$productId => $productPosition])); $this->category->expects($this->once())->method('getProductCollection')->will($this->returnValue($productCollection)); $this->productLinkBuilder->expects($this->any())->method('populateWithArray')->with($this->equalTo([ProductLink::SKU => $productSku, ProductLink::POSITION => $productPosition]))->will($this->returnValue($this->productLinkBuilder)); $this->assertEquals([$productDto], $this->model->assignedProducts($categoryId)); }
private function prepareMocksForAssign($categoryId, $productId = 333) { $productSku = 'sku333'; $productsPosition = [105 => 16, 334 => 1]; $this->productLink->expects($this->once())->method('getSku')->will($this->returnValue($productSku)); $this->productLink->expects($this->any())->method('getPosition')->will($this->returnValue($categoryId)); $this->categoryLoader->expects($this->once())->method('load')->with($this->equalTo($categoryId))->will($this->returnValue($this->category)); $this->category->expects($this->once())->method('getProductsPosition')->will($this->returnValue($productsPosition)); $newProductPositions = [$productId => $categoryId] + $productsPosition; $this->category->expects($this->any())->method('setPostedProducts')->with($this->equalTo($newProductPositions)); $this->product->expects($this->once())->method('getIdBySku')->with($this->equalTo($productSku))->will($this->returnValue($productId)); }
/** * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCategoryNoSuchEntityException() { $categoryId = 3; $productId = $categoryId + 6; /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productObject */ $productObject = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); /** @var \Magento\Framework\Data\Collection\Db|\PHPUnit_Framework_MockObject_MockObject $productCollection */ $productCollection = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\Db')->disableOriginalConstructor()->getMock(); $productCollection->expects($this->any())->method('getItems')->will($this->returnValue([$productId => $productObject])); $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId)); $this->category->expects($this->once())->method('getId')->will($this->returnValue(0)); $this->model->assignedProducts($categoryId); }
public function testGenerationForCustomWithTargetPathGeneration() { $storeId = 12; $categoryId = 123; $requestPath = 'generate-for-custom-without-redirect-type.html'; $targetPath = 'generated-target-path.html'; $description = 'description'; $this->urlFinder->expects($this->once())->method('findAllByData')->will($this->returnValue($this->getCurrentRewritesMocks([[UrlRewrite::REQUEST_PATH => $requestPath, UrlRewrite::TARGET_PATH => 'custom-target-path.html', UrlRewrite::REDIRECT_TYPE => 'code', UrlRewrite::IS_AUTOGENERATED => 0, UrlRewrite::DESCRIPTION => $description, UrlRewrite::METADATA => []]]))); $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($targetPath)); $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->urlRewriteBuilder->expects($this->once())->method('setDescription')->with($description)->will($this->returnSelf()); $this->prepareUrlRewriteMock($storeId, $categoryId, $requestPath, $targetPath, 'code'); $this->assertEquals([$this->urlRewrite], $this->currentUrlRewritesRegenerator->generate($storeId, $this->category)); }
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->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category)); $this->category->expects($this->any())->method('setStoreId')->will($this->returnSelf()); $this->category->expects($this->any())->method('load')->with($categoryId)->will($this->returnSelf()); $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 testSkipGenerationForGlobalScope() { $this->category->expects($this->any())->method('getStoreIds')->will($this->returnValue([1, 2])); $this->storeViewService->expects($this->exactly(2))->method('doesEntityHaveOverriddenUrlKeyForStore')->will($this->returnValue(true)); $this->assertEquals([], $this->categoryUrlRewriteGenerator->generate($this->category)); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please correct the category. */ public function testSetCurrentCategoryNotFoundException() { $this->category->expects($this->once())->method('getId')->will($this->returnValue(null)); $this->model->setCurrentCategory($this->category); }
public function testGetCanonicalUrlPathWithCategory() { $this->product->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->category->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->assertEquals('catalog/product/view/id/1/category/1', $this->productUrlPathGenerator->getCanonicalUrlPath($this->product, $this->category)); }