13
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
14
14
use Magento \Framework \Api \SearchCriteriaInterface ;
15
15
use Magento \Framework \Search \Request \BucketInterface ;
16
+ use Magento \Framework \Search \Request \Config ;
16
17
use Magento \Framework \Search \RequestInterface ;
17
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
18
19
@@ -38,6 +39,11 @@ class AggregationResolverTest extends \PHPUnit_Framework_TestCase
38
39
*/
39
40
private $ request ;
40
41
42
+ /**
43
+ * @var Config|\PHPUnit_Framework_MockObject_MockObject
44
+ */
45
+ private $ config ;
46
+
41
47
/**
42
48
* @var AggregationResolver
43
49
*/
@@ -51,13 +57,15 @@ protected function setUp()
51
57
->disableOriginalConstructor ()
52
58
->getMock ();
53
59
$ this ->request = $ this ->getMock (RequestInterface::class);
60
+ $ this ->config = $ this ->getMockBuilder (Config::class)->disableOriginalConstructor ()->getMock ();
54
61
55
62
$ this ->aggregationResolver = (new ObjectManager ($ this ))->getObject (
56
63
AggregationResolver::class,
57
64
[
58
65
'attributeSetFinder ' => $ this ->attributeSetFinder ,
59
66
'productAttributeRepository ' => $ this ->productAttributeRepository ,
60
67
'searchCriteriaBuilder ' => $ this ->searchCriteriaBuilder ,
68
+ 'config ' => $ this ->config ,
61
69
]
62
70
);
63
71
}
@@ -66,6 +74,7 @@ public function testResolve()
66
74
{
67
75
$ documentIds = [1 , 2 , 3 ];
68
76
$ attributeSetIds = [4 , 5 ];
77
+ $ requestName = 'request_name ' ;
69
78
70
79
$ this ->attributeSetFinder
71
80
->expects ($ this ->once ())
@@ -113,11 +122,28 @@ public function testResolve()
113
122
$ bucketSecond ->expects ($ this ->once ())
114
123
->method ('getField ' )
115
124
->willReturn ('some_another_code ' );
125
+ $ bucketThird = $ this ->getMock (BucketInterface::class);
126
+ $ bucketThird ->expects ($ this ->once ())
127
+ ->method ('getName ' )
128
+ ->willReturn ('custom_not_attribute_field ' );
116
129
117
130
$ this ->request ->expects ($ this ->once ())
118
131
->method ('getAggregation ' )
119
- ->willReturn ([$ bucketFirst , $ bucketSecond ]);
120
-
121
- $ this ->assertEquals ([$ bucketFirst ], $ this ->aggregationResolver ->resolve ($ this ->request , $ documentIds ));
132
+ ->willReturn ([$ bucketFirst , $ bucketSecond , $ bucketThird ]);
133
+ $ this ->request ->expects ($ this ->once ())
134
+ ->method ('getName ' )
135
+ ->willReturn ($ requestName );
136
+
137
+ $ this ->config ->expects ($ this ->once ())
138
+ ->method ('get ' )
139
+ ->with ($ requestName )
140
+ ->willReturn ([
141
+ 'aggregations ' => ['custom_not_attribute_field ' => []],
142
+ ]);
143
+
144
+ $ this ->assertEquals (
145
+ [$ bucketFirst , $ bucketThird ],
146
+ $ this ->aggregationResolver ->resolve ($ this ->request , $ documentIds )
147
+ );
122
148
}
123
149
}
0 commit comments