|
11 | 11 | use Magento\Authorization\Model\Role;
|
12 | 12 | use Magento\Authorization\Model\RoleFactory;
|
13 | 13 | use Magento\Authorization\Model\Rules;
|
| 14 | +use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory; |
14 | 15 | use Magento\Authorization\Model\RulesFactory;
|
15 | 16 | use Magento\Catalog\Api\Data\ProductInterface;
|
16 | 17 | use Magento\Catalog\Model\ResourceModel\Product\Gallery;
|
|
34 | 35 | use Magento\Store\Model\WebsiteRepository;
|
35 | 36 | use Magento\TestFramework\Helper\Bootstrap;
|
36 | 37 | use Magento\TestFramework\TestCase\WebapiAbstract;
|
| 38 | +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; |
37 | 39 |
|
38 | 40 | /**
|
39 | 41 | * Test for \Magento\Catalog\Api\ProductRepositoryInterface
|
@@ -84,23 +86,31 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
|
84 | 86 | * @var AdminTokenServiceInterface
|
85 | 87 | */
|
86 | 88 | private $adminTokens;
|
| 89 | + |
87 | 90 | /**
|
88 | 91 | * @var array
|
89 | 92 | */
|
90 | 93 | private $fixtureProducts = [];
|
91 | 94 |
|
| 95 | + /** |
| 96 | + * @var UrlRewriteCollectionFactory |
| 97 | + */ |
| 98 | + private $urlRewriteCollectionFactory; |
| 99 | + |
92 | 100 | /**
|
93 | 101 | * @inheritDoc
|
94 | 102 | */
|
95 | 103 | protected function setUp(): void
|
96 | 104 | {
|
97 | 105 | parent::setUp();
|
98 | 106 |
|
99 |
| - $this->roleFactory = Bootstrap::getObjectManager()->get(RoleFactory::class); |
100 |
| - $this->rulesFactory = Bootstrap::getObjectManager()->get(RulesFactory::class); |
101 |
| - $this->adminTokens = Bootstrap::getObjectManager()->get(AdminTokenServiceInterface::class); |
| 107 | + $objectManager = Bootstrap::getObjectManager(); |
| 108 | + $this->roleFactory = $objectManager->get(RoleFactory::class); |
| 109 | + $this->rulesFactory = $objectManager->get(RulesFactory::class); |
| 110 | + $this->adminTokens = $objectManager->get(AdminTokenServiceInterface::class); |
| 111 | + $this->urlRewriteCollectionFactory = $objectManager->get(UrlRewriteCollectionFactory::class); |
102 | 112 | /** @var DomainManagerInterface $domainManager */
|
103 |
| - $domainManager = Bootstrap::getObjectManager()->get(DomainManagerInterface::class); |
| 113 | + $domainManager = $objectManager->get(DomainManagerInterface::class); |
104 | 114 | $domainManager->addDomains(['example.com']);
|
105 | 115 | }
|
106 | 116 |
|
@@ -2156,6 +2166,32 @@ public function testUpdateProductWithMediaGallery(): void
|
2156 | 2166 | $this->assertEquals($img2, $imageRolesPerStore[$defaultScope]['thumbnail']);
|
2157 | 2167 | }
|
2158 | 2168 |
|
| 2169 | + /** |
| 2170 | + * Update url_key attribute and check it in url_rewrite collection |
| 2171 | + * |
| 2172 | + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php |
| 2173 | + * @magentoConfigFixture default_store general/single_store_mode/enabled 1 |
| 2174 | + * |
| 2175 | + * @return void |
| 2176 | + */ |
| 2177 | + public function testUpdateUrlKeyAttribute(): void |
| 2178 | + { |
| 2179 | + $newUrlKey = 'my-new-url'; |
| 2180 | + |
| 2181 | + $productData = [ |
| 2182 | + ProductInterface::SKU => 'simple', |
| 2183 | + 'custom_attributes' => [['attribute_code' => 'url_key', 'value' => $newUrlKey]], |
| 2184 | + ]; |
| 2185 | + |
| 2186 | + $this->updateProduct($productData); |
| 2187 | + |
| 2188 | + $urlRewriteCollection = $this->urlRewriteCollectionFactory->create(); |
| 2189 | + $urlRewriteCollection->addFieldToFilter(UrlRewrite::ENTITY_TYPE, 'product') |
| 2190 | + ->addFieldToFilter('request_path', $newUrlKey . '.html'); |
| 2191 | + |
| 2192 | + $this->assertCount(1, $urlRewriteCollection); |
| 2193 | + } |
| 2194 | + |
2159 | 2195 | /**
|
2160 | 2196 | * @return string
|
2161 | 2197 | */
|
|
0 commit comments