1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Pricing\Test\Unit\Adjustment;
use \Magento\Framework\Pricing\Adjustment\Pool;
class PoolTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\Pricing\Adjustment\Pool
*/
public $model;
protected function setUp()
{
$adjustmentsData = [
'adj1' => ['className' => 'adj1_class', 'sortOrder' => 10],
'adj2' => ['className' => 'adj2_class', 'sortOrder' => 20],
'adj3' => ['className' => 'adj3_class', 'sortOrder' => 5],
'adj4' => ['className' => 'adj4_class', 'sortOrder' => null],
'adj5' => ['className' => 'adj5_class'],
];
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $adjustmentFactory */
$adjustmentFactory = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\Factory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$adjustmentFactory->expects($this->any())->method('create')->will(
$this->returnCallback(
function ($className, $data) {
return $className . '|' . $data['sortOrder'];
}
)
);
$this->model = new Pool($adjustmentFactory, $adjustmentsData);
}
public function testGetAdjustments()
{
$expectedResult = [
'adj1' => 'adj1_class|10',
'adj2' => 'adj2_class|20',
'adj3' => 'adj3_class|5',
'adj4' => 'adj4_class|' . \Magento\Framework\Pricing\Adjustment\Pool::DEFAULT_SORT_ORDER,
'adj5' => 'adj5_class|' . \Magento\Framework\Pricing\Adjustment\Pool::DEFAULT_SORT_ORDER,
];
$result = $this->model->getAdjustments();
$this->assertEquals($expectedResult, $result);
}
/**
* @dataProvider getAdjustmentByCodeDataProvider
*/
public function testGetAdjustmentByCode($code, $expectedResult)
{
$result = $this->model->getAdjustmentByCode($code);
$this->assertEquals($expectedResult, $result);
}
/**
* @return array
*/
public function getAdjustmentByCodeDataProvider()
{
return [
['adj1', 'adj1_class|10'],
['adj2', 'adj2_class|20'],
['adj3', 'adj3_class|5'],
['adj4', 'adj4_class|' . \Magento\Framework\Pricing\Adjustment\Pool::DEFAULT_SORT_ORDER],
['adj5', 'adj5_class|' . \Magento\Framework\Pricing\Adjustment\Pool::DEFAULT_SORT_ORDER],
];
}
/**
* @expectedException \InvalidArgumentException
*/
public function testGetAdjustmentByNotExistingCode()
{
$this->model->getAdjustmentByCode('not_existing_code');
}
}