forked from jens-maus/carddav2fb
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use libphonenumber to properly format phone numbers
- Loading branch information
Showing
5 changed files
with
56 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,7 @@ private function defaultConfig(): array | |
'CELL' => 'mobile', | ||
'FAX' => 'fax_work' | ||
], | ||
'phoneReplaceCharacters' => [ | ||
'+49' => '', | ||
'(' => '', | ||
')' => '', | ||
'/' => '', | ||
'@' => '', | ||
'-' => '' | ||
], | ||
'defaultCountry' => 'DE', | ||
'realName' => [], | ||
], | ||
]; | ||
|
@@ -211,24 +204,43 @@ public function testPhoneWithoutType() | |
$this->assertEquals('other', (string)$numberType['type']); | ||
} | ||
|
||
public function testPhonenumberConversionType() | ||
public function testSipNumbersDoNotGetChanged() | ||
{ | ||
unset($this->contact->TEL); | ||
$this->contact->add('TEL', '[email protected]', ['type' => 'work']); | ||
$this->contact->add('TEL', '(0511)12345/678-890', ['type' => 'home']); | ||
$this->checkConversionResult('[email protected]', '[email protected]'); | ||
} | ||
|
||
$res = $this->converter->convert($this->contact); | ||
$this->assertCount(1, $res); | ||
public function testNationalNumbersGetNoCountryCode() | ||
{ | ||
$this->checkConversionResult('+49(0511)12345/678-890', '0511 12345678890'); | ||
} | ||
|
||
$contact = $res[0]; | ||
$this->assertCount(2, $contact->telephony->children()); | ||
public function testInternationalNumbersGetCountryCode() | ||
{ | ||
$this->checkConversionResult('+1234567890', '00 1 234567890'); | ||
} | ||
|
||
public function testGarbageNumbersAreNotChanged() | ||
{ | ||
$this->checkConversionResult('garbage', 'garbage'); | ||
} | ||
|
||
public function testInteralNumbersAreNotChanged() | ||
{ | ||
$this->checkConversionResult('**123', '**123'); | ||
} | ||
|
||
private function checkConversionResult($number, $expectedResult) | ||
{ | ||
unset($this->contact->TEL); | ||
$this->contact->add('TEL', $number, ['type' => 'other']); | ||
|
||
$result = $this->converter->convert($this->contact); | ||
$this->assertCount(1, $result); | ||
|
||
// no number conversion | ||
$number = $contact->telephony->children()[0]; | ||
$this->assertEquals('[email protected]', (string)$number); | ||
$resultingContact = $result[0]; | ||
$this->assertCount(1, $resultingContact->telephony->children()); | ||
|
||
// number conversion | ||
$number = $contact->telephony->children()[1]; | ||
$this->assertEquals('051112345678890', (string)$number); | ||
$convertedNumber = (string)$resultingContact->telephony->children()[0]; | ||
$this->assertEquals($expectedResult, $convertedNumber); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters