14
14
use Magento \Catalog \Model \ResourceModel \Category \Collection ;
15
15
use Magento \Catalog \Model \ResourceModel \Category \Tree ;
16
16
use Magento \Catalog \Model \ResourceModel \Product \Collection as ProductCollection ;
17
+ use Magento \Catalog \Test \Fixture \Category as CategoryFixture ;
17
18
use Magento \Eav \Model \Entity \Attribute \Exception as AttributeException ;
19
+ use Magento \Framework \Exception \LocalizedException ;
18
20
use Magento \Framework \Exception \NoSuchEntityException ;
19
21
use Magento \Framework \Math \Random ;
20
22
use Magento \Framework \Url ;
21
23
use Magento \Store \Api \StoreRepositoryInterface ;
22
24
use Magento \Store \Model \Store ;
23
25
use Magento \Store \Model \StoreManagerInterface ;
26
+ use Magento \TestFramework \Fixture \DataFixture ;
27
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
28
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
24
29
use Magento \TestFramework \Helper \Bootstrap ;
25
30
use PHPUnit \Framework \TestCase ;
26
31
@@ -57,6 +62,11 @@ class CategoryTest extends TestCase
57
62
/** @var CategoryRepositoryInterface */
58
63
private $ categoryRepository ;
59
64
65
+ /**
66
+ * @var DataFixtureStorage
67
+ */
68
+ private DataFixtureStorage $ dataFixtureStorage ;
69
+
60
70
/**
61
71
* @inheritdoc
62
72
*/
@@ -69,6 +79,7 @@ protected function setUp(): void
69
79
$ this ->_model = $ this ->objectManager ->create (Category::class);
70
80
$ this ->categoryResource = $ this ->objectManager ->get (CategoryResource::class);
71
81
$ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepositoryInterface::class);
82
+ $ this ->dataFixtureStorage = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
72
83
}
73
84
74
85
public function testGetUrlInstance (): void
@@ -509,4 +520,20 @@ protected function getCategoryByName($categoryName)
509
520
510
521
return $ collection ->getItemByColumnValue ('name ' , $ categoryName );
511
522
}
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
+ }
512
539
}
0 commit comments