public function testCountryCallingCodeIsNotIgnored() { // +46 is the country calling code for Sweden (SE), and 40404 is a valid short number in the US. $this->assertFalse($this->shortInfo->isPossibleShortNumberForRegion($this->parse('+4640404', RegionCode::SE), RegionCode::US)); $this->assertFalse($this->shortInfo->isValidShortNumberForRegion($this->parse('+4640404', RegionCode::SE), RegionCode::US)); $this->assertEquals(ShortNumberCost::UNKNOWN_COST, $this->shortInfo->getExpectedCostForRegion($this->parse('+4640404', RegionCode::SE), RegionCode::US)); }
public function testOverlappingNANPANumber() { // 211 is an emergency number in Barbados, while it is a toll-free information line in Canada // and the USA. $this->assertTrue($this->shortInfo->isEmergencyNumber("211", RegionCode::BB)); $this->assertEquals(ShortNumberCost::TOLL_FREE, $this->shortInfo->getExpectedCostForRegion("211", RegionCode::BB)); $this->assertFalse($this->shortInfo->isEmergencyNumber("211", RegionCode::US)); $this->assertEquals(ShortNumberCost::UNKNOWN_COST, $this->shortInfo->getExpectedCostForRegion("211", RegionCode::US)); $this->assertFalse($this->shortInfo->isEmergencyNumber("211", RegionCode::CA)); $this->assertEquals(ShortNumberCost::UNKNOWN_COST, $this->shortInfo->getExpectedCostForRegion("211", RegionCode::CA)); }
/** * @dataProvider shortNumberRegionList */ public function testCarrierSpecificShortNumbers($regionCode) { // Test the carrier-specific tag. $desc = $this->shortNumberInfo->getMetadataForRegion($regionCode)->getCarrierSpecific(); if ($desc->hasExampleNumber()) { $exampleNumber = $desc->getExampleNumber(); $carrierSpecificNumber = $this->phoneNumberUtil->parse($exampleNumber, $regionCode); if (!$this->shortNumberInfo->isPossibleShortNumberForRegion($carrierSpecificNumber, $regionCode) || !$this->shortNumberInfo->isCarrierSpecific($carrierSpecificNumber)) { $this->fail("Carrier-specific test failed for " . $regionCode); } } }
public function __construct($number, array $config = NULL) { $this->number = $number; $this->config = Kohana::$config->load('phonenumber')->as_array(); if (!empty($config)) { $this->config = Arr::merge($this->config, $config); } if (!isset($this->config['country'])) { $this->config['country'] = ''; } if (empty($this->config['country'])) { throw new Kohana_Exception('Country code is required'); } $this->config['country'] = strtoupper($this->config['country']); if (!isset($this->config['language'])) { $this->config['language'] = ''; } if (!isset($this->config['region'])) { $this->config['region'] = ''; } $this->config['language'] = empty($this->config['language']) ? 'en' : strtolower($this->config['language']); $this->config['region'] = empty($this->config['region']) ? NULL : strtoupper($this->config['region']); $this->phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); $this->shortNumberInfo = \libphonenumber\ShortNumberInfo::getInstance(); $this->phoneNumberGeocoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance(); if (!empty($number)) { try { $this->phoneNumber = $this->phoneNumberUtil->parse($number, $this->config['country'], NULL, TRUE); $this->possibleNumber = $this->phoneNumberUtil->isPossibleNumber($this->phoneNumber); $this->isPossibleNumberWithReason = $this->phoneNumberUtil->isPossibleNumberWithReason($this->phoneNumber); $this->validNumber = $this->phoneNumberUtil->isValidNumber($this->phoneNumber); $this->validNumberForRegion = $this->phoneNumberUtil->isValidNumberForRegion($this->phoneNumber, $input['country']); $this->phoneNumberRegion = $this->phoneNumberUtil->getRegionCodeForNumber($this->phoneNumber); $this->phoneNumberType = $this->phoneNumberUtil->getNumberType($this->phoneNumber); $this->geolocation = $this->phoneNumberGeocoder->getDescriptionForNumber($this->phoneNumber, $this->config['language'], $this->config['region']); $this->phoneNumberToCarrierInfo = \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForNumber($this->phoneNumber, $this->config['language']); $this->timezone = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance()->getTimeZonesForNumber($this->phoneNumber); } catch (\libphonenumber\NumberParseException $e) { throw new Kohana_Exception(':error', array(':error' => $e->getMessage()), $e->getCode()); } } }
public function testIssue64WithoutPhoneNumberUtilresetInstance() { PhoneNumberUtil::resetInstance(); $sortNumberUtil = ShortNumberInfo::getInstance(); $this->assertTrue($sortNumberUtil->isEmergencyNumber('999', 'GB')); }
public function testShortNumberInfoIsPossibleShortNumberForRegionWithRegionMissingFromCodeSet() { $exampleNumber = $this->getExampleNumber('NE'); $shortNumberInfo = ShortNumberInfo::getInstance(); $this->assertFalse($shortNumberInfo->isPossibleShortNumberForRegion($exampleNumber, 'NE')); }