public function testArrayToConditionDataModel()
 {
     $array = ['type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', 'attribute' => null, 'operator' => null, 'value' => 1, 'is_value_processed' => null, 'aggregator' => 'all', 'conditions' => [['type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', 'attribute' => 'base_subtotal', 'operator' => '>=', 'value' => 100, 'is_value_processed' => null], ['type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', 'attribute' => 'total_qty', 'operator' => '>', 'value' => 2, 'is_value_processed' => null], ['type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', 'attribute' => null, 'operator' => null, 'value' => 1, 'is_value_processed' => null, 'aggregator' => 'all', 'conditions' => [['type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', 'attribute' => 'category_ids', 'operator' => '==', 'value' => 3, 'is_value_processed' => null]]]]];
     $dataCondition = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Data\\Condition')->setMethods(['setData'])->disableOriginalConstructor()->getMock();
     $this->conditionDataFactory->expects($this->any())->method('create')->willReturn($dataCondition);
     $return = $this->model->arrayToConditionDataModel($array);
     $this->assertEquals($dataCondition, $return);
 }
 public function testSave()
 {
     $rule = $this->getMock('\\Magento\\SalesRule\\Model\\Data\\Rule', [], [], '', false);
     $model = $this->getMock('\\Magento\\SalesRule\\Model\\Rule', [], [], '', false);
     $this->toModelConverter->expects($this->once())->method('toModel')->with($rule)->willReturn($model);
     $model->expects($this->once())->method('save');
     $model->expects($this->once())->method('getId')->willReturn(10);
     $model->expects($this->once())->method('load')->with(10);
     $model->expects($this->once())->method('getStoreLabels');
     $this->toDataModelConverter->expects($this->once())->method('toDataModel')->with($model)->willReturn($rule);
     $this->assertEquals($rule, $this->ruleRepository->save($rule));
 }
 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $collection */
     $collection = $this->ruleCollectionFactory->create();
     $ruleInterfaceName = 'Magento\\SalesRule\\Api\\Data\\RuleInterface';
     $this->extensionAttributesJoinProcessor->process($collection, $ruleInterfaceName);
     $collection->addWebsitesToResult();
     //Add filters from root filter group to the collection
     /** @var FilterGroup $group */
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders === null) {
         $sortOrders = [];
     }
     /** @var \Magento\Framework\Api\SortOrder $sortOrder */
     foreach ($sortOrders as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $collection->load();
     $rules = [];
     /** @var \Magento\SalesRule\Model\Rule $ruleModel */
     foreach ($collection->getItems() as $ruleModel) {
         $ruleModel->getCustomerGroupIds();
         $ruleModel->getStoreLabels();
         $rules[] = $this->toDataModelConverter->toDataModel($ruleModel);
     }
     $searchResults = $this->searchResultFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     $searchResults->setItems($rules);
     $searchResults->setTotalCount($collection->getSize());
     return $searchResults;
 }