Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CountryValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CountryValidatorTest extends \PHPUnit\Framework\TestCase
9 {
11  protected $model;
12 
16  protected $configMock;
17 
21  protected $resultFactoryMock;
22 
26  protected $resultMock;
27 
28  protected function setUp()
29  {
30  $this->configMock = $this->getMockBuilder(\Magento\Payment\Gateway\ConfigInterface::class)
31  ->getMockForAbstractClass();
32  $this->resultFactoryMock = $this->getMockBuilder(
33  \Magento\Payment\Gateway\Validator\ResultInterfaceFactory::class
34  )->setMethods(['create'])
35  ->disableOriginalConstructor()
36  ->getMock();
37  $this->resultMock = $this->getMockBuilder(\Magento\Payment\Gateway\Validator\Result::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->model = new \Magento\Payment\Gateway\Validator\CountryValidator(
42  $this->resultFactoryMock,
43  $this->configMock
44  );
45  }
46 
50  public function testValidateAllowspecificTrue($storeId, $country, $allowspecific, $specificcountry, $isValid)
51  {
52  $validationSubject = ['storeId' => $storeId, 'country' => $country];
53 
54  $this->configMock->expects($this->at(0))
55  ->method('getValue')
56  ->with('allowspecific', $storeId)
57  ->willReturn($allowspecific);
58  $this->configMock->expects($this->at(1))
59  ->method('getValue')
60  ->with('specificcountry', $storeId)
61  ->willReturn($specificcountry);
62 
63  $this->resultFactoryMock->expects($this->once())
64  ->method('create')
65  ->with(['isValid' => $isValid, 'failsDescription' => [], 'errorCodes' => []])
66  ->willReturn($this->resultMock);
67 
68  $this->assertSame($this->resultMock, $this->model->validate($validationSubject));
69  }
70 
75  {
76  return [
77  [1, 'US', 1, 'US,UK,CA', true], //$storeId, $country, $allowspecific, $specificcountry, $isValid
78  [1, 'BJ', 1, 'US,UK,CA', false]
79  ];
80  }
81 
85  public function testValidateAllowspecificFalse($storeId, $allowspecific, $isValid)
86  {
87  $validationSubject = ['storeId' => $storeId];
88 
89  $this->configMock->expects($this->at(0))
90  ->method('getValue')
91  ->with('allowspecific', $storeId)
92  ->willReturn($allowspecific);
93 
94  $this->resultFactoryMock->expects($this->once())
95  ->method('create')
96  ->with(['isValid' => $isValid, 'failsDescription' => [], 'errorCodes' => []])
97  ->willReturn($this->resultMock);
98 
99  $this->assertSame($this->resultMock, $this->model->validate($validationSubject));
100  }
101 
106  {
107  return [
108  [1, 0, true] //$storeId, $allowspecific, $isValid
109  ];
110  }
111 }
testValidateAllowspecificTrue($storeId, $country, $allowspecific, $specificcountry, $isValid)