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 
12 class PostcodeTest extends \PHPUnit\Framework\TestCase
13 {
18 
22  protected $attributeMock;
23 
27  private $localeMock;
28 
32  private $localeResolverMock;
33 
37  private $loggerMock;
38 
39  protected function setUp()
40  {
41  $this->localeMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
42  ->getMock();
43  $this->localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class)
44  ->getMock();
45  $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
46  ->getMock();
47  $this->directoryHelperMock = $this->getMockBuilder(\Magento\Directory\Helper\Data::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50  $this->attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
51  ->disableOriginalConstructor()
52  ->setMethods(['getStoreLabel'])
53  ->getMock();
54  }
55 
64  public function testValidateValue($value, $expected, $countryId, $isOptional)
65  {
66  $storeLabel = 'Zip/Postal Code';
67  $this->attributeMock->expects($this->any())
68  ->method('getStoreLabel')
69  ->willReturn($storeLabel);
70 
71  $this->directoryHelperMock->expects($this->once())
72  ->method('isZipCodeOptional')
73  ->willReturnMap([
74  [$countryId, $isOptional],
75  ]);
76 
77  $object = new \Magento\Customer\Model\Attribute\Data\Postcode(
78  $this->localeMock,
79  $this->loggerMock,
80  $this->localeResolverMock,
81  $this->directoryHelperMock
82  );
83  $object->setAttribute($this->attributeMock);
84  $object->setExtractedData(['country_id' => $countryId]);
85 
86  $actual = $object->validateValue($value);
87  $this->assertEquals($expected, $actual);
88  }
89 
93  public function validateValueDataProvider()
94  {
95  return [
96  ['', ['"Zip/Postal Code" is a required value.'], 'US', false],
97  ['90034', true, 'US', false],
98  ['', true, 'IE', true],
99  ['90034', true, 'IE', true],
100  ];
101  }
102 }
$value
Definition: gender.phtml:16
testValidateValue($value, $expected, $countryId, $isOptional)