/** * {@inheritdoc} */ public function save(\Magento\SalesRule\Api\Data\RuleInterface $rule) { $model = $this->toModelConverter->toModel($rule); $model->save(); $model->load($model->getId()); $model->getStoreLabels(); return $this->toDataModelConverter->toDataModel($model); }
public function testToModel() { /** * @var \Magento\SalesRule\Model\Data\Rule $dataModel */ $dataModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Data\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getData', 'getRuleId', 'getCondition', 'getActionCondition', 'getStoreLabels'])->getMock(); $dataModel->expects($this->atLeastOnce())->method('getRuleId')->willReturn(1); $dataModel->expects($this->atLeastOnce())->method('getCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getActionCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getStoreLabels')->willReturn([]); $ruleModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getId', 'getData'])->getMock(); $ruleModel->expects($this->atLeastOnce())->method('load')->willReturn($ruleModel); $ruleModel->expects($this->atLeastOnce())->method('getId')->willReturn(1); $ruleModel->expects($this->atLeastOnce())->method('getData')->willReturn(['data_1' => 1]); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->willReturn(['data_2' => 2]); $this->ruleFactory->expects($this->any())->method('create')->willReturn($ruleModel); $result = $this->model->toModel($dataModel); $this->assertEquals($ruleModel, $result); }
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)); }
/** * @dataProvider expectedDatesProvider */ public function testFormattingDate($data) { /** * @var \Magento\SalesRule\Model\Data\Rule|\PHPUnit_Framework_MockObject_MockObject $dataModel */ $dataModel = $this->getMockBuilder(\Magento\SalesRule\Model\Data\Rule::class)->disableOriginalConstructor()->setMethods(['create', 'load', 'getData', 'getRuleId', 'getCondition', 'getActionCondition', 'getStoreLabels', 'getFromDate', 'setFromDate', 'getToDate', 'setToDate'])->getMock(); $dataModel->expects($this->atLeastOnce())->method('getRuleId')->willReturn(null); $dataModel->expects($this->atLeastOnce())->method('getCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getActionCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getStoreLabels')->willReturn([]); $ruleModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getId', 'getData'])->getMock(); $ruleModel->expects($this->atLeastOnce())->method('getData')->willReturn(['data_1' => 1]); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->willReturn(['data_2' => 2]); $this->ruleFactory->expects($this->any())->method('create')->willReturn($ruleModel); $dataModel->expects($this->atLeastOnce())->method('getFromDate')->willReturn($data['from_date']); $dataModel->expects($this->atLeastOnce())->method('getToDate')->willReturn($data['to_date']); $dataModel->expects($this->atLeastOnce())->method('setFromDate')->with($data['expected_from_date']); $dataModel->expects($this->atLeastOnce())->method('setToDate')->with($data['expected_to_date']); $this->model->toModel($dataModel); }