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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogRule\Test\Unit\Helper;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
class DataTest extends \PHPUnit\Framework\TestCase
{
/**
* Helper object
*
* @var \Magento\CatalogRule\Helper\Data
*/
protected $helper;
protected function setUp()
{
$this->helper = (new ObjectManager($this))->getObject(\Magento\CatalogRule\Helper\Data::class);
}
/**
* Test price rule calculation
*
* @param string $actionOperator
* @param int|float $ruleAmount
* @param int|float $price
* @param int|float $expectedAmount
*
* @dataProvider calcPriceRuleDataProvider
*/
public function testCalcPriceRule($actionOperator, $ruleAmount, $price, $expectedAmount)
{
$this->assertEquals($expectedAmount, $this->helper->calcPriceRule($actionOperator, $ruleAmount, $price));
}
/**
* Data provider for cal price rule test
*
* @return array
*/
public function calcPriceRuleDataProvider()
{
return [
['to_fixed', 10, 10, 10],
['to_fixed', 0, 10, 0],
['to_fixed', 10, 0, 0],
['to_fixed', 0, 0, 0],
['to_percent', 100, 100, 100],
['to_percent', 10, 100, 10],
['to_percent', 10, 70, 7],
['to_percent', 100, 10, 10],
['by_fixed', 100, 100, 0],
['by_fixed', 10, 100, 90],
['by_fixed', 100, 10, 0],
['by_percent', 100, 100, 0],
['by_percent', 100, 10, 0],
['by_percent', 100, 1, 0],
['by_percent', 10, 100, 90],
['by_percent', 10, 10, 9],
['by_percent', 1, 10, 9.90],
];
}
}