<?php /** * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * * BOKEH is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * the Free Software Foundation. * * There are special exceptions to the terms and conditions of the AGPL as it * is applied to this software (see README file). * * BOKEH is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * 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 */ class BlogControllerHierarchicalTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); Class_Profil::getCurrentProfil() ->setCfgModules(['blog' => ['hierarchical' => ['nb_display' => 2]]]); Class_AdminVar::set('AVIS_MIN_SAISIE', 0); Class_AdminVar::set('AVIS_MAX_SAISIE', 1000); $this->theme = $this->fixture('Class_Catalogue', ['id' => 10, 'libelle' => 'THEME']); $this->art = $this->fixture('Class_Catalogue', ['id' => 12, 'libelle' => 'Art', 'tags' => 'jeuxvideo', 'domaine_parent' => $this->theme]); $this->music = $this->fixture('Class_Catalogue', ['id' => 14, 'libelle' => 'Musique', 'domaine_parent' => $this->art]); $this->bd = $this->fixture('Class_Catalogue', ['id' => 15, 'libelle' => 'BD', 'domaine_parent' => $this->art]); $this->ksp = $this->fixture('Class_Notice', ['id' => 233134, 'titre_principal' => 'Kerbal Space Program', 'clef_oeuvre' => 'KERBALSPACEPROG-SQUAD-', 'clef_alpha' => 'KERBALSPACEPROG-SQUAD-']); $this ->onLoaderOfModel('Class_Catalogue') ->whenCalled('getNoticesByPreferences') ->with(['id_panier' => 0, 'id_catalogue' => 12, 'abon_ou_bib' => 'all', 'nb_notices' => null, 'aleatoire' => 0, 'avec_avis' => 1]) ->answers([$this->ksp]); $this->fixture('Class_AvisNotice', ['id' => 1, 'id_notice' => 233134, 'note' => 5, 'entete' => 'Incroyable', 'id_notice' => $this->ksp->getId(), 'avis' => 'What a wonderful game', 'statut' => 1, 'date_avis' => '2015-05-18 00:00:00', 'id_user' => 3, 'clef_oeuvre' => $this->ksp->getClefOeuvre()]); $this->fixture('Class_AvisNotice', ['id' => 2, 'note' => 4, 'entete' => 'Nice !', 'avis' => 'What a nice game', 'statut' => 1, 'date_avis' => '2016-05-18 00:00:00', 'id_user' => 3, 'clef_oeuvre' => $this->ksp->getClefOeuvre()]); $this->fixture('Class_AvisNotice', ['id' => 3, 'note' => 5, 'entete' => 'So hot !', 'avis' => 'What a hot game', 'statut' => 1, 'date_avis' => '2014-05-18 00:00:00', 'id_user' => 3, 'clef_oeuvre' => $this->ksp->getClefOeuvre()]); $this->fixture('Class_Users', ['id' => 3, 'login' => 'Harlock', 'password' => 'arcadia']); $this->dispatch('/blog/hierarchical/id/12/start_id/12/truncate_at/30', true); } /** @test */ public function shouldNotDisplaySearch() { $this->assertNotXPath('//input[@name="title_search"]'); } /** @test */ public function shouldNotDisplayCount() { $this->assertNotXPathContentContains('//a', '(0)'); } /** @test */ public function rootDomainLinkShouldNotBePresent() { $this->assertNotDomainLink($this->theme, 12); } /** @test */ public function startDomainLinkShouldBePresent() { $this->assertDomainLink($this->art, 12); } /** @test */ public function musicDomainShouldBePresent() { $this->assertDomainLink($this->music, 12); } /** @test */ public function bdDomainShouldBePresent() { $this->assertDomainLink($this->bd, 12); } /** @test */ public function kspShouldBePresent() { $this->assertXPathContentContains('//h2', 'Kerbal Space Program',$this->_response->getBody()); } /** @test */ public function kspRecordLinkShouldBePresent() { $this->assertXPathContentContains('//a[contains(@href, "recherche/viewnotice/id/233134/clef/KERBALSPACEPROG-SQUAD-")]', 'Voir la notice', $this->_response->getBody()); } /** @test */ public function kspRatingShouldBeFive() { $this->assertXPath('//img[contains(@src, "stars-5.gif")]'); } /** @test */ public function kspReviewTitleShouldBePresent() { $this->assertXPathContentContains('//a[contains(@href, "blog/viewavis/id/1")]', 'Incroyable'); } /** @test */ public function kspSecondReviewTitleShouldBePresent() { $this->assertXPathContentContains('//a[contains(@href, "blog/viewavis/id/2")]', 'Nice'); } /** @test */ public function kspThirdReviewTitleShouldNotBePresent() { $this->assertNotXPathContentContains('//a[contains(@href, "blog/viewavis/id/3")]', 'So hot !'); } /** @test */ public function kspAuthorShouldBePresent() { $this->assertXPathContentContains('//a[contains(@href, "blog/viewauteur/id/3")]', 'Harlock'); } /** @test */ public function kspDateShouldBePresent() { $this->assertXPathContentContains('//span', '18 mai 2015'); } /** @test */ public function kspReviewContentShouldBePresent() { $this->assertXPathContentContains('//p', 'What a wonderful game'); } protected function assertDomainLink($domain, $start) { call_user_func_array([$this, 'assertXPathContentContains'], $this->_linkDomainAssertParams($domain, $start)); } protected function assertNotDomainLink($domain, $start) { call_user_func_array([$this, 'assertNotXPathContentContains'], $this->_linkDomainAssertParams($domain, $start)); } protected function _linkDomainAssertParams($domain, $start) { return [sprintf('//a[contains(@href, "blog/hierarchical/start_id/%s/truncate_at/30/id/%s")]', $start, $domain->getId()), $domain->getLibelle(), $this->_response->getBody()]; } }