/** * @param int $direction * @param string $expectedDirection * @dataProvider getListSuccessDataProvider */ public function testGetListSuccess($direction, $expectedDirection) { $searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false); $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false); $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $pageSize = 10; $this->searchResultsDataFactory->expects($this->once())->method('create')->will($this->returnValue($searchResult)); $searchResult->expects($this->once())->method('setSearchCriteria'); $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock])); //addFilterGroupToCollection() checks $filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock])); $filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id')); $filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq')); $filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value')); //back in getList() $this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize); $searchResult->expects($this->once())->method('setTotalCount')->with($pageSize); $sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock(); //foreach cycle $searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock])); $sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id')); $sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction)); $this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection); $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1)); $searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10)); $this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1); $this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10); $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('\\Magento\\Quote\\Model\\ResourceModel\\Quote\\Collection')); $this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]); $searchResult->expects($this->once())->method('setItems')->with([$cartMock]); $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock)); }
/** * Get select count sql * * @return \Magento\Framework\DB\Select */ public function getSelectCountSql() { if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) { $countSelect = clone $this->quoteResource->getSelect(); $countSelect->reset()->from(['quote_item_table' => $this->getTable('quote_item')], ['COUNT(DISTINCT quote_item_table.product_id)'])->join(['quote_table' => $this->getTable('quote')], 'quote_table.entity_id = quote_item_table.quote_id AND quote_table.is_active = 1', []); return $countSelect; } $countSelect = clone $this->getSelect(); $countSelect->reset(\Magento\Framework\DB\Select::ORDER); $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS); $countSelect->reset(\Magento\Framework\DB\Select::GROUP); $countSelect->reset(\Magento\Framework\DB\Select::HAVING); $countSelect->columns("count(DISTINCT e.entity_id)"); return $countSelect; }
/** * Adds a specified filter group to the specified quote collection. * * @param FilterGroup $filterGroup The filter group. * @param QuoteCollection $collection The quote collection. * @return void * @throws InputException The specified filter group or quote collection does not exist. */ protected function addFilterGroupToCollection(FilterGroup $filterGroup, QuoteCollection $collection) { $fields = []; $conditions = []; foreach ($filterGroup->getFilters() as $filter) { $fields[] = $filter->getField(); $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; $conditions[] = [$condition => $filter->getValue()]; } if ($fields) { $collection->addFieldToFilter($fields, $conditions); } }
private function assertQuoteCollectionNotContains(Quote $expected) { $message = sprintf('The quote with ID "%s" is contained in the quote collection, but was expected to be absent', $expected->getId()); $this->assertNotContains($expected->getId(), $this->quoteCollection->getAllIds(), $message); }
/** * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot * @param \Magento\Customer\Model\ResourceModel\Customer $customerResource * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource */ public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, \Magento\Customer\Model\ResourceModel\Customer $customerResource, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null) { parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $entitySnapshot, $connection, $resource); $this->customerResource = $customerResource; }