ValueProviderTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Test\Unit\Model\Rule\Metadata;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. /**
  9. * @covers Magento\SalesRule\Model\Rule\Metadata\ValueProvider
  10. */
  11. class ValueProviderTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\SalesRule\Model\Rule\Metadata\ValueProvider
  15. */
  16. protected $model;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $storeMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $groupRepositoryMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $searchCriteriaBuilderMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $dataObjectMock;
  33. /**
  34. * @var \Magento\SalesRule\Model\RuleFactory|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $ruleFactoryMock;
  37. protected function setUp()
  38. {
  39. $this->searchCriteriaBuilderMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaBuilder::class);
  40. $this->storeMock = $this->createMock(\Magento\Store\Model\System\Store::class);
  41. $this->groupRepositoryMock = $this->createMock(\Magento\Customer\Api\GroupRepositoryInterface::class);
  42. $this->dataObjectMock = $this->createMock(\Magento\Framework\Convert\DataObject::class);
  43. $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class);
  44. $groupSearchResultsMock = $this->createMock(\Magento\Customer\Api\Data\GroupSearchResultsInterface::class);
  45. $groupsMock = $this->createMock(\Magento\Customer\Api\Data\GroupInterface::class);
  46. $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
  47. $this->groupRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)
  48. ->willReturn($groupSearchResultsMock);
  49. $groupSearchResultsMock->expects($this->once())->method('getItems')->willReturn([$groupsMock]);
  50. $this->storeMock->expects($this->once())->method('getWebsiteValuesForForm')->willReturn([]);
  51. $this->dataObjectMock->expects($this->once())->method('toOptionArray')->with([$groupsMock], 'id', 'code')
  52. ->willReturn([]);
  53. $this->ruleFactoryMock = $this->createPartialMock(\Magento\SalesRule\Model\RuleFactory::class, ['create']);
  54. $this->model = (new ObjectManager($this))->getObject(
  55. \Magento\SalesRule\Model\Rule\Metadata\ValueProvider::class,
  56. [
  57. 'store' => $this->storeMock,
  58. 'groupRepository' => $this->groupRepositoryMock,
  59. 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock,
  60. 'objectConverter' => $this->dataObjectMock,
  61. 'salesRuleFactory' => $this->ruleFactoryMock,
  62. ]
  63. );
  64. }
  65. public function testGetMetadataValues()
  66. {
  67. $expectedData = include __DIR__ . '/_files/MetaData.php';
  68. /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleMock */
  69. $ruleMock = $this->createMock(\Magento\SalesRule\Model\Rule::class);
  70. $this->ruleFactoryMock->expects($this->once())
  71. ->method('create')
  72. ->willReturn($ruleMock);
  73. $ruleMock->expects($this->once())
  74. ->method('getCouponTypes')
  75. ->willReturn(
  76. [
  77. 'key1' => 'couponType1',
  78. 'key2' => 'couponType2',
  79. ]
  80. );
  81. $ruleMock->expects($this->once())
  82. ->method('getStoreLabels')
  83. ->willReturn(
  84. [
  85. 'label0'
  86. ]
  87. );
  88. $test = $this->model->getMetadataValues($ruleMock);
  89. $this->assertEquals($expectedData, $test);
  90. }
  91. }