Permalink
Browse files

Added testFormatNumberWithExtension test

  • Loading branch information...
1 parent 1a0e2e5 commit 00f53cd4bff1b10eaa11b565263c76b24d8f48dc @davideme committed May 5, 2012
Showing with 17 additions and 6 deletions.
  1. +4 −6 PhoneMetadata.php
  2. +13 −0 Tests/PhoneNumberUtilTest.php
View
@@ -673,12 +673,10 @@ public function fromArray(array $input) {
if (isset($input['nationalPrefix'])) {
$this->setNationalPrefix($input['nationalPrefix']);
}
- /*
- hasString = objectInput.readBoolean();
- if (hasString) {
- setPreferredExtnPrefix(objectInput.readUTF());
- }
- */
+
+ if (isset($input['preferredExtnPrefix'])) {
+ $this->setPreferredExtnPrefix($input['preferredExtnPrefix']);
+ }
if (isset($input['nationalPrefixForParsing'])) {
$this->setNationalPrefixForParsing($input['nationalPrefixForParsing']);
@@ -745,6 +745,19 @@ public function testFormatE164Number() {
$this->assertEquals("+80012345678", $this->phoneUtil->format(self::$internationalTollFree, PhoneNumberFormat::E164));
}
+ public function testFormatNumberWithExtension() {
+ $nzNumber = new PhoneNumber();
+ $nzNumber->mergeFrom(self::$nzNumber)->setExtension("1234");
+ // Uses default extension prefix:
+ $this->assertEquals("03-331 6005 ext. 1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::NATIONAL));
+ // Uses RFC 3966 syntax.
+ $this->assertEquals("+64-3-331-6005;ext=1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::RFC3966));
+ // Extension prefix overridden in the territory information for the US:
+ $usNumberWithExtension = new PhoneNumber();
+ $usNumberWithExtension->mergeFrom(self::$usNumber)->setExtension("4567");
+ $this->assertEquals("650 253 0000 extn. 4567", $this->phoneUtil->format($usNumberWithExtension, PhoneNumberFormat::NATIONAL));
+ }
+
/**
*
*/

0 comments on commit 00f53cd

Please sign in to comment.