/**
  * @covers ::match
  * @covers ::matchRule
  * @covers ::buildList
  */
 public function testMatch()
 {
     // Test empty rules.
     $this->assertEquals(true, PostalCodeHelper::match('123', null, null));
     // Test regular expressions.
     $includeRule = '/(20)[0-9]{1}/';
     $excludeRule = '/(20)[0-2]{1}/';
     $this->assertEquals(true, PostalCodeHelper::match('203', $includeRule, $excludeRule));
     $this->assertEquals(false, PostalCodeHelper::match('202', $includeRule, $excludeRule));
     // Test lists
     $includeRule = '10, 20, 30:40';
     $excludeRule = '35';
     $this->assertEquals(true, PostalCodeHelper::match('34', $includeRule, $excludeRule));
     $this->assertEquals(false, PostalCodeHelper::match('35', $includeRule, $excludeRule));
 }
 /**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     if ($address->getCountryCode() != $this->configuration['country_code']) {
         return FALSE;
     }
     $administrative_area = $this->configuration['administrative_area'];
     $locality = $this->configuration['locality'];
     $dependent_locality = $this->configuration['dependent_locality'];
     if ($administrative_area && $administrative_area != $address->getAdministrativeArea()) {
         return FALSE;
     }
     if ($locality && $locality != $address->getLocality()) {
         return FALSE;
     }
     if ($dependent_locality && $dependent_locality != $address->getDependentLocality()) {
         return FALSE;
     }
     $included_postal_codes = $this->configuration['included_postal_codes'];
     $excluded_postal_codes = $this->configuration['excluded_postal_codes'];
     if (!PostalCodeHelper::match($address->getPostalCode(), $included_postal_codes, $excluded_postal_codes)) {
         return FALSE;
     }
     return TRUE;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     if ($address->getCountryCode() != $this->countryCode) {
         return false;
     }
     if ($this->administrativeArea && $this->administrativeArea != $address->getAdministrativeArea()) {
         return false;
     }
     if ($this->locality && $this->locality != $address->getLocality()) {
         return false;
     }
     if ($this->dependentLocality && $this->dependentLocality != $address->getDependentLocality()) {
         return false;
     }
     if (!PostalCodeHelper::match($address->getPostalCode(), $this->includedPostalCodes, $this->excludedPostalCodes)) {
         return false;
     }
     return true;
 }