/** * */ public function testCategoryCreate() { $this->testReindexAll(); $categories = $this->getCategories(4); $products = $this->getProducts(3); /** @var Category $categorySecond */ $categorySecond = $categories[1]; $categorySecond->setIsAnchor(0); $categorySecond->save(); /** @var Category $categoryFifth */ $categoryFifth = end($categories); /** @var Category $categorySixth */ $categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category'); $categorySixth->setName('Category 6')->setPath($categoryFifth->getPath())->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->save(); /** @var \Magento\Catalog\Model\Product $productThird */ $productThird = end($products); $productThird->setCategoryIds([$categorySixth->getId()]); $productThird->save(); $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId()]; foreach ($categories as $categoryId) { $this->assertTrue((bool) $this->productResource->canBeShowInCategory($productThird, $categoryId)); } $categories = [$categoryFifth->getId(), $categorySecond->getId()]; foreach ($categories as $categoryId) { $this->assertFalse((bool) $this->productResource->canBeShowInCategory($productThird, $categoryId)); } }
/** * @return void */ public function testVisibilityChange() { $this->testReindexAll(); $categories = $this->getCategories(4); $products = $this->getProducts(3); /** @var \Magento\Catalog\Model\Product $product */ $productFirst = $products[0]; $productFirst->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); $productFirst->save(); $productThird = array_pop($products); $productThird->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE); $productThird->save(); /** @var \Magento\Catalog\Model\Category $categoryFirst */ $categoryFirst = $categories[0]; /** @var \Magento\Catalog\Model\Category $categoryFourth */ $categoryFourth = end($categories); $categories = [self::DEFAULT_ROOT_CATEGORY, $categoryFirst->getId(), $categoryFourth->getId()]; foreach ($categories as $categoryId) { foreach ($products as $product) { /** @var \Magento\Catalog\Model\Product $product */ $this->assertTrue((bool) $this->productResource->canBeShowInCategory($product, $categoryId)); } $this->assertFalse((bool) $this->productResource->canBeShowInCategory($productThird, $categoryId)); } }