Skip to content
Snippets Groups Projects
BlogControllerTest.php 7.18 KiB
Newer Older
<?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 {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['blog' => ['hierarchical' => ['nb_display' => 2]]]);

Patrick Barroca's avatar
Patrick Barroca committed
    Class_AdminVar::set('AVIS_MIN_SAISIE', 0);
    Class_AdminVar::set('AVIS_MAX_SAISIE', 1000);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->theme = $this->fixture('Class_Catalogue',
                                  ['id' => 10, 'libelle' => 'THEME']);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->art = $this->fixture('Class_Catalogue',
                                ['id' => 12, 'libelle' => 'Art',
                                 'tags' => 'jeuxvideo',
                                 'domaine_parent' => $this->theme]);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->music = $this->fixture('Class_Catalogue',
                                  ['id' => 14, 'libelle' => 'Musique',
                                   'domaine_parent' => $this->art]);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->bd = $this->fixture('Class_Catalogue',
                               ['id' => 15, 'libelle' => 'BD',
                                'domaine_parent' => $this->art]);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->ksp = $this->fixture('Class_Notice',
                                ['id' => 233134,
                                 'titre_principal' => 'Kerbal Space Program',
                                 'clef_oeuvre' => 'KERBALSPACEPROG-SQUAD-',
                                 'clef_alpha' => 'KERBALSPACEPROG-SQUAD-']);
Patrick Barroca's avatar
Patrick Barroca committed
    $this
      ->onLoaderOfModel('Class_Catalogue')
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('getNoticesByPreferences')
      ->with(['id_panier' => 0,
              'id_catalogue' => 12,
              'abon_ou_bib' => 'all',
              'nb_notices' => null,
              'aleatoire' => 0,
              'avec_avis' => 1])
      ->answers([$this->ksp]);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->fixture('Class_AvisNotice',
                   ['id' => 1,
                    'id_notice' => 233134,
Patrick Barroca's avatar
Patrick Barroca committed
                    'note' => 5,
                    'entete' => 'Incroyable',
                    'id_notice' => $this->ksp->getId(),
Patrick Barroca's avatar
Patrick Barroca committed
                    '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()]);

Patrick Barroca's avatar
Patrick Barroca committed
    $this->fixture('Class_Users',
                   ['id' => 3,
                    'login' => 'Harlock',
                    'password' => 'arcadia']);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/blog/hierarchical/id/12/start_id/12/truncate_at/30', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldNotDisplaySearch() {
    $this->assertNotXPath('//input[@name="title_search"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldNotDisplayCount() {
    $this->assertNotXPathContentContains('//a', '(0)');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function rootDomainLinkShouldNotBePresent() {
    $this->assertNotDomainLink($this->theme, 12);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function startDomainLinkShouldBePresent() {
    $this->assertDomainLink($this->art, 12);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function musicDomainShouldBePresent() {
    $this->assertDomainLink($this->music, 12);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function bdDomainShouldBePresent() {
    $this->assertDomainLink($this->bd, 12);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspShouldBePresent() {
    $this->assertXPathContentContains('//h2', 'Kerbal Space Program',$this->_response->getBody());
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspRecordLinkShouldBePresent() {
    $this->assertXPathContentContains('//a[contains(@href, "recherche/viewnotice/id/233134/clef/KERBALSPACEPROG-SQUAD-")]',
                                      'Voir la notice',
                                      $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspRatingShouldBeFive() {
    $this->assertXPath('//img[contains(@src, "stars-5.gif")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @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 !');
  }


Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspAuthorShouldBePresent() {
    $this->assertXPathContentContains('//a[contains(@href, "blog/viewauteur/id/3")]',
                                      'Harlock');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspDateShouldBePresent() {
    $this->assertXPathContentContains('//span', '18 mai 2015');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function kspReviewContentShouldBePresent() {
    $this->assertXPathContentContains('//p', 'What a wonderful game');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  protected function assertDomainLink($domain, $start) {
    call_user_func_array([$this, 'assertXPathContentContains'],
                         $this->_linkDomainAssertParams($domain, $start));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  protected function assertNotDomainLink($domain, $start) {
    call_user_func_array([$this, 'assertNotXPathContentContains'],
                         $this->_linkDomainAssertParams($domain, $start));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  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()];
  }