|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Catalog\Model\ResourceModel\Category; |
| 7 | + |
| 8 | +class CollectionTest extends \PHPUnit\Framework\TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var \Magento\Catalog\Model\ResourceModel\Category\Collection |
| 12 | + */ |
| 13 | + protected $collection; |
| 14 | + |
| 15 | + /** |
| 16 | + * Sets up the fixture, for example, opens a network connection. |
| 17 | + * This method is called before a test is executed. |
| 18 | + */ |
| 19 | + protected function setUp() |
| 20 | + { |
| 21 | + $this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 22 | + \Magento\Catalog\Model\ResourceModel\Category\Collection::class |
| 23 | + ); |
| 24 | + } |
| 25 | + |
| 26 | + protected function setDown() { |
| 27 | + /* Refresh stores memory cache after store deletion */ |
| 28 | + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
| 29 | + \Magento\Store\Model\StoreManagerInterface::class |
| 30 | + )->reinitStores(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @magentoAppIsolation enabled |
| 35 | + * @magentoDbIsolation enabled |
| 36 | + * @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php |
| 37 | + */ |
| 38 | + public function testJoinUrlRewriteOnDefault() |
| 39 | + { |
| 40 | + $categories = $this->collection->joinUrlRewrite()->addPathFilter('1/2/3'); |
| 41 | + $this->assertCount(1, $categories); |
| 42 | + /** @var $category \Magento\Catalog\Model\Category */ |
| 43 | + $category = $categories->getFirstItem(); |
| 44 | + $this->assertStringEndsWith('category.html', $category->getUrl()); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @magentoAppIsolation enabled |
| 49 | + * @magentoDbIsolation enabled |
| 50 | + * @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php |
| 51 | + */ |
| 52 | + public function testJoinUrlRewriteNotOnDefaultStore() |
| 53 | + { |
| 54 | + $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class); |
| 55 | + $storeId = $store->load('second_category_store', 'code')->getId(); |
| 56 | + $categories = $this->collection->setStoreId($storeId)->joinUrlRewrite()->addPathFilter('1/2/3'); |
| 57 | + $this->assertCount(1, $categories); |
| 58 | + /** @var $category \Magento\Catalog\Model\Category */ |
| 59 | + $category = $categories->getFirstItem(); |
| 60 | + $this->assertStringEndsWith('category-3-on-2.html', $category->getUrl()); |
| 61 | + } |
| 62 | +} |
0 commit comments