Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PostcodeTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Directory\Helper\Data as DirectoryHelper;
11 
13 {
17  protected $directoryHelper;
18 
19  protected function setUp()
20  {
21  parent::setUp();
22 
23  $this->directoryHelper = $this->getMockBuilder(\Magento\Directory\Helper\Data::class)
24  ->disableOriginalConstructor()
25  ->getMock();
26  }
27 
34  protected function getClass($value)
35  {
36  return new \Magento\Customer\Model\Metadata\Form\Postcode(
37  $this->localeMock,
38  $this->loggerMock,
39  $this->attributeMetadataMock,
40  $this->localeResolverMock,
41  $value,
42  0,
43  false,
44  $this->directoryHelper
45  );
46  }
47 
56  public function testValidateValue($value, $expected, $countryId, $isOptional)
57  {
58  $storeLabel = 'Zip/Postal Code';
59  $this->attributeMetadataMock->expects($this->once())
60  ->method('getStoreLabel')
61  ->willReturn($storeLabel);
62 
63  $this->directoryHelper->expects($this->once())
64  ->method('isZipCodeOptional')
65  ->willReturnMap([
66  [$countryId, $isOptional],
67  ]);
68 
69  $object = $this->getClass($value);
70  $object->setExtractedData(['country_id' => $countryId]);
71 
72  $actual = $object->validateValue($value);
73  $this->assertEquals($expected, $actual);
74  }
75 
79  public function validateValueDataProvider()
80  {
81  return [
82  ['', ['"Zip/Postal Code" is a required value.'], 'US', false],
83  ['90034', true, 'US', false],
84  ['', true, 'IE', true],
85  ['90034', true, 'IE', true],
86  ];
87  }
88 }
$value
Definition: gender.phtml:16
testValidateValue($value, $expected, $countryId, $isOptional)