diff --git a/library/ZendAfi/View/Helper/RenderLieu.php b/library/ZendAfi/View/Helper/RenderLieu.php index 7c6b86eb80bfbbdd73e999a7c44323de572e726e..50fee6b2d7b5f2759902c6c9a2d824eb93bdabb7 100644 --- a/library/ZendAfi/View/Helper/RenderLieu.php +++ b/library/ZendAfi/View/Helper/RenderLieu.php @@ -24,12 +24,30 @@ class ZendAfi_View_Helper_RenderLieu extends Zend_View_Helper_HtmlElement { if (!$lieu) return ''; - $adresse = nl2br($lieu->getAdresse()) . '<br/>' . $lieu->getCodePostal() . ' ' . $lieu->getVille() . '<br />' . $lieu->getTelephone() . '<br />' . $lieu->getMail(); + + $adresse = array(); + + if (nl2br($lieu->getAdresse())) + $adresse[] = nl2br($lieu->getAdresse()); + + if ($lieu->getCodePostal()) + $adresse[] = $lieu->getCodePostal(); + + if ($lieu->getVille()) + $adresse[] = $lieu->getVille(); + + if ($lieu->getTelephone()) + $adresse[] = $lieu->getTelephone(); + + if ($lieu->getMail()) + $adresse[] = $lieu->getMail(); + + $adresse_str = implode('<br />', $adresse); return sprintf('<div class="lieu">%s %s <p>%s</p></div>', $this->view->mapForLieu($lieu, $map_options), $lieu->getLibelle(), - $adresse); + $adresse_str); } } diff --git a/tests/library/ZendAfi/View/Helper/RenderLieuTest.php b/tests/library/ZendAfi/View/Helper/RenderLieuTest.php index e1d4ff7e5bb7977c77fe8e56da8271ddbee3f42f..fe51545ec39726c3613815024163a5e7dc510284 100644 --- a/tests/library/ZendAfi/View/Helper/RenderLieuTest.php +++ b/tests/library/ZendAfi/View/Helper/RenderLieuTest.php @@ -38,16 +38,20 @@ class ZendAfi_View_Helper_RenderLieuTest extends ViewHelperTestCase { /** @test */ public function withLieuShouldRenderEmail() { - $this->assertContains('toto@example.com', $this->_helper->renderLieu(Class_Lieu::getLoader() - ->newInstanceWithId(4) - ->setMail('toto@example.com'))); + $this->assertContains('toto@example.com', $this->_helper->renderLieu($this->fixture( + 'Class_Lieu', + ['id' => 4, + 'libelle' => 'Mon lieu', + 'mail' => 'toto@example.com']))); } /** @test */ public function withLieuShouldRenderPhoneNumber() { - $this->assertContains('010203040506', $this->_helper->renderLieu(Class_Lieu::getLoader() - ->newInstanceWithId(4) - ->setTelephone('010203040506'))); + $this->assertContains('010203040506', $this->_helper->renderLieu($this->fixture( + 'Class_Lieu', + ['id' => 4, + 'libelle' => 'Mon lieu', + 'telephone' => '010203040506']))); }