@@ -52,7 +52,16 @@ protected function setUp()
52
52
);
53
53
$ this ->category = $ this ->getMock (
54
54
\Magento \Catalog \Model \Category::class,
55
- ['setUrlKey ' , 'setUrlPath ' , 'dataHasChangedFor ' , 'isObjectNew ' , 'getResource ' , 'getUrlKey ' , 'getStoreId ' ],
55
+ [
56
+ 'setUrlKey ' ,
57
+ 'setUrlPath ' ,
58
+ 'dataHasChangedFor ' ,
59
+ 'isObjectNew ' ,
60
+ 'getResource ' ,
61
+ 'getUrlKey ' ,
62
+ 'getStoreId ' ,
63
+ 'getData '
64
+ ],
56
65
[],
57
66
'' ,
58
67
false
@@ -96,7 +105,7 @@ public function testSetCategoryUrlAndCategoryPath()
96
105
$ this ->category ->expects ($ this ->once ())->method ('setUrlKey ' )->with ('urk_key ' )->willReturnSelf ();
97
106
$ this ->categoryUrlPathGenerator ->expects ($ this ->once ())->method ('getUrlPath ' )->willReturn ('url_path ' );
98
107
$ this ->category ->expects ($ this ->once ())->method ('setUrlPath ' )->with ('url_path ' )->willReturnSelf ();
99
- $ this ->category ->expects ($ this ->once ( ))->method ('isObjectNew ' )->willReturn (true );
108
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (true );
100
109
101
110
$ this ->categoryUrlPathAutogeneratorObserver ->execute ($ this ->observer );
102
111
}
@@ -109,6 +118,26 @@ public function testExecuteWithoutUrlKeyAndUrlPathUpdating()
109
118
$ this ->categoryUrlPathAutogeneratorObserver ->execute ($ this ->observer );
110
119
}
111
120
121
+ /**
122
+ * @expectedException \Magento\Framework\Exception\LocalizedException
123
+ * @expectedExceptionMessage Invalid URL key
124
+ */
125
+ public function testExecuteWithException ()
126
+ {
127
+ $ categoryName = 'test ' ;
128
+ $ categoryData = ['url_key ' => 0 ];
129
+ $ this ->category ->expects ($ this ->once ())->method ('getUrlKey ' )->willReturn ($ categoryName );
130
+ $ this ->category ->expects ($ this ->once ())
131
+ ->method ('getData ' )
132
+ ->with ('use_default ' )
133
+ ->willReturn ($ categoryData );
134
+ $ this ->categoryUrlPathGenerator ->expects ($ this ->once ())
135
+ ->method ('getUrlKey ' )
136
+ ->with ($ this ->category )
137
+ ->willReturn (null );
138
+ $ this ->categoryUrlPathAutogeneratorObserver ->execute ($ this ->observer );
139
+ }
140
+
112
141
public function testUrlKeyAndUrlPathUpdating ()
113
142
{
114
143
$ this ->categoryUrlPathGenerator ->expects ($ this ->once ())->method ('getUrlKey ' )->with ($ this ->category )
@@ -120,7 +149,7 @@ public function testUrlKeyAndUrlPathUpdating()
120
149
$ this ->category ->expects ($ this ->once ())->method ('setUrlKey ' )->with ('url_key ' )->willReturnSelf ();
121
150
$ this ->category ->expects ($ this ->once ())->method ('setUrlPath ' )->with ('url_path ' )->willReturnSelf ();
122
151
// break code execution
123
- $ this ->category ->expects ($ this ->once ( ))->method ('isObjectNew ' )->willReturn (true );
152
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (true );
124
153
125
154
$ this ->categoryUrlPathAutogeneratorObserver ->execute ($ this ->observer );
126
155
}
@@ -134,7 +163,7 @@ public function testUrlPathAttributeNoUpdatingIfCategoryIsNew()
134
163
$ this ->category ->expects ($ this ->any ())->method ('setUrlKey ' )->willReturnSelf ();
135
164
$ this ->category ->expects ($ this ->any ())->method ('setUrlPath ' )->willReturnSelf ();
136
165
137
- $ this ->category ->expects ($ this ->once ( ))->method ('isObjectNew ' )->willReturn (true );
166
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (true );
138
167
$ this ->categoryResource ->expects ($ this ->never ())->method ('saveAttribute ' );
139
168
140
169
$ this ->categoryUrlPathAutogeneratorObserver ->execute ($ this ->observer );
@@ -148,7 +177,7 @@ public function testUrlPathAttributeUpdating()
148
177
$ this ->category ->expects ($ this ->any ())->method ('getUrlKey ' )->willReturn ('not_formatted_url_key ' );
149
178
$ this ->category ->expects ($ this ->any ())->method ('setUrlKey ' )->willReturnSelf ();
150
179
$ this ->category ->expects ($ this ->any ())->method ('setUrlPath ' )->willReturnSelf ();
151
- $ this ->category ->expects ($ this ->once ( ))->method ('isObjectNew ' )->willReturn (false );
180
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (false );
152
181
153
182
$ this ->categoryResource ->expects ($ this ->once ())->method ('saveAttribute ' )->with ($ this ->category , 'url_path ' );
154
183
@@ -168,7 +197,7 @@ public function testChildrenUrlPathAttributeNoUpdatingIfParentUrlPathIsNotChange
168
197
$ this ->category ->expects ($ this ->any ())->method ('getUrlKey ' )->willReturn ('not_formatted_url_key ' );
169
198
$ this ->category ->expects ($ this ->any ())->method ('setUrlKey ' )->willReturnSelf ();
170
199
$ this ->category ->expects ($ this ->any ())->method ('setUrlPath ' )->willReturnSelf ();
171
- $ this ->category ->expects ($ this ->once ( ))->method ('isObjectNew ' )->willReturn (false );
200
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (false );
172
201
// break code execution
173
202
$ this ->category ->expects ($ this ->once ())->method ('dataHasChangedFor ' )->with ('url_path ' )->willReturn (false );
174
203
@@ -183,7 +212,7 @@ public function testChildrenUrlPathAttributeUpdatingForSpecificStore()
183
212
$ this ->category ->expects ($ this ->any ())->method ('getUrlKey ' )->willReturn ('not_formatted_url_key ' );
184
213
$ this ->category ->expects ($ this ->any ())->method ('setUrlKey ' )->willReturnSelf ();
185
214
$ this ->category ->expects ($ this ->any ())->method ('setUrlPath ' )->willReturnSelf ();
186
- $ this ->category ->expects ($ this ->any ( ))->method ('isObjectNew ' )->willReturn (false );
215
+ $ this ->category ->expects ($ this ->exactly ( 2 ))->method ('isObjectNew ' )->willReturn (false );
187
216
$ this ->category ->expects ($ this ->any ())->method ('dataHasChangedFor ' )->willReturn (true );
188
217
// only for specific store
189
218
$ this ->category ->expects ($ this ->atLeastOnce ())->method ('getStoreId ' )->willReturn (1 );
0 commit comments