@@ -2096,9 +2096,38 @@ public function testSaveUnknownDataWhenEmptyInputFilter()
2096
2096
$ this ->assertEquals ($ params , $ dataParams ->getBodyParams ());
2097
2097
}
2098
2098
2099
- public function testFilterEmptyEntriesFromDataByOptionWithNestedData ()
2099
+ /**
2100
+ * @group 40 removeEmptyData
2101
+ *
2102
+ * @param array $eventParams
2103
+ *
2104
+ * @return MvcEvent
2105
+ */
2106
+ public function createGroup40Event (array $ eventParams )
2107
+ {
2108
+ $ request = new HttpRequest ();
2109
+ $ request ->setMethod ('POST ' );
2110
+
2111
+ $ matches = $ this ->createRouteMatch (['controller ' => 'Foo ' ]);
2112
+
2113
+ $ dataParams = new ParameterDataContainer ();
2114
+ $ dataParams ->setBodyParams ($ eventParams );
2115
+
2116
+ $ event = new MvcEvent ();
2117
+ $ event ->setRequest ($ request );
2118
+ $ event ->setRouteMatch ($ matches );
2119
+ $ event ->setParam ('ZFContentNegotiationParameterData ' , $ dataParams );
2120
+
2121
+ return $ event ;
2122
+ }
2123
+
2124
+ /**
2125
+ * @group 40 removeEmptyData
2126
+ *
2127
+ * @return ContentValidationListener
2128
+ */
2129
+ public function createGroup40Listener ()
2100
2130
{
2101
- $ services = new ServiceManager ();
2102
2131
$ factory = new InputFilterFactory ();
2103
2132
2104
2133
$ inputFilterA = $ factory ->createInputFilter (
@@ -2141,9 +2170,10 @@ public function testFilterEmptyEntriesFromDataByOptionWithNestedData()
2141
2170
2142
2171
$ inputFilterA ->add ($ inputFilterB , 'empty_array ' );
2143
2172
2173
+ $ services = new ServiceManager ();
2144
2174
$ services ->setService ('FooFilter ' , $ inputFilterA );
2145
2175
2146
- $ listener = new ContentValidationListener (
2176
+ return new ContentValidationListener (
2147
2177
[
2148
2178
'Foo ' => [
2149
2179
'input_filter ' => 'FooFilter ' ,
@@ -2157,27 +2187,168 @@ public function testFilterEmptyEntriesFromDataByOptionWithNestedData()
2157
2187
'Foo ' => 'foo_id ' ,
2158
2188
]
2159
2189
);
2190
+ }
2160
2191
2161
- $ request = new HttpRequest ();
2162
- $ request ->setMethod ('POST ' );
2192
+ /**
2193
+ * @group 40 removeEmptyData
2194
+ *
2195
+ * Flows:
2196
+ * 1 - data is empty, return immediately
2197
+ * 2 - loop key/value - value (is not an array and (not empty or (is a boolean & not in comparison array)))
2198
+ * 3 - loop key/value - value is not an array
2199
+ * 4 - after filtering value, value is empty
2200
+ * 5 - value is an array containing recursive data (subject to 1 through 4)
2201
+ *
2202
+ * This test does #1
2203
+ */
2204
+ public function testFilterEmptyEntriesFromDataByOptionWhenDataEmpty ()
2205
+ {
2206
+ // empty array
2207
+ $ event = $ this ->createGroup40Event ([]);
2163
2208
2164
- $ matches = $ this ->createRouteMatch (['controller ' => 'Foo ' ]);
2209
+ $ listener = $ this ->createGroup40Listener ();
2210
+ $ listener ->onRoute ($ event );
2165
2211
2166
- $ params = [
2167
- 'foo ' => ' abc ' ,
2168
- 'empty ' => null ,
2169
- 'empty_array ' => [
2170
- 'empty_field ' => null ,
2212
+ $ this ->assertEquals (
2213
+ [],
2214
+ $ event ->getParam ('ZFContentNegotiationParameterData ' )->getBodyParams ()
2215
+ );
2216
+ }
2217
+
2218
+ /**
2219
+ * @group 40 removeEmptyData
2220
+ *
2221
+ * Flows:
2222
+ * 1 - data is empty, return immediately
2223
+ * 2 - loop key/value - value (is not an array and (not empty or (is a boolean & not in comparison array)))
2224
+ * 3 - loop key/value - value is not an array
2225
+ * 4 - after filtering value, value is empty
2226
+ * 5 - value is an array containing recursive data (subject to 1 through 4)
2227
+ *
2228
+ * This test does #2 (twice, once for 'true', once for 'false')
2229
+ */
2230
+ public function testFilterEmptyEntriesFromDataByOptionWhenValueBooleanNotInComparison ()
2231
+ {
2232
+ $ event = $ this ->createGroup40Event (
2233
+ [
2234
+ 'foo ' => true ,
2235
+ ]
2236
+ );
2237
+
2238
+ $ listener = $ this ->createGroup40Listener ();
2239
+ $ listener ->onRoute ($ event );
2240
+
2241
+ $ this ->assertEquals (
2242
+ [
2243
+ 'foo ' => true ,
2171
2244
],
2172
- ];
2245
+ $ event ->getParam ('ZFContentNegotiationParameterData ' )->getBodyParams ()
2246
+ );
2173
2247
2174
- $ dataParams = new ParameterDataContainer ();
2175
- $ dataParams ->setBodyParams ($ params );
2248
+ $ event2 = $ this ->createGroup40Event (
2249
+ [
2250
+ 'foo ' => false ,
2251
+ ]
2252
+ );
2176
2253
2177
- $ event = new MvcEvent ();
2178
- $ event ->setRequest ($ request );
2179
- $ event ->setRouteMatch ($ matches );
2180
- $ event ->setParam ('ZFContentNegotiationParameterData ' , $ dataParams );
2254
+ $ listener2 = $ this ->createGroup40Listener ();
2255
+ $ listener2 ->onRoute ($ event2 );
2256
+
2257
+ $ this ->assertEquals (
2258
+ [
2259
+ 'foo ' => false ,
2260
+ ],
2261
+ $ event2 ->getParam ('ZFContentNegotiationParameterData ' )->getBodyParams ()
2262
+ );
2263
+ }
2264
+
2265
+ /**
2266
+ * @group 40 removeEmptyData
2267
+ *
2268
+ * Flows:
2269
+ * 1 - data is empty, return immediately
2270
+ * 2 - loop key/value - value (is not an array and (not empty or (is a boolean & not in comparison array)))
2271
+ * 3 - loop key/value - value is not an array
2272
+ * 4 - after filtering value, value is empty
2273
+ * 5 - value is an array containing recursive data (subject to 1 through 4)
2274
+ *
2275
+ * This test does #3
2276
+ */
2277
+ public function testFilterEmptyEntriesFromDataByOptionWhenValueNotAnArray ()
2278
+ {
2279
+ $ event = $ this ->createGroup40Event (
2280
+ [
2281
+ 'foo ' => ' string ' ,
2282
+ ]
2283
+ );
2284
+
2285
+ $ listener = $ this ->createGroup40Listener ();
2286
+ $ listener ->onRoute ($ event );
2287
+
2288
+ $ this ->assertEquals (
2289
+ [
2290
+ 'foo ' => 'string ' ,
2291
+ ],
2292
+ $ event ->getParam ('ZFContentNegotiationParameterData ' )->getBodyParams ()
2293
+ );
2294
+ }
2295
+
2296
+ /**
2297
+ * @group 40 removeEmptyData
2298
+ *
2299
+ * Flows:
2300
+ * 1 - data is empty, return immediately
2301
+ * 2 - loop key/value - value (is not an array and (not empty or (is a boolean & not in comparison array)))
2302
+ * 3 - loop key/value - value is not an array
2303
+ * 4 - after filtering value, value is empty
2304
+ * 5 - value is an array containing recursive data (subject to 1 through 4)
2305
+ *
2306
+ * This test does #4
2307
+ */
2308
+ public function testFilterEmptyEntriesFromDataByOptionWhenValueEmptyAfterFilter ()
2309
+ {
2310
+ $ event = $ this ->createGroup40Event (
2311
+ [
2312
+ 'foo ' => [
2313
+ 'test ' => []
2314
+ ],
2315
+ ]
2316
+ );
2317
+
2318
+ $ listener = $ this ->createGroup40Listener ();
2319
+ $ listener ->onRoute ($ event );
2320
+
2321
+ $ this ->assertEquals (
2322
+ [],
2323
+ $ event ->getParam ('ZFContentNegotiationParameterData ' )->getBodyParams ()
2324
+ );
2325
+ }
2326
+
2327
+ /**
2328
+ * @group 40 removeEmptyData
2329
+ *
2330
+ * Flows:
2331
+ * 1 - data is empty, return immediately
2332
+ * 2 - loop key/value - value (is not an array and (not empty or (is a boolean & not in comparison array)))
2333
+ * 3 - loop key/value - value is not an array
2334
+ * 4 - after filtering value, value is empty
2335
+ * 5 - value is an array containing recursive data (subject to 1 through 4)
2336
+ *
2337
+ * This test does #5
2338
+ */
2339
+ public function testFilterEmptyEntriesFromDataByOptionWithNestedData ()
2340
+ {
2341
+ $ event = $ this ->createGroup40Event (
2342
+ [
2343
+ 'foo ' => ' abc ' ,
2344
+ 'empty ' => null ,
2345
+ 'empty_array ' => [
2346
+ 'empty_field ' => null ,
2347
+ ],
2348
+ ]
2349
+ );
2350
+
2351
+ $ listener = $ this ->createGroup40Listener ();
2181
2352
2182
2353
$ listener ->onRoute ($ event );
2183
2354
@@ -2190,7 +2361,7 @@ public function testFilterEmptyEntriesFromDataByOptionWithNestedData()
2190
2361
[
2191
2362
'foo ' => 'abc ' ,
2192
2363
],
2193
- $ dataParams ->getBodyParams ()
2364
+ $ event -> getParam ( ' ZFContentNegotiationParameterData ' ) ->getBodyParams ()
2194
2365
);
2195
2366
}
2196
2367
0 commit comments