27 $this->ruleFactory = $this->getMockBuilder(\
Magento\SalesRule\Model\RuleFactory::class)
28 ->disableOriginalConstructor()
29 ->setMethods([
'create'])
32 $this->dataObjectProcessor = $this->getMockBuilder(\
Magento\Framework\Reflection\DataObjectProcessor::class)
33 ->disableOriginalConstructor()
37 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38 $this->model =
$helper->getObject(
39 \
Magento\SalesRule\Model\Converter\ToModel::class,
41 'ruleFactory' => $this->ruleFactory,
42 'dataObjectProcessor' => $this->dataObjectProcessor,
47 public function testDataModelToArray()
50 'type' =>
'conditionType',
52 'attribute' =>
'getAttributeName',
53 'operator' =>
'getOperator',
54 'aggregator' =>
'getAggregatorType',
74 $dataCondition = $this->getMockBuilder(\
Magento\SalesRule\Model\Data\Condition::class)
75 ->disableOriginalConstructor()
76 ->setMethods([
'create',
'load',
'getConditionType',
'getValue',
'getAttributeName',
'getOperator',
77 'getAggregatorType',
'getConditions'])
81 ->expects($this->atLeastOnce())
82 ->method(
'getConditionType')
83 ->willReturn(
'conditionType');
86 ->expects($this->atLeastOnce())
88 ->willReturn(
'value');
91 ->expects($this->atLeastOnce())
92 ->method(
'getAttributeName')
93 ->willReturn(
'getAttributeName');
96 ->expects($this->atLeastOnce())
97 ->method(
'getOperator')
98 ->willReturn(
'getOperator');
101 ->expects($this->atLeastOnce())
102 ->method(
'getAggregatorType')
103 ->willReturn(
'getAggregatorType');
105 $dataCondition1 = $this->getMockBuilder(\
Magento\SalesRule\Model\Data\Condition::class)
106 ->disableOriginalConstructor()
107 ->setMethods([
'create',
'load',
'getConditionType',
'getValue',
'getAttributeName',
'getOperator',
108 'getAggregatorType',
'getConditions'])
111 $dataCondition2 = $this->getMockBuilder(\
Magento\SalesRule\Model\Data\Condition::class)
112 ->disableOriginalConstructor()
113 ->setMethods([
'create',
'load',
'getConditionType',
'getValue',
'getAttributeName',
'getOperator',
114 'getAggregatorType',
'getConditions'])
118 ->expects($this->atLeastOnce())
119 ->method(
'getConditions')
120 ->willReturn([$dataCondition1, $dataCondition2]);
122 $result = $this->model->dataModelToArray($dataCondition);
124 $this->assertEquals($array,
$result);
127 public function testToModel()
132 $dataModel = $this->getMockBuilder(\
Magento\SalesRule\Model\Data\Rule::class)
133 ->disableOriginalConstructor()
134 ->setMethods([
'create',
'load',
'getData',
'getRuleId',
'getCondition',
'getActionCondition',
138 ->expects($this->atLeastOnce())
139 ->method(
'getRuleId')
143 ->expects($this->atLeastOnce())
144 ->method(
'getCondition')
148 ->expects($this->atLeastOnce())
149 ->method(
'getActionCondition')
153 ->expects($this->atLeastOnce())
154 ->method(
'getStoreLabels')
157 $ruleModel = $this->getMockBuilder(\
Magento\SalesRule\Model\Rule::class)
158 ->disableOriginalConstructor()
159 ->setMethods([
'create',
'load',
'getId',
'getData'])
163 ->expects($this->atLeastOnce())
165 ->willReturn($ruleModel);
167 ->expects($this->atLeastOnce())
172 ->expects($this->atLeastOnce())
174 ->willReturn([
'data_1'=>1]);
176 $this->dataObjectProcessor
177 ->expects($this->any())
178 ->method(
'buildOutputDataArray')
179 ->willReturn([
'data_2'=>2]);
182 ->expects($this->any())
184 ->willReturn($ruleModel);
186 $result = $this->model->toModel($dataModel);
187 $this->assertEquals($ruleModel,
$result);
193 public function testFormattingDate(
$data)
198 $dataModel = $this->getMockBuilder(\
Magento\SalesRule\Model\Data\Rule::class)
199 ->disableOriginalConstructor()
207 'getActionCondition',
217 ->expects($this->atLeastOnce())
218 ->method(
'getRuleId')
222 ->expects($this->atLeastOnce())
223 ->method(
'getCondition')
227 ->expects($this->atLeastOnce())
228 ->method(
'getActionCondition')
231 ->expects($this->atLeastOnce())
232 ->method(
'getStoreLabels')
234 $ruleModel = $this->getMockBuilder(\
Magento\SalesRule\Model\Rule::class)
235 ->disableOriginalConstructor()
236 ->setMethods([
'create',
'load',
'getId',
'getData'])
239 ->expects($this->atLeastOnce())
241 ->willReturn([
'data_1'=>1]);
243 $this->dataObjectProcessor
244 ->expects($this->any())
245 ->method(
'buildOutputDataArray')
246 ->willReturn([
'data_2'=>2]);
249 ->expects($this->any())
251 ->willReturn($ruleModel);
254 ->expects($this->atLeastOnce())
255 ->method(
'getFromDate')
256 ->willReturn(
$data[
'from_date']);
259 ->expects($this->atLeastOnce())
260 ->method(
'getToDate')
261 ->willReturn(
$data[
'to_date']);
264 ->expects($this->atLeastOnce())
265 ->method(
'setFromDate')
266 ->with(
$data[
'expected_from_date']);
269 ->expects($this->atLeastOnce())
270 ->method(
'setToDate')
271 ->with(
$data[
'expected_to_date']);
273 $this->model->toModel($dataModel);
282 'mm/dd/yyyy to yyyy-mm-dd' => [
284 'from_date' =>
'03/24/2016',
285 'to_date' =>
'03/25/2016',
286 'expected_from_date' =>
'2016-03-24T00:00:00-0700',
287 'expected_to_date' =>
'2016-03-25T00:00:00-0700',
290 'yyyy-mm-dd to yyyy-mm-dd' => [
292 'from_date' =>
'2016-03-24',
293 'to_date' =>
'2016-03-25',
294 'expected_from_date' =>
'2016-03-24T00:00:00-0700',
295 'expected_to_date' =>
'2016-03-25T00:00:00-0700',
298 'yymmdd to yyyy-mm-dd' => [
300 'from_date' =>
'20160324',
301 'to_date' =>
'20160325',
302 'expected_from_date' =>
'2016-03-24T00:00:00-0700',
303 'expected_to_date' =>
'2016-03-25T00:00:00-0700',