ChildrenValidationLocatorTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\SalesRule\Test\Unit\Model\Quote;
  8. use Magento\SalesRule\Model\Quote\ChildrenValidationLocator;
  9. use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  11. use Magento\Catalog\Model\Product;
  12. /**
  13. * Test for Magento\SalesRule\Model\Quote\ChildrenValidationLocator
  14. */
  15. class ChildrenValidationLocatorTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var array
  19. */
  20. private $productTypeChildrenValidationMap;
  21. /**
  22. * @var ObjectManager
  23. */
  24. private $objectManager;
  25. /**
  26. * @var ChildrenValidationLocator
  27. */
  28. private $model;
  29. /**
  30. * @var QuoteItem|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $quoteItemMock;
  33. /**
  34. * @var Product|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. private $productMock;
  37. protected function setUp()
  38. {
  39. $this->objectManager = new ObjectManager($this);
  40. $this->productTypeChildrenValidationMap = [
  41. 'type1' => true,
  42. 'type2' => false,
  43. ];
  44. $this->quoteItemMock = $this->getMockBuilder(QuoteItem::class)
  45. ->disableOriginalConstructor()
  46. ->setMethods(['getProduct'])
  47. ->getMockForAbstractClass();
  48. $this->productMock = $this->getMockBuilder(Product::class)
  49. ->disableOriginalConstructor()
  50. ->setMethods(['getTypeId'])
  51. ->getMock();
  52. $this->model = $this->objectManager->getObject(
  53. ChildrenValidationLocator::class,
  54. [
  55. 'productTypeChildrenValidationMap' => $this->productTypeChildrenValidationMap,
  56. ]
  57. );
  58. }
  59. /**
  60. * @dataProvider productTypeDataProvider
  61. * @param string $type
  62. * @param bool $expected
  63. *
  64. * @return void
  65. */
  66. public function testIsChildrenValidationRequired(string $type, bool $expected): void
  67. {
  68. $this->quoteItemMock->expects($this->once())
  69. ->method('getProduct')
  70. ->willReturn($this->productMock);
  71. $this->productMock->expects($this->once())
  72. ->method('getTypeId')
  73. ->willReturn($type);
  74. $this->assertEquals($this->model->isChildrenValidationRequired($this->quoteItemMock), $expected);
  75. }
  76. /**
  77. * @return array
  78. */
  79. public function productTypeDataProvider(): array
  80. {
  81. return [
  82. ['type1', true],
  83. ['type2', false],
  84. ['type3', true],
  85. ];
  86. }
  87. }