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,8 +62,14 @@ class CategoryTest extends TestCase
57
62
/** @var CategoryRepositoryInterface */
58
63
private $ categoryRepository ;
59
64
65
+ /**
66
+ * @var DataFixtureStorage
67
+ */
68
+ private $ dataFixtureStorage ;
69
+
60
70
/**
61
71
* @inheritdoc
72
+ * @throws LocalizedException
62
73
*/
63
74
protected function setUp (): void
64
75
{
@@ -69,6 +80,7 @@ protected function setUp(): void
69
80
$ this ->_model = $ this ->objectManager ->create (Category::class);
70
81
$ this ->categoryResource = $ this ->objectManager ->get (CategoryResource::class);
71
82
$ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepositoryInterface::class);
83
+ $ this ->dataFixtureStorage = DataFixtureStorageManager::getStorage ();
72
84
}
73
85
74
86
public function testGetUrlInstance (): void
@@ -509,4 +521,21 @@ protected function getCategoryByName($categoryName)
509
521
510
522
return $ collection ->getItemByColumnValue ('name ' , $ categoryName );
511
523
}
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
+ }
512
541
}
0 commit comments