Esempio n. 1
0
 /**
  * @param Rule $ruleModel
  * @return RuleDataModel
  */
 public function toDataModel(\Magento\SalesRule\Model\Rule $ruleModel)
 {
     /** @var \Magento\SalesRule\Model\Data\Rule $dataModel */
     $dataModel = $this->ruleDataFactory->create(['data' => $ruleModel->getData()]);
     $this->mapFields($dataModel, $ruleModel);
     return $dataModel;
 }
 public function testToDataModel()
 {
     $array = ['rule_id' => '1', 'name' => 'testrule', 'is_active' => '1', 'conditions_serialized' => 'a:7:{s:4:"type";s:46:"Magento\\SalesRule\\Model\\Rule\\Condition\\Combine";s:9:"attribute";N;' . 's:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";' . 's:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:46:"Magento\\SalesRule\\Model\\Rule\\Condition\\Address";' . 's:9:"attribute";s:13:"base_subtotal";s:8:"operator";s:2:">=";s:5:"value";s:3:"100";' . 's:18:"is_value_processed";b:0;}}}', 'actions_serialized' => 'a:7:{s:4:"type";s:54:"Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine";s:9:"attribute";N;' . 's:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";' . 's:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:46:"Magento\\SalesRule\\Model\\Rule\\Condition\\Product";' . 's:9:"attribute";s:16:"attribute_set_id";s:8:"operator";s:2:"==";s:5:"value";s:1:"4";' . 's:18:"is_value_processed";b:0;}}}', 'coupon_type' => '1', 'coupon_code' => '', 'store_labels' => [0 => 'TestRule', 1 => 'TestRuleForDefaultStore']];
     $dataModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Data\\Rule')->disableOriginalConstructor()->setMethods(['create', 'getStoreLabels', 'setStoreLabels', 'getCouponType', 'setCouponType'])->getMock();
     $dataLabel = $this->getMockBuilder('\\Magento\\SalesRule\\Api\\Data\\RuleLabel')->setMethods(['setStoreId', 'setStoreLabel', 'setStoreLabels'])->disableOriginalConstructor()->getMock();
     $dataCondition = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Data\\Condition')->setMethods(['setData'])->disableOriginalConstructor()->getMock();
     $this->ruleLabelFactory->expects($this->any())->method('create')->willReturn($dataLabel);
     $this->conditionDataFactory->expects($this->any())->method('create')->willReturn($dataCondition);
     $this->ruleDataFactory->expects($this->any())->method('create')->willReturn($dataModel);
     $this->salesRule->expects($this->any())->method('getData')->willReturn($array);
     $this->salesRule->expects($this->once())->method('getConditionsSerialized')->willReturn($array['conditions_serialized']);
     $dataModel->expects($this->atLeastOnce())->method('getStoreLabels')->willReturn($array['store_labels']);
     $dataModel->expects($this->atLeastOnce())->method('setStoreLabels');
     $dataModel->expects($this->atLeastOnce())->method('getCouponType')->willReturn(\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON);
     $dataModel->expects($this->atLeastOnce())->method('setCouponType');
     $return = $this->model->toDataModel($this->salesRule);
     $this->assertSame($dataModel, $return);
 }