diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php index b0f262e56e2796da2feeebe1c8c81d59950102f6..06bfe632df10bc47bc86024f53167031ce636ee6 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php @@ -16,137 +16,121 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; -require_once 'Class/AvisNotice.php'; -class CritiquesAvisEmptyTestCase extends ViewHelperTestCase { + +class CritiquesAvisEmptyTest extends ViewHelperTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); - $params = array('type_module' => 'CRITIQUES', - 'division' => 2, - 'preferences' => array()); - - $this->avis_loader = $this->getMock('MockLoader', array('getAvisFromPreferences')); - Storm_Model_Abstract::setLoaderFor('Class_AvisNotice', $this->avis_loader); - $this->avis_loader - ->expects($this->once()) - ->method('getAvisFromPreferences') - ->will($this->returnValue(array())); + $params = ['type_module' => 'CRITIQUES', + 'division' => 2, + 'preferences' => []]; $helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $params); $helper->setView(new ZendAfi_Controller_Action_Helper_View()); $this->html = $helper->getBoite(); } - public function testAucuneCritiquesPresent() { + + /** @test */ + public function aucuneCritiquesShouldBePresent() { $this->assertQueryContentContains($this->html, 'p', utf8_encode('Aucune critique récente')); } - public function testBoiteDivisionMilieu() { - $this->assertXPath($this->html, "//div[@class='boiteMilieu']"); + + /** @test */ + public function boiteMilieuShouldBePresent() { + $this->assertXPath($this->html, '//div[@class="boiteMilieu"]'); } } abstract class CritiquesAvisTestCase extends ViewHelperTestCase { - public function setUp() { - parent::setUp(); - $lolo = new Class_Users(); - $lolo - ->setId(91) - ->setPseudo('Lolo'); - - $millenium = new Class_Notice(); - $millenium - ->setId(9867) - ->setTitrePrincipal('Millenium (Stieg Larsson)') - ->setClefAlpha('MILLENIUM') - ->setUrlVignette('http://amazon.com/vignette.png'); - - $avis_millenium = new Class_AvisNotice(); - $avis_millenium - ->setId(23) - ->setEntete("J'adore") - ->setAvis("Suspense intense") - ->setNote(5) - ->setDateAvis('2010-03-18 13:00:00') - ->setUser($lolo) - ->setAbonOuBib(0) - ->setStatut(1) - ->setNotices(array($millenium)); - - $avis_orphan = new Class_AvisNotice(); - $avis_orphan - ->setId(34) - ->setEntete("J'ai oublié") - ->setAvis("Ce que c'était") - ->setNote(2) - ->setDateAvis('2010-03-18 13:00:00') - ->setUser($lolo) - ->setAbonOuBib(0) - ->setStatut(1) - ->setNotices(array()); - - - $potter = new Class_Notice(); - $potter - ->setId(687) - ->setTitrePrincipal('Potter') - ->setUrlVignette('NO'); - - $avis_potter = new Class_AvisNotice(); - $avis_potter - ->setId(87) - ->setEntete("Le sorcier") - ->setAvis("A du charme") - ->setNote(4) - ->setDateAvis('2010-03-18 13:00:00') - ->setUser($lolo) - ->setAbonOuBib(0) - ->setStatut(1) - ->setNotices(array($potter)); - - - $this->avis_loader = $this->getMock('MockLoader', array('getAvisFromPreferences', 'delete')); - Storm_Model_Abstract::setLoaderFor('Class_AvisNotice', $this->avis_loader); - - $this->avis_loader - ->expects($this->once()) - ->method('getAvisFromPreferences') - ->will($this->returnValue(array($avis_millenium, $avis_orphan, $avis_potter))); - } -} - + protected $_storm_default_to_volatile = true; + protected $_prefs = []; // subclass responsibility -class CritiquesWithVignettesTest extends CritiquesAvisTestCase { public function setUp() { parent::setUp(); - $params = array('type_module' => 'CRITIQUES', - 'division' => 1, - 'preferences' => array('rss_avis' => true, - 'only_img' => 1, - 'display_order' => 'Random', - 'titre' => 'Livres préférés', - 'nb_aff_avis' => '3', - 'nb_words' => 20, - 'boite' => 'boite_de_la_division_droite')); - - - $profil = new Class_Profil(); - $profil->setId(18); - Class_Profil::setCurrentProfil($profil); - - $helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $params); + Class_AdminVar::set('AVIS_MIN_SAISIE', 0); + Class_AdminVar::set('AVIS_MAX_SAISIE', 1000); + + $lolo = $this->fixture('Class_Users', ['id' => 91, + 'login' => 'lolo', + 'password' => 'il l\'a ?', + 'pseudo' => 'Lolo']); + + $millenium = $this->fixture('Class_Notice', + ['id' => 9867, + 'titre_principal' => 'Millenium (Stieg Larsson)', + 'clef_alpha' => 'MILLENIUM', + 'url_vignette' => 'http://amazon.com/vignette.png']); + + $avis_millenium = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'J\'adore', + 'avis' => 'Suspense intense', + 'note' => 5, + 'date_avis' => '2010-03-18 13:00:00', + 'user' => $lolo, + 'statut' => 1, + 'notices' => [$millenium]]); + + $avis_orphan = $this->fixture('Class_AvisNotice', + ['id' => 34, + 'entete' => 'J\'ai oublié', + 'avis' => 'Ce que c\'était', + 'note' => 2, + 'date_avis' => '2010-03-18 13:00:00', + 'user' => $lolo, + 'abon_ou_bib' => 0, + 'statut' => 1, + 'notices' => []]); + + $potter = $this->fixture('Class_Notice', + ['id' => 687, + 'titre_principal' => 'Potter', + 'url_vignette' => 'NO']); + + $avis_potter = $this->fixture('Class_AvisNotice', + ['id' => 87, + 'entete' => 'Le sorcier', + 'avis' => 'A du charme', + 'note' => 4, + 'date_avis' => '2010-03-18 13:00:00', + 'user' => $lolo, + 'abon_ou_bib' => 0, + 'statut' => 1, + 'notices' => [$potter]]); + + Class_Profil::setCurrentProfil($this->fixture('Class_Profil', ['id' => 18])); + + $helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $this->_prefs); $helper->setView(new ZendAfi_Controller_Action_Helper_View()); $this->html = $helper->getBoite(); } +} + - public function testMilleniumIsHere() { +class CritiquesWithVignettesTest extends CritiquesAvisTestCase { + protected $_prefs = ['type_module' => 'CRITIQUES', + 'division' => 1, + 'preferences' => ['rss_avis' => true, + 'only_img' => 1, + 'display_order' => 'Random', + 'titre' => 'Livres préférés', + 'nb_aff_avis' => '3', + 'nb_words' => 20, + 'boite' => 'boite_de_la_division_droite']]; + + + /** @test */ + public function milleniumShouldBePresent() { $this->assertQueryContentContains($this->html, 'div.critique h2', 'Millenium'); } @@ -154,71 +138,82 @@ class CritiquesWithVignettesTest extends CritiquesAvisTestCase { /** @test */ public function linkToMilleniumShouldContainsRetourAvisIdModuleTwo() { $this->assertXPath($this->html, - '//a[contains(@href, "/recherche/viewnotice/id/9867/clef/MILLENIUM/retour_avis/2")]',$this->html); + '//a[contains(@href, "/recherche/viewnotice/id/9867/clef/MILLENIUM/retour_avis/2")]'); } - public function testPotterIsNotShown() { + + /** @test */ + public function potterShouldNotBePresent() { $this->assertNotQueryContentContains($this->html, 'div.critique h2', 'Potter'); } - public function testOrphanAvisIsNotShown() { + + /** @test */ + public function orphanShouldNotBePresent() { $this->assertNotQueryContentContains($this->html, 'a', utf8_encode("J'ai oublié")); } - public function testTitreIsLivresPreferes() { + + /** @test */ + public function titleShouldBeLivresPreferes() { $this->assertQueryContentContains($this->html, 'a', utf8_encode('Livres préférés')); } - public function testRSSLinkPresents() { - $this->assertXPath($this->html, "//a[contains(@href, 'rss/critiques?id_module=2&id_profil=18')]"); + + /** @test */ + public function rssLinkShouldBePresent() { + $this->assertXPath($this->html, + "//a[contains(@href, 'rss/critiques?id_module=2&id_profil=18')]"); } - public function testBoiteDivisionDroite() { + + /** @test */ + public function boiteDroiteShouldBePresent() { $this->assertXPath($this->html, "//div[@class='boiteDroite']"); } } -class CritiquesWithEmptyVignettesAllowedTest extends CritiquesAvisTestCase { - public function setUp() { - parent::setUp(); - - $params = array('type_module' => 'CRITIQUES', - 'division' => 1, - 'preferences' => array('rss_avis' => false, - 'only_img' => 0, - 'display_order' => 'Random', - 'titre' => 'Livres préférés', - 'nb_aff_avis' => '3', - 'nb_words' => 20, - 'boite' => null)); - +class CritiquesWithEmptyVignettesAllowedTest extends CritiquesAvisTestCase { + protected $_prefs = ['type_module' => 'CRITIQUES', + 'division' => 1, + 'preferences' => ['rss_avis' => false, + 'only_img' => 0, + 'display_order' => 'Random', + 'titre' => 'Livres préférés', + 'nb_aff_avis' => '3', + 'nb_words' => 20, + 'boite' => null]]; - $helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $params); - $helper->setView(new ZendAfi_Controller_Action_Helper_View()); - $this->html = $helper->getBoite(); - } - public function testMilleniumIsHere() { + /** @test */ + public function milleniumShouldBePresent() { $this->assertQueryContentContains($this->html, 'div.critique h2', 'Millenium'); } - public function testPotterIsHere() { + + /** @test */ + public function potterShouldNotBePresent() { $this->assertQueryContentContains($this->html, 'div.critique h2', 'Potter'); } - public function testOrphanAvisIsNotShown() { + + /** @test */ + public function orphanShouldNotBePresent() { $this->assertNotQueryContentContains($this->html, 'a', utf8_encode("J'ai oublié")); } - public function testRSSLinkNotPresents() { - $this->assertNotXPath($this->html, "//div[@class='rss']/a[contains(@href, 'rss/critiques?id_module=2&id_profil=2')]"); + + /** @test */ + public function rssLinkShouldNotBePresent() { + $this->assertNotXPath($this->html, + "//a[contains(@href, 'rss/critiques?id_module=2&id_profil=2')]"); } - public function testBoiteDivisionGauche() { + + /** @test */ + public function boiteGaucheShouldBePresent() { $this->assertXPath($this->html, "//div[@class='boiteGauche']"); } -} - -?> \ No newline at end of file +} \ No newline at end of file