RuleTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogRule\Model;
  7. class RuleTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\CatalogRule\Model\Rule
  11. */
  12. protected $_object;
  13. /**
  14. * Sets up the fixture, for example, opens a network connection.
  15. * This method is called before a test is executed.
  16. */
  17. protected function setUp()
  18. {
  19. $resourceMock = $this->createPartialMock(
  20. \Magento\CatalogRule\Model\ResourceModel\Rule::class,
  21. ['getIdFieldName', 'getRulesFromProduct']
  22. );
  23. $resourceMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id'));
  24. $resourceMock->expects(
  25. $this->any()
  26. )->method(
  27. 'getRulesFromProduct'
  28. )->will(
  29. $this->returnValue($this->_getCatalogRulesFixtures())
  30. );
  31. $this->_object = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  32. \Magento\CatalogRule\Model\Rule::class,
  33. ['ruleResourceModel' => $resourceMock]
  34. );
  35. }
  36. /**
  37. * @magentoAppIsolation enabled
  38. * @covers \Magento\CatalogRule\Model\Rule::calcProductPriceRule
  39. */
  40. public function testCalcProductPriceRule()
  41. {
  42. $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  43. \Magento\Catalog\Model\Product::class
  44. );
  45. $this->assertEquals($this->_object->calcProductPriceRule($product, 100), 45);
  46. $product->setParentId(true);
  47. $this->assertEquals($this->_object->calcProductPriceRule($product, 50), 50);
  48. }
  49. /**
  50. * Get array with catalog rule data
  51. *
  52. * @return array
  53. */
  54. protected function _getCatalogRulesFixtures()
  55. {
  56. return [
  57. [
  58. 'action_operator' => 'by_percent',
  59. 'action_amount' => '50.0000',
  60. 'action_stop' => '0'
  61. ],
  62. [
  63. 'action_operator' => 'by_percent',
  64. 'action_amount' => '10.0000',
  65. 'action_stop' => '0'
  66. ]
  67. ];
  68. }
  69. }