@@ -84,9 +84,7 @@ public function setUp()
84
84
$ this ->product = $ this ->getMockBuilder (Product::class)
85
85
->disableOriginalConstructor ()
86
86
->setMethods ([
87
- 'getProductCategories ' ,
88
- 'dataHasChangedFor ' ,
89
- 'getVisibility '
87
+ 'getProductCategories '
90
88
])
91
89
->getMock ();
92
90
@@ -98,24 +96,58 @@ public function setUp()
98
96
99
97
}
100
98
101
- public function testVisibility ()
99
+ /**
100
+ * @dataProvider visibilityProvider
101
+ * @param integer $before
102
+ * @param integer $after
103
+ */
104
+ public function testVisibility ($ before , $ after )
102
105
{
106
+ $ this ->product ->setOrigData ('visibility ' , $ before );
107
+ $ this ->product ->setData ('visibility ' , $ after );
108
+
103
109
$ this ->productUrlRewriteGenerator ->expects (static ::once ())
104
110
->method ('generate ' )
105
111
->with ($ this ->product )
106
- ->willReturn ([]);
107
- $ this ->urlPersist ->expects (static ::atLeastOnce ())
112
+ ->willReturn ([' test ' ]);
113
+ $ this ->urlPersist ->expects (static ::once ())
108
114
->method ('replace ' )
109
- ->with ([]);
110
- $ this ->product ->expects (static ::atLeastOnce ())
111
- ->method ('getVisibility ' )
112
- ->willReturn (Visibility::VISIBILITY_IN_CATALOG );
113
- $ this ->product ->expects (static ::atLeastOnce ())
114
- ->method ('dataHasChangedFor ' )
115
- ->willReturnMap ([
116
- ['visibility ' , true ],
117
- ]);
115
+ ->with (['test ' ]);
118
116
119
117
$ this ->productProcessUrlRewriteSavingObserver ->execute ($ this ->observer );
120
118
}
119
+
120
+ public function visibilityProvider ()
121
+ {
122
+ return [
123
+ ['origData ' => Visibility::VISIBILITY_NOT_VISIBLE , 'data ' => Visibility::VISIBILITY_IN_CATALOG ],
124
+ ['origData ' => null , 'data ' => Visibility::VISIBILITY_IN_CATALOG ],
125
+ ['origData ' => Visibility::VISIBILITY_BOTH , 'data ' => Visibility::VISIBILITY_IN_SEARCH ],
126
+ ];
127
+ }
128
+
129
+ /**
130
+ * @dataProvider notVisibilityProvider
131
+ * @param integer $before
132
+ * @param integer $after
133
+ */
134
+ public function testNotVisibility ($ before , $ after )
135
+ {
136
+ $ this ->product ->setOrigData ('visibility ' , $ before );
137
+ $ this ->product ->setData ('visibility ' , $ after );
138
+
139
+ $ this ->productUrlRewriteGenerator ->expects (static ::never ())->method ('generate ' );
140
+ $ this ->urlPersist ->expects (static ::never ())->method ('replace ' );
141
+
142
+ $ this ->productProcessUrlRewriteSavingObserver ->execute ($ this ->observer );
143
+ }
144
+
145
+ public function notVisibilityProvider ()
146
+ {
147
+ return [
148
+ ['origData ' => Visibility::VISIBILITY_IN_SEARCH , 'data ' => Visibility::VISIBILITY_IN_SEARCH ],
149
+ ['origData ' => Visibility::VISIBILITY_IN_CATALOG , 'data ' => Visibility::VISIBILITY_NOT_VISIBLE ],
150
+ ['origData ' => null , 'data ' => Visibility::VISIBILITY_NOT_VISIBLE ],
151
+ ];
152
+ }
121
153
}
0 commit comments