From 2d12dac1672aa4125b1012e454a8b58bb9ee9b73 Mon Sep 17 00:00:00 2001 From: Alessandro Pagnin Date: Sun, 18 Mar 2018 23:26:09 +0100 Subject: [PATCH] add integration test --- .../ResourceModel/Category/CollectionTest.php | 62 +++++++++++++++++++ .../_files/category_multiple_stores.php | 61 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Category/CollectionTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Category/CollectionTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Category/CollectionTest.php new file mode 100644 index 0000000000000..7d2d5d8e443a7 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Category/CollectionTest.php @@ -0,0 +1,62 @@ +collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Catalog\Model\ResourceModel\Category\Collection::class + ); + } + + protected function setDown() { + /* Refresh stores memory cache after store deletion */ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Store\Model\StoreManagerInterface::class + )->reinitStores(); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + * @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php + */ + public function testJoinUrlRewriteOnDefault() + { + $categories = $this->collection->joinUrlRewrite()->addPathFilter('1/2/3'); + $this->assertCount(1, $categories); + /** @var $category \Magento\Catalog\Model\Category */ + $category = $categories->getFirstItem(); + $this->assertStringEndsWith('category.html', $category->getUrl()); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + * @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php + */ + public function testJoinUrlRewriteNotOnDefaultStore() + { + $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class); + $storeId = $store->load('second_category_store', 'code')->getId(); + $categories = $this->collection->setStoreId($storeId)->joinUrlRewrite()->addPathFilter('1/2/3'); + $this->assertCount(1, $categories); + /** @var $category \Magento\Catalog\Model\Category */ + $category = $categories->getFirstItem(); + $this->assertStringEndsWith('category-3-on-2.html', $category->getUrl()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php new file mode 100644 index 0000000000000..c6590bb6a0f9f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php @@ -0,0 +1,61 @@ +create( + \Magento\Catalog\Model\CategoryFactory::class +); +/** @var \Magento\Catalog\Model\CategoryRepository $repository */ +$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Catalog\Model\CategoryRepository::class +); +/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ +$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Store\Model\StoreManagerInterface::class +); +/** @var \Magento\Store\Model\Store $store */ +$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class); +if (!$store->load('second_category_store', 'code')->getId()) { + $websiteId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Store\Model\StoreManagerInterface::class + )->getWebsite()->getId(); + $groupId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Store\Model\StoreManagerInterface::class + )->getWebsite()->getDefaultGroupId(); + $store->setCode( + 'second_category_store' + )->setWebsiteId( + $websiteId + )->setGroupId( + $groupId + )->setName( + 'Fixture Store' + )->setSortOrder( + 10 + )->setIsActive( + 1 + ); + $store->save(); +} + +/* Refresh stores memory cache */ +\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Store\Model\StoreManagerInterface::class +)->reinitStores(); + +/** @var \Magento\Catalog\Model\Category $newCategory */ +$newCategory = $factory->create(); +$newCategory + ->setName('Category') + ->setParentId(2) + ->setLevel(2) + ->setPath('1/2/3') + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1); +$repository->save($newCategory); +$currentStoreId = $storeManager->getStore()->getId(); +$storeManager->setCurrentStore($storeManager->getStore($store->getId())); +$newCategory + ->setUrlKey('category-3-on-2'); +$repository->save($newCategory); +$storeManager->setCurrentStore($storeManager->getStore($currentStoreId)); \ No newline at end of file