1414use Magento \Catalog \Model \ResourceModel \Category \Collection ;
1515use Magento \Catalog \Model \ResourceModel \Category \Tree ;
1616use Magento \Catalog \Model \ResourceModel \Product \Collection as ProductCollection ;
17+ use Magento \Catalog \Test \Fixture \Category as CategoryFixture ;
1718use Magento \Eav \Model \Entity \Attribute \Exception as AttributeException ;
19+ use Magento \Framework \Exception \LocalizedException ;
1820use Magento \Framework \Exception \NoSuchEntityException ;
1921use Magento \Framework \Math \Random ;
2022use Magento \Framework \Url ;
2123use Magento \Store \Api \StoreRepositoryInterface ;
2224use Magento \Store \Model \Store ;
2325use Magento \Store \Model \StoreManagerInterface ;
26+ use Magento \TestFramework \Fixture \DataFixture ;
27+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
28+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
2429use Magento \TestFramework \Helper \Bootstrap ;
2530use PHPUnit \Framework \TestCase ;
2631
@@ -57,8 +62,14 @@ class CategoryTest extends TestCase
5762 /** @var CategoryRepositoryInterface */
5863 private $ categoryRepository ;
5964
65+ /**
66+ * @var DataFixtureStorage
67+ */
68+ private $ dataFixtureStorage ;
69+
6070 /**
6171 * @inheritdoc
72+ * @throws LocalizedException
6273 */
6374 protected function setUp (): void
6475 {
@@ -69,6 +80,7 @@ protected function setUp(): void
6980 $ this ->_model = $ this ->objectManager ->create (Category::class);
7081 $ this ->categoryResource = $ this ->objectManager ->get (CategoryResource::class);
7182 $ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepositoryInterface::class);
83+ $ this ->dataFixtureStorage = DataFixtureStorageManager::getStorage ();
7284 }
7385
7486 public function testGetUrlInstance (): void
@@ -509,4 +521,21 @@ protected function getCategoryByName($categoryName)
509521
510522 return $ collection ->getItemByColumnValue ('name ' , $ categoryName );
511523 }
524+
525+ /**
526+ * @return void
527+ * @throws LocalizedException|\Exception
528+ */
529+ #[
530+ DataFixture(CategoryFixture::class, as: 'category ' ),
531+ ]
532+ public function testGetUrlAfterUpdate ()
533+ {
534+ $ category = $ this ->dataFixtureStorage ->get ('category ' );
535+ $ category ->setUrlKey ('new-url ' );
536+ $ category ->setSaveRewritesHistory (true );
537+ $ this ->categoryResource ->save ($ category );
538+
539+ $ this ->assertStringEndsWith ('new-url.html ' , $ category ->getUrl ());
540+ }
512541}
0 commit comments