1010use Magento \Framework \ObjectManagerInterface ;
1111use Magento \Framework \Registry ;
1212use Magento \Store \Model \Store ;
13+ use Magento \Store \Model \StoreFactory ;
14+ use Magento \Store \Api \WebsiteRepositoryInterface ;
1315use Magento \TestFramework \Helper \Bootstrap ;
1416use Magento \UrlRewrite \Model \UrlFinderInterface ;
1517use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
1618
1719/**
1820 * Test for plugin which is listening store resource model and on save replace cms page url rewrites
21+ *
22+ * @magentoAppArea adminhtml
1923 */
2024class ViewTest extends \PHPUnit \Framework \TestCase
2125{
@@ -29,22 +33,39 @@ class ViewTest extends \PHPUnit\Framework\TestCase
2933 */
3034 private $ objectManager ;
3135
36+ /**
37+ * @var StoreFactory
38+ */
39+ private $ storeFactory ;
40+
41+ /**
42+ * @var string
43+ */
44+ private $ storeCode ;
45+
46+ /**
47+ * @var WebsiteRepositoryInterface
48+ */
49+ private $ websiteRepository ;
50+
3251 /**
3352 * @inheritdoc
3453 */
3554 protected function setUp ()
3655 {
3756 $ this ->objectManager = Bootstrap::getObjectManager ();
3857 $ this ->urlFinder = $ this ->objectManager ->create (UrlFinderInterface::class);
58+ $ this ->storeFactory = $ this ->objectManager ->create (StoreFactory::class);
59+ $ this ->websiteRepository = $ this ->objectManager ->get (WebsiteRepositoryInterface::class);
60+ $ this ->storeCode = 'test_ ' . mt_rand ();
3961 }
4062
4163 /**
4264 * Test of replacing cms page url rewrites on create and delete store
4365 *
4466 * @magentoDataFixture Magento/Cms/_files/pages.php
45- * @magentoAppArea adminhtml
4667 */
47- public function testAfterSave ()
68+ public function testUrlRewritesChangesAfterStoreSave ()
4869 {
4970 $ data = [
5071 UrlRewrite::REQUEST_PATH => 'page100 ' ,
@@ -67,13 +88,13 @@ public function testAfterSave()
6788 private function createStore (): void
6889 {
6990 /** @var $store Store */
70- $ store = $ this ->objectManager ->create (Store::class );
71- if (!$ store ->load (' test ' , 'code ' )->getId ()) {
91+ $ store = $ this ->storeFactory ->create ();
92+ if (!$ store ->load ($ this -> storeCode , 'code ' )->getId ()) {
7293 $ store ->setData (
7394 [
74- 'code ' => ' test ' ,
75- 'website_id ' => ' 1 ' ,
76- 'group_id ' => ' 1 ' ,
95+ 'code ' => $ this -> storeCode ,
96+ 'website_id ' => $ this -> websiteRepository -> getDefault ()-> getId () ,
97+ 'group_id ' => $ this -> websiteRepository -> getDefault ()-> getDefaultGroupId () ,
7798 'name ' => 'Test Store ' ,
7899 'sort_order ' => '0 ' ,
79100 'is_active ' => '1 ' ,
@@ -83,7 +104,7 @@ private function createStore(): void
83104 } else {
84105 if ($ store ->getId ()) {
85106 /** @var \Magento\TestFramework\Helper\Bootstrap $registry */
86- $ registry = Bootstrap:: getObjectManager () ->get (
107+ $ registry = $ this -> objectManager ->get (
87108 Registry::class
88109 );
89110 $ registry ->unregister ('isSecureArea ' );
@@ -94,9 +115,9 @@ private function createStore(): void
94115 $ store = $ this ->objectManager ->create (Store::class);
95116 $ store ->setData (
96117 [
97- 'code ' => ' test ' ,
98- 'website_id ' => ' 1 ' ,
99- 'group_id ' => ' 1 ' ,
118+ 'code ' => $ this -> storeCode ,
119+ 'website_id ' => $ this -> websiteRepository -> getDefault ()-> getId () ,
120+ 'group_id ' => $ this -> websiteRepository -> getDefault ()-> getDefaultGroupId () ,
100121 'name ' => 'Test Store ' ,
101122 'sort_order ' => '0 ' ,
102123 'is_active ' => '1 ' ,
@@ -120,13 +141,7 @@ private function deleteStore(): void
120141 $ registry ->register ('isSecureArea ' , true );
121142 /** @var Store $store */
122143 $ store = $ this ->objectManager ->get (Store::class);
123- $ store ->load ('test ' , 'code ' );
124- if ($ store ->getId ()) {
125- $ store ->delete ();
126- }
127- /** @var Store $store */
128- $ store = $ this ->objectManager ->get (Store::class);
129- $ store ->load ('test ' , 'code ' );
144+ $ store ->load ($ this ->storeCode , 'code ' );
130145 if ($ store ->getId ()) {
131146 $ store ->delete ();
132147 }
0 commit comments