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,6 +62,11 @@ class CategoryTest extends TestCase
5762 /** @var CategoryRepositoryInterface */
5863 private $ categoryRepository ;
5964
65+ /**
66+ * @var DataFixtureStorage
67+ */
68+ private DataFixtureStorage $ dataFixtureStorage ;
69+
6070 /**
6171 * @inheritdoc
6272 */
@@ -69,6 +79,7 @@ protected function setUp(): void
6979 $ this ->_model = $ this ->objectManager ->create (Category::class);
7080 $ this ->categoryResource = $ this ->objectManager ->get (CategoryResource::class);
7181 $ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepositoryInterface::class);
82+ $ this ->dataFixtureStorage = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
7283 }
7384
7485 public function testGetUrlInstance (): void
@@ -509,4 +520,20 @@ protected function getCategoryByName($categoryName)
509520
510521 return $ collection ->getItemByColumnValue ('name ' , $ categoryName );
511522 }
523+
524+ /**
525+ * @return void
526+ * @throws LocalizedException|\Exception
527+ */
528+ #[
529+ DataFixture(CategoryFixture::class, as: 'category ' ),
530+ ]
531+ public function testGetUrlAfterUpdate () {
532+ $ category = $ this ->dataFixtureStorage ->get ('category ' );
533+ $ category ->setUrlKey ('new-url ' );
534+ $ category ->setSaveRewritesHistory (true );
535+ $ this ->categoryResource ->save ($ category );
536+
537+ $ this ->assertStringEndsWith ('new-url.html ' , $ category ->getUrl ());
538+ }
512539}
0 commit comments