8 use \Magento\Framework\Data\SearchResultProcessor;
32 $this->searchCriteriaMock = $this->getMockBuilder(\
Magento\Framework\Api\CriteriaInterface::class)
33 ->disableOriginalConstructor()
36 $this->searchResultCollectionMock = $this->getMockBuilder(\
Magento\Framework\Data\AbstractSearchResult::class)
37 ->disableOriginalConstructor()
38 ->setMethods([
'getSearchCriteria',
'getItems',
'getItemId'])
39 ->getMockForAbstractClass();
40 $this->searchResultCollectionMock->expects($this->any())
41 ->method(
'getSearchCriteria')
42 ->willReturn($this->searchCriteriaMock);
49 $this->searchCriteriaMock->expects($this->once())
51 ->willReturn([
$page]);
52 $this->assertEquals(
$page, $this->searchResultProcessor->getCurrentPage());
58 $this->searchCriteriaMock->expects($this->once())
60 ->willReturn([
null, $size]);
61 $this->assertEquals($size, $this->searchResultProcessor->getPageSize());
66 $itemData = [
'id' => 1];
67 $itemData2 = [
'id' => 2];
69 $testItem = new \Magento\Framework\DataObject($itemData);
70 $testItem2 = new \Magento\Framework\DataObject($itemData2);
72 $this->searchResultCollectionMock->expects($this->once())
74 ->willReturn([$testItem, $testItem2]);
76 $this->assertEquals($testItem, $this->searchResultProcessor->getFirstItem());
81 $itemData = [
'id' => 1];
82 $itemData2 = [
'id' => 2];
84 $testItem = new \Magento\Framework\DataObject($itemData);
85 $testItem2 = new \Magento\Framework\DataObject($itemData2);
87 $this->searchResultCollectionMock->expects($this->once())
89 ->willReturn([$testItem, $testItem2]);
91 $this->assertEquals($testItem2, $this->searchResultProcessor->getLastItem());
96 $itemData = [
'id' => 1];
99 $testItem = new \Magento\Framework\DataObject($itemData);
101 $this->searchResultCollectionMock->expects($this->once())
103 ->willReturn([$testItem]);
104 $this->searchResultCollectionMock->expects($this->once())
105 ->method(
'getItemId')
109 $this->assertEquals($ids, $this->searchResultProcessor->getAllIds());
114 $itemData = [
'id' => 1];
115 $itemData2 = [
'id' => 2];
117 $testItem = new \Magento\Framework\DataObject($itemData);
118 $testItem2 = new \Magento\Framework\DataObject($itemData2);
120 $this->searchResultCollectionMock->expects($this->once())
122 ->willReturn([1 => $testItem, $testItem2]);
124 $this->assertEquals($testItem2, $this->searchResultProcessor->getItemById(2));
129 $columnKey =
'columnKey';
130 $columnValue =
'columnValue';
131 $itemData = [
'id' => 1, $columnKey => $columnValue];
133 $testItem = new \Magento\Framework\DataObject($itemData);
135 $this->searchResultCollectionMock->expects($this->once())
137 ->willReturn([$testItem]);
138 $this->assertEquals([$columnValue], $this->searchResultProcessor->getColumnValues($columnKey));
143 $columnKey =
'columnKey';
144 $columnValue =
'columnValue';
145 $itemData = [
'id' => 1, $columnKey => $columnValue];
146 $itemData2 = [
'id' => 2, $columnKey => $columnValue];
148 $testItem = new \Magento\Framework\DataObject($itemData);
149 $testItem2 = new \Magento\Framework\DataObject($itemData2);
151 $this->searchResultCollectionMock->expects($this->once())
153 ->willReturn([$testItem, $testItem2]);
156 [$testItem, $testItem2],
157 $this->searchResultProcessor->getItemsByColumnValue($columnKey, $columnValue)
163 $columnKey =
'columnKey';
164 $columnValue =
'columnValue';
165 $columnValue2 =
'columnValue2';
166 $itemData = [
'id' => 1, $columnKey => $columnValue];
167 $itemData2 = [
'id' => 2, $columnKey => $columnValue2];
169 $testItem = new \Magento\Framework\DataObject($itemData);
170 $testItem2 = new \Magento\Framework\DataObject($itemData2);
172 $this->searchResultCollectionMock->expects($this->once())
174 ->willReturn([$testItem, $testItem2]);
176 $this->assertEquals($testItem2, $this->searchResultProcessor->getItemByColumnValue($columnKey, $columnValue2));
testGetItemsByColumnValue()
testGetItemByColumnValue()
$searchResultCollectionMock