addressFormatRepository = new AddressFormatRepository();
$this->countryRepository = new CountryRepository();
$this->subdivisionRepository = new SubdivisionRepository();
$this->formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository);
}
/**
* @covers ::__construct
*/
public function testConstructor(): void
{
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository);
$reflected_constraint = (new \ReflectionObject($formatter))->getProperty('addressFormatRepository');
$reflected_constraint->setAccessible(TRUE);
$constraint = $reflected_constraint->getValue($formatter);
$this->assertInstanceOf(AddressFormatRepository::class, $constraint);
$reflected_constraint = (new \ReflectionObject($formatter))->getProperty('countryRepository');
$reflected_constraint->setAccessible(TRUE);
$constraint = $reflected_constraint->getValue($formatter);
$this->assertInstanceOf(CountryRepository::class, $constraint);
$reflected_constraint = (new \ReflectionObject($formatter))->getProperty('subdivisionRepository');
$reflected_constraint->setAccessible(TRUE);
$constraint = $reflected_constraint->getValue($formatter);
$this->assertInstanceOf(SubdivisionRepository::class, $constraint);
}
/**
* @covers ::__construct
*/
public function testUnrecognizedOption()
{
$this->expectException(\InvalidArgumentException::class);
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['unrecognized' => '123']);
}
/**
* @covers ::__construct
*/
public function testInvalidOption()
{
$this->expectException(\InvalidArgumentException::class);
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['html' => 'INVALID']);
}
/**
* @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter
*/
public function testAndorraAddress()
{
$address = new Address();
$address = $address
->withCountryCode('AD')
->withLocality("Parròquia d'Andorra la Vella")
->withPostalCode('AD500')
->withAddressLine1('C. Prat de la Creu, 62-64');
// Andorra has no predefined administrative areas, but it does have
// predefined localities, which must be shown.
$expectedTextLines = [
'C. Prat de la Creu, 62-64',
"AD500 Parròquia d'Andorra la Vella",
'Andorra',
];
$textAddress = $this->formatter->format($address, ['html' => false]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
}
/**
* @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter
*/
public function testElSalvadorAddress()
{
$address = new Address();
$address = $address
->withCountryCode('SV')
->withAdministrativeArea('Ahuachapán')
->withLocality('Ahuachapán')
->withAddressLine1('Some Street 12');
$expectedHtmlLines = [
'
',
'Some Street 12
',
'Ahuachapán
',
'Ahuachapán
',
'El Salvador',
'
',
];
$htmlAddress = $this->formatter->format($address);
$this->assertFormattedAddress($expectedHtmlLines, $htmlAddress);
$expectedTextLines = [
'Some Street 12',
'Ahuachapán',
'Ahuachapán',
'El Salvador',
];
$textAddress = $this->formatter->format($address, ['html' => false]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
$address = $address->withPostalCode('CP 2101');
$expectedHtmlLines = [
'',
'Some Street 12
',
'CP 2101-Ahuachapán
',
'Ahuachapán
',
'El Salvador',
'
',
];
$htmlAddress = $this->formatter->format($address);
$this->assertFormattedAddress($expectedHtmlLines, $htmlAddress);
$expectedTextLines = [
'Some Street 12',
'CP 2101-Ahuachapán',
'Ahuachapán',
'El Salvador',
];
$textAddress = $this->formatter->format($address, ['html' => false]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
}
/**
* @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter
*/
public function testTaiwanAddress()
{
$address = new Address();
$address = $address
->withCountryCode('TW')
->withAdministrativeArea('Taipei City')
->withLocality("Da'an District")
->withAddressLine1('Sec. 3 Hsin-yi Rd.')
->withPostalCode('106')
// Any HTML in the fields is supposed to be removed when formatting
// for text, and escaped when formatting for html.
->withOrganization('Giant Bike
Store')
->withGivenName('Te-Chiang')
->withFamilyName('Liu')
->withLocale('zh-Hant');
$expectedHtmlLines = [
'',
'台灣
',
'106
',
'台北市大安區
',
'Sec. 3 Hsin-yi Rd.
',
'Giant <h2>Bike</h2> Store
',
'Liu Te-Chiang',
'
',
];
// Test wrapper attributes and a custom locale.
$htmlAddress = $this->formatter->format($address, [
'locale' => 'zh-Hant',
'html_attributes' => [
'translate' => 'no',
'class' => ['address', 'postal-address'],
],
]);
$this->assertFormattedAddress($expectedHtmlLines, $htmlAddress);
$expectedTextLines = [
'台灣',
'106',
'台北市大安區',
'Sec. 3 Hsin-yi Rd.',
'Giant Bike Store',
'Liu Te-Chiang',
];
$textAddress = $this->formatter->format($address, [
'locale' => 'zh-Hant',
'html' => false,
]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
}
/**
* @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter
*/
public function testUnitedStatesIncompleteAddress()
{
$address = new Address();
$address = $address
->withCountryCode('US')
->withAdministrativeArea('CA')
->withPostalCode('94043')
->withAddressLine1('1098 Alta Ave');
$expectedHtmlLines = [
'',
'1098 Alta Ave
',
'CA 94043
',
'United States',
'
',
];
$htmlAddress = $this->formatter->format($address);
$this->assertFormattedAddress($expectedHtmlLines, $htmlAddress);
$expectedTextLines = [
'1098 Alta Ave',
'CA 94043',
'United States',
];
$textAddress = $this->formatter->format($address, ['html' => false]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
// Now add the locality, but remove the administrative area.
$address = $address
->withLocality('Mountain View')
->withAdministrativeArea('');
$expectedHtmlLines = [
'',
'1098 Alta Ave
',
'Mountain View, 94043
',
'United States',
'
',
];
$htmlAddress = $this->formatter->format($address);
$this->assertFormattedAddress($expectedHtmlLines, $htmlAddress);
$expectedTextLines = [
'1098 Alta Ave',
'Mountain View, 94043',
'United States',
];
$textAddress = $this->formatter->format($address, ['html' => false]);
$this->assertFormattedAddress($expectedTextLines, $textAddress);
}
/**
* Asserts that the formatted address is valid.
*/
protected function assertFormattedAddress(array $expectedLines, string $formattedAddress)
{
$expectedLines = implode("\n", $expectedLines);
$this->assertEquals($expectedLines, $formattedAddress);
}
}
__halt_compiler();----SIGNATURE:----O/WSqb4faxxBLTRjrA7nD7ti2jSqDfQycFwwGQIXpZBpsC3l5/SfKmq5QqJaiYM99ugnpimeHZHx5Vapm9mE79CQJjUEJt0sJ33aVBa91UwOc8rIcR1rc620HnZdEBs2yg1ymTw3C6x8Qao6GV/Ggja6vao7jwZs5Rl7KjJhsZ4ysGZcWJ42w/ZhMMgl9qgR/48U6oq9yjwpVnHRLkl7coBKsWXejjJKXz1HBPatG8wHtobZMB0rQekD3YEIqUDIGRn+McxrWZMvpdKAr0KXsC+3GzqEk+A+mAN5nZTKeSiwVV3KNzAugHLzvvW4ipopT6Wo32WWXd9zo0Wp1PKLvqDsQZwYOlMPMrmDCdmMLWYvGgL27dvudkclxjbSFV/CVH522i8EkequzwXdXDfa6ASOHgA1hPG155fBBiH3VIKYJCU0Z8PFMRctrTuYme9IKkZzHrtmmRC3sfpX9o7WYxRsYfWZAM0pMasbCInHNlrtB6XkL9gGhOQMHQxAEi0OW8LGwvrTFgPx2ceu7irMSvmvoppaGouglalB6tbfOAO8Q3qxzvJio4ccim43EUtxULtxwMj2APnV21WsLyv70U37puAHRDb+fiVgVE473qLdCZVM/w5ld7depdRqwG3Cd+1xlDac5M//QAOHAmq1hXa/ieaMWfruUYZVHE5RJ9Q=----ATTACHMENT:----MjkzMTUyNDE3NzU2NjY2IDE3NTQ3NzExMjUzODgxMjcgMjQ1NTYzODkyNDg0Njg0OA==