-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the "name"-part of a MailAddress gets quoted multiple times
refs #18
- Loading branch information
1 parent
ec170f3
commit d8a0989
Showing
2 changed files
with
57 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,59 @@ public function testToString() | |
public function testFromString() | ||
{ | ||
|
||
/** | ||
* @see conjoon/php-lib-conjoon#12 | ||
*/ | ||
$tests = [ | ||
[ | ||
["Peter, Parker", "[email protected]"], | ||
["\"Peter, Parker\"", "[email protected]"] | ||
], | ||
[ | ||
["Parker Peter", "[email protected]"], | ||
["Parker Peter", "[email protected]"], | ||
], | ||
[ | ||
["Parker \" Peter", "[email protected]"], | ||
["\"Parker \\\" Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Parker ' Peter", "[email protected]"], | ||
["\"Parker \' Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Parker \"Parker, Peter Peter", "[email protected]"], | ||
["\"Parker \\\"Parker, Peter Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Schäfer, Peter", "[email protected]"], | ||
["\"Schäfer, Peter\"", "[email protected]"] | ||
], | ||
[ | ||
['"Schäfer, Peter"', "[email protected]"], | ||
['"\"Schäfer, Peter\""', "[email protected]"] | ||
], | ||
[ | ||
['"Schä"fer, Pe"ter"', "[email protected]"], | ||
['"\"Schä\"fer, Pe\"ter\""', "[email protected]"] | ||
] | ||
|
||
]; | ||
|
||
foreach ($tests as $test) { | ||
[$input, $output] = $test; | ||
|
||
$mailAddress = new MailAddress($input[1], $input[0]); | ||
|
||
$jsonString = json_encode($mailAddress->toJson()); | ||
$fromStringMailAddress = MailAddress::fromString($jsonString); | ||
|
||
$this->assertSame($output[1], $fromStringMailAddress->getAddress()); | ||
$this->assertSame($output[0], $fromStringMailAddress->getName()); | ||
} | ||
|
||
|
||
|
||
$name = "Peter Parker"; | ||
$address = "[email protected]"; | ||
$mailAddress = new MailAddress($address, $name); | ||
|
@@ -166,39 +219,4 @@ public function testCopy() | |
} | ||
|
||
|
||
/** | ||
* @see conjoon/php-lib-conjoon#12 | ||
*/ | ||
public function testForAddressThatNeedToBeSanitized() | ||
{ | ||
$tests = [ | ||
[ | ||
["Parker, Peter", "[email protected]"], | ||
["\"Parker, Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Parker Peter", "[email protected]"], | ||
["Parker Peter", "[email protected]"], | ||
], | ||
[ | ||
["Parker \" Peter", "[email protected]"], | ||
["\"Parker \\\" Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Parker ' Peter", "[email protected]"], | ||
["\"Parker \' Peter\"", "[email protected]"], | ||
], | ||
[ | ||
["Parker \"Parker, Peter Peter", "[email protected]"], | ||
["\"Parker \\\"Parker, Peter Peter\"", "[email protected]"], | ||
] | ||
]; | ||
|
||
foreach ($tests as $test) { | ||
[$input, $output] = $test; | ||
$mailAddress = new MailAddress($input[1], $input[0]); | ||
$this->assertSame($output[1], $mailAddress->getAddress()); | ||
$this->assertSame($output[0], $mailAddress->getName()); | ||
} | ||
} | ||
} |