PriceBackendTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Test\Unit\Model\Plugin;
  7. use \Magento\Bundle\Model\Plugin\PriceBackend;
  8. use Magento\Bundle\Model\Product\Price;
  9. use Magento\Catalog\Model\Product\Type;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  11. class PriceBackendTest extends \PHPUnit\Framework\TestCase
  12. {
  13. const CLOSURE_VALUE = 'CLOSURE';
  14. /** @var PriceBackend */
  15. private $priceBackendPlugin;
  16. /** @var \PHPUnit_Framework_MockObject_MockObject */
  17. private $priceAttributeMock;
  18. /** @var \Closure */
  19. private $closure;
  20. /** @var \PHPUnit_Framework_MockObject_MockObject */
  21. private $productMock;
  22. protected function setUp()
  23. {
  24. $objectManager = new ObjectManager($this);
  25. $this->priceBackendPlugin = $objectManager->getObject(\Magento\Bundle\Model\Plugin\PriceBackend::class);
  26. $this->closure = function () {
  27. return static::CLOSURE_VALUE;
  28. };
  29. $this->priceAttributeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Attribute\Backend\Price::class)
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
  33. ->disableOriginalConstructor()
  34. ->setMethods(['getTypeId', 'getPriceType', '__wakeUp'])
  35. ->getMock();
  36. }
  37. /**
  38. * @dataProvider aroundValidateDataProvider
  39. *
  40. * @param $typeId
  41. * @param $priceType
  42. * @param $expectedResult
  43. */
  44. public function testAroundValidate($typeId, $priceType, $expectedResult)
  45. {
  46. $this->productMock->expects($this->any())->method('getTypeId')->will($this->returnValue($typeId));
  47. $this->productMock->expects($this->any())->method('getPriceType')->will($this->returnValue($priceType));
  48. $result = $this->priceBackendPlugin->aroundValidate(
  49. $this->priceAttributeMock,
  50. $this->closure,
  51. $this->productMock
  52. );
  53. $this->assertEquals($expectedResult, $result);
  54. }
  55. /**
  56. * Data provider for testAroundValidate
  57. *
  58. * @return array
  59. */
  60. public function aroundValidateDataProvider()
  61. {
  62. return [
  63. ['type' => Type::TYPE_SIMPLE, 'priceType' => Price::PRICE_TYPE_FIXED, 'result' => static::CLOSURE_VALUE],
  64. ['type' => Type::TYPE_SIMPLE, 'priceType' => Price::PRICE_TYPE_DYNAMIC, 'result' => static::CLOSURE_VALUE],
  65. ['type' => Type::TYPE_BUNDLE, 'priceType' => Price::PRICE_TYPE_FIXED, 'result' => static::CLOSURE_VALUE],
  66. ['type' => Type::TYPE_BUNDLE, 'priceType' => Price::PRICE_TYPE_DYNAMIC, 'result' => true],
  67. ['type' => Type::TYPE_VIRTUAL, 'priceType' => Price::PRICE_TYPE_FIXED, 'result' => static::CLOSURE_VALUE],
  68. ['type' => Type::TYPE_VIRTUAL, 'priceType' => Price::PRICE_TYPE_DYNAMIC, 'result' => static::CLOSURE_VALUE],
  69. ];
  70. }
  71. }