10
10
use Magento \Framework \ObjectManagerInterface ;
11
11
use Magento \Framework \Registry ;
12
12
use Magento \Store \Model \Store ;
13
+ use Magento \Store \Model \StoreFactory ;
14
+ use Magento \Store \Api \WebsiteRepositoryInterface ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
14
16
use Magento \UrlRewrite \Model \UrlFinderInterface ;
15
17
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
16
18
17
19
/**
18
20
* Test for plugin which is listening store resource model and on save replace cms page url rewrites
21
+ *
22
+ * @magentoAppArea adminhtml
19
23
*/
20
24
class ViewTest extends \PHPUnit \Framework \TestCase
21
25
{
@@ -29,22 +33,39 @@ class ViewTest extends \PHPUnit\Framework\TestCase
29
33
*/
30
34
private $ objectManager ;
31
35
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
+
32
51
/**
33
52
* @inheritdoc
34
53
*/
35
54
protected function setUp ()
36
55
{
37
56
$ this ->objectManager = Bootstrap::getObjectManager ();
38
57
$ 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 ();
39
61
}
40
62
41
63
/**
42
64
* Test of replacing cms page url rewrites on create and delete store
43
65
*
44
66
* @magentoDataFixture Magento/Cms/_files/pages.php
45
- * @magentoAppArea adminhtml
46
67
*/
47
- public function testAfterSave ()
68
+ public function testUrlRewritesChangesAfterStoreSave ()
48
69
{
49
70
$ data = [
50
71
UrlRewrite::REQUEST_PATH => 'page100 ' ,
@@ -67,13 +88,13 @@ public function testAfterSave()
67
88
private function createStore (): void
68
89
{
69
90
/** @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 ()) {
72
93
$ store ->setData (
73
94
[
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 () ,
77
98
'name ' => 'Test Store ' ,
78
99
'sort_order ' => '0 ' ,
79
100
'is_active ' => '1 ' ,
@@ -83,7 +104,7 @@ private function createStore(): void
83
104
} else {
84
105
if ($ store ->getId ()) {
85
106
/** @var \Magento\TestFramework\Helper\Bootstrap $registry */
86
- $ registry = Bootstrap:: getObjectManager () ->get (
107
+ $ registry = $ this -> objectManager ->get (
87
108
Registry::class
88
109
);
89
110
$ registry ->unregister ('isSecureArea ' );
@@ -94,9 +115,9 @@ private function createStore(): void
94
115
$ store = $ this ->objectManager ->create (Store::class);
95
116
$ store ->setData (
96
117
[
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 () ,
100
121
'name ' => 'Test Store ' ,
101
122
'sort_order ' => '0 ' ,
102
123
'is_active ' => '1 ' ,
@@ -120,13 +141,7 @@ private function deleteStore(): void
120
141
$ registry ->register ('isSecureArea ' , true );
121
142
/** @var Store $store */
122
143
$ 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 ' );
130
145
if ($ store ->getId ()) {
131
146
$ store ->delete ();
132
147
}
0 commit comments