DataTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogRule\Test\Unit\Helper;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. class DataTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Helper object
  12. *
  13. * @var \Magento\CatalogRule\Helper\Data
  14. */
  15. protected $helper;
  16. protected function setUp()
  17. {
  18. $this->helper = (new ObjectManager($this))->getObject(\Magento\CatalogRule\Helper\Data::class);
  19. }
  20. /**
  21. * Test price rule calculation
  22. *
  23. * @param string $actionOperator
  24. * @param int|float $ruleAmount
  25. * @param int|float $price
  26. * @param int|float $expectedAmount
  27. *
  28. * @dataProvider calcPriceRuleDataProvider
  29. */
  30. public function testCalcPriceRule($actionOperator, $ruleAmount, $price, $expectedAmount)
  31. {
  32. $this->assertEquals($expectedAmount, $this->helper->calcPriceRule($actionOperator, $ruleAmount, $price));
  33. }
  34. /**
  35. * Data provider for cal price rule test
  36. *
  37. * @return array
  38. */
  39. public function calcPriceRuleDataProvider()
  40. {
  41. return [
  42. ['to_fixed', 10, 10, 10],
  43. ['to_fixed', 0, 10, 0],
  44. ['to_fixed', 10, 0, 0],
  45. ['to_fixed', 0, 0, 0],
  46. ['to_percent', 100, 100, 100],
  47. ['to_percent', 10, 100, 10],
  48. ['to_percent', 10, 70, 7],
  49. ['to_percent', 100, 10, 10],
  50. ['by_fixed', 100, 100, 0],
  51. ['by_fixed', 10, 100, 90],
  52. ['by_fixed', 100, 10, 0],
  53. ['by_percent', 100, 100, 0],
  54. ['by_percent', 100, 10, 0],
  55. ['by_percent', 100, 1, 0],
  56. ['by_percent', 10, 100, 90],
  57. ['by_percent', 10, 10, 9],
  58. ['by_percent', 1, 10, 9.90],
  59. ];
  60. }
  61. }