41 $this->requestMock = $this->createMock(\
Magento\Framework\Webapi\Rest\Request::class);
43 $this->sampleResponseValue = [
47 'created_in' =>
'Default Store View',
50 'custom_attributes' => [
52 'attribute_code' =>
'disable_auto_group_change',
56 'firstname' =>
'Jane',
59 'default_billing' =>
'1',
60 'default_shipping' =>
'1',
61 'created_at' =>
'2014-05-27 18:59:43',
62 'dob' =>
'1983-05-26 00:00:00',
63 'taxvat' =>
'1212121212',
68 'firstname' =>
'Jane',
71 0 =>
'7700 Parmer ln',
78 'region_code' =>
'TX',
80 'postcode' =>
'78728',
81 'telephone' =>
'1111111111',
82 'default_billing' =>
true,
83 'default_shipping' =>
true,
88 'firstname' =>
'Jane',
91 0 =>
'2211 N First St ',
96 'region' =>
'California',
98 'region_code' =>
'CA',
100 'postcode' =>
'98454',
101 'telephone' =>
'2222222222',
102 'default_billing' =>
true,
103 'default_shipping' =>
true,
105 'customer_id' =>
'1',
113 $expected = [
'customer' => $this->sampleResponseValue[
'customer']];
115 $simpleFilter =
'customer';
116 $this->requestMock->expects($this->any())->method(
'getParam')->will($this->returnValue($simpleFilter));
117 $filteredResponse = $this->processor->filter($this->sampleResponseValue);
119 $this->assertEquals($expected, $filteredResponse);
126 'email' => $this->sampleResponseValue[
'customer'][
'email'],
127 'id' => $this->sampleResponseValue[
'customer'][
'id'],
131 $simpleFilter =
"customer[email,id]";
133 $this->requestMock->expects($this->any())->method(
'getParam')->will($this->returnValue($simpleFilter));
134 $filteredResponse = $this->processor->filter($this->sampleResponseValue);
136 $this->assertEquals($expected, $filteredResponse);
151 'region_code' =>
'TX',
153 'postcode' =>
'78728',
156 'city' =>
'San Jose',
158 'region' =>
'California',
159 'region_code' =>
'CA',
161 'postcode' =>
'98454',
166 $nestedFilter =
'customer[id,email],addresses[city,postcode,region[region_code,region]]';
168 $this->requestMock->expects($this->any())->method(
'getParam')->will($this->returnValue($nestedFilter));
169 $filteredResponse = $this->processor->filter($this->sampleResponseValue);
171 $this->assertEquals($expected, $filteredResponse);
187 'region_code' =>
'TX',
189 'postcode' =>
'78728',
194 'region' =>
'California',
195 'region_code' =>
'CA',
197 'postcode' =>
'98454',
202 $nonExistentFieldFilter =
'customer[id,email],addresses[invalid,postcode,region[region_code,region]]';
205 ->expects($this->any())
207 ->will($this->returnValue($nonExistentFieldFilter));
208 $filteredResponse = $this->processor->filter($this->sampleResponseValue);
210 $this->assertEquals($expected, $filteredResponse);
218 $this->requestMock->expects($this->any())->method(
'getParam')->will($this->returnValue($invalidFilter));
219 $filteredResponse = $this->processor->filter($this->sampleResponseValue);
221 $this->assertEmpty($filteredResponse);
235 [
' customer[email]'],
237 [
'customer[id,email],addresses[city,postcode,region[region_code,region]']
testInvalidFilters($invalidFilter)
testFilterSimpleNesting()
testFilterMultilevelNesting()
testNonExistentFieldFilter()
invalidFilterDataProvider()