Skip to content

Commit

Permalink
added function validAddressPieces
Browse files Browse the repository at this point in the history
added function validAddressPieces

Update FormatTest.php

Update FormatTest.php

Update FormatTest.php

Update FormatTest.php

Update FormatTest.php
  • Loading branch information
ickbinhier committed Jan 25, 2015
1 parent 47cb5bf commit ef7d983
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Adamlc/AddressFormat/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,33 @@ public function offsetUnset($offset)
$this->offsetSet($offset, '');
}
}

/**
* Return the valid pieces
*
* @access public
* @return array
*/
public function validAddressPieces()
{
$return = array();

if (isset($this->locale['fmt']))
{
$address_format_array = explode("%", $this->locale['fmt']);
foreach($address_format_array as $key => $value )
{
$value = trim($value);
if( !empty($value) && isset($this->address_map[$value]) )
{
$return[]=$this->address_map[$value];
}
}
return $return;
} else {
throw new LocaleMissingFormatException('Locale missing format');
}
}


}
61 changes: 60 additions & 1 deletion tests/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,63 @@ public function testArrayAccess()
'Schulstrasse 4'
);
}
}

/**
* Check that an exception is thrown for validAddressPieces by invlidate locale
*
* @expectedException Adamlc\AddressFormat\Exceptions\LocaleMissingFormatException
* @return void
*/
public function testValidAddressPiecesLocaleMissingFormatException()
{
//Clear any previously set attributes
$this->container->clearAttributes();

//Set expected Exception
$this->setExpectedException('Adamlc\AddressFormat\Exceptions\LocaleMissingFormatException');

$this->container->validAddressPieces();
}

/**
* Test get the ordered adress pieces for this locale
*
* @return void
*/
public function testValidAddressPieces()
{
//Clear any previously set attributes
$this->container->clearAttributes();

//Set Locale
$this->container->setLocale('DE');

//get the ordered adress pieces for this locale
$validAddressPieces = $this->container->validAddressPieces();

$this->assertEquals(
$validAddressPieces[0],
"RECIPIENT"
);

$this->assertEquals(
$validAddressPieces[1],
"ORGANIZATION"
);

$this->assertEquals(
$validAddressPieces[2],
"STREET_ADDRESS"
);

$this->assertEquals(
$validAddressPieces[3],
"POSTAL_CODE"
);

$this->assertEquals(
$validAddressPieces[4],
"LOCALITY"
);
}
}

0 comments on commit ef7d983

Please sign in to comment.