Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueProviderTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ValueProviderTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $storeMock;
24 
29 
34 
38  protected $dataObjectMock;
39 
43  protected $ruleFactoryMock;
44 
45  protected function setUp()
46  {
47  $this->searchCriteriaBuilderMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaBuilder::class);
48  $this->storeMock = $this->createMock(\Magento\Store\Model\System\Store::class);
49  $this->groupRepositoryMock = $this->createMock(\Magento\Customer\Api\GroupRepositoryInterface::class);
50  $this->dataObjectMock = $this->createMock(\Magento\Framework\Convert\DataObject::class);
51  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class);
52  $groupSearchResultsMock = $this->createMock(\Magento\Customer\Api\Data\GroupSearchResultsInterface::class);
53  $groupsMock = $this->createMock(\Magento\Customer\Api\Data\GroupInterface::class);
54 
55  $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
56  $this->groupRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)
57  ->willReturn($groupSearchResultsMock);
58  $groupSearchResultsMock->expects($this->once())->method('getItems')->willReturn([$groupsMock]);
59  $this->storeMock->expects($this->once())->method('getWebsiteValuesForForm')->willReturn([]);
60  $this->dataObjectMock->expects($this->once())->method('toOptionArray')->with([$groupsMock], 'id', 'code')
61  ->willReturn([]);
62  $this->ruleFactoryMock = $this->createPartialMock(\Magento\SalesRule\Model\RuleFactory::class, ['create']);
63  $this->model = (new ObjectManager($this))->getObject(
64  \Magento\SalesRule\Model\Rule\Metadata\ValueProvider::class,
65  [
66  'store' => $this->storeMock,
67  'groupRepository' => $this->groupRepositoryMock,
68  'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock,
69  'objectConverter' => $this->dataObjectMock,
70  'salesRuleFactory' => $this->ruleFactoryMock,
71  ]
72  );
73  }
74 
75  public function testGetMetadataValues()
76  {
77  $expectedData = include __DIR__ . '/_files/MetaData.php';
78 
80  $ruleMock = $this->createMock(\Magento\SalesRule\Model\Rule::class);
81  $this->ruleFactoryMock->expects($this->once())
82  ->method('create')
83  ->willReturn($ruleMock);
84  $ruleMock->expects($this->once())
85  ->method('getCouponTypes')
86  ->willReturn(
87  [
88  'key1' => 'couponType1',
89  'key2' => 'couponType2',
90  ]
91  );
92  $ruleMock->expects($this->once())
93  ->method('getStoreLabels')
94  ->willReturn(
95  [
96  'label0'
97  ]
98  );
99  $test = $this->model->getMetadataValues($ruleMock);
100  $this->assertEquals($expectedData, $test);
101  }
102 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60