Skip to content
Snippets Groups Projects
BlogControllerTest.php 11.6 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 {

  protected bool $_storm_mock_zend_adapter = true;
  protected array $_storm_scopes = [BlogController::class];
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);
    $this->theme = $this->fixture(Class_Catalogue::class,
                                  ['id' => 10,
                                   'libelle' => 'THEME']);
    $this->art = $this->fixture(Class_Catalogue::class,
                                ['id' => 12,
                                 'libelle' => 'Art',
Patrick Barroca's avatar
Patrick Barroca committed
                                 'tags' => 'jeuxvideo',
                                 'domaine_parent' => $this->theme]);
    $this->music = $this->fixture(Class_Catalogue::class,
                                  ['id' => 14,
                                   'libelle' => 'Musique',
Patrick Barroca's avatar
Patrick Barroca committed
                                   'domaine_parent' => $this->art]);
    $this->bd = $this->fixture(Class_Catalogue::class,
                               ['id' => 15,
                                'libelle' => 'BD',
Patrick Barroca's avatar
Patrick Barroca committed
                                'domaine_parent' => $this->art]);
    $this->ksp = $this->fixture(Class_Notice::class,
Patrick Barroca's avatar
Patrick Barroca committed
                                ['id' => 233134,
                                 'titre_principal' => 'Kerbal Space Program',
                                 'clef_oeuvre' => 'KERBALSPACEPROG-SQUAD-',
                                 'clef_alpha' => 'KERBALSPACEPROG-SQUAD-',
                                 'facettes' => 'Zjeuxvideo',
                                 'type' => 1]);
    $this->fixture(Class_AvisNotice::class,
Patrick Barroca's avatar
Patrick Barroca committed
                   ['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,
                    'source_author' => null,
Patrick Barroca's avatar
Patrick Barroca committed
                    'clef_oeuvre' => $this->ksp->getClefOeuvre()]);
    $this->fixture(Class_AvisNotice::class,
                   ['id' => 2,
                    'note' => 4,
                    'entete' => 'Nice !',
                    'avis' => 'What a nice game',
                    'statut' => 1,
                    'date_avis' => '2016-05-18 00:00:00',
                    'id_user' => 3,
                    'source_author' => null,
                    'clef_oeuvre' => $this->ksp->getClefOeuvre()]);

    $this->fixture(Class_AvisNotice::class,
                   ['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,
                    'source_author' => null,
                    'clef_oeuvre' => $this->ksp->getClefOeuvre()]);

    $this->fixture(Class_Users::class,
Patrick Barroca's avatar
Patrick Barroca committed
                   ['id' => 3,
                    'login' => 'Harlock',
                    'password' => 'arcadia']);
    $this->dispatch('/blog/hierarchical/id/12/start_id/12/truncate_at/30');
  }


  /** @test */
  public function requestShouldExists() {
    $this->assertSqlEquals(["SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC0001%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1",
                            "SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC00010001%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1",
                            "SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC00010002%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1",
                            "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_Zjeuxvideo' IN BOOLEAN MODE) AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 2",
                            "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (2, 1)) ORDER BY `notices_avis`.`date_avis` DESC"]);
Patrick Barroca's avatar
Patrick Barroca committed
  }
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');
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');
Patrick Barroca's avatar
Patrick Barroca committed
  }
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")]',
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()];
  }
/** @see http://forge.afi-sa.fr/issues/99313 */
class BlogControllerViewavisTest extends AbstractControllerTestCase {

  public function setUp() {
    parent::setUp();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['blog' => ['viewavis' => ['barre_nav' => 'Coups de coeur à partager']]]);

    Class_AdminVar::set('AVIS_MIN_SAISIE', 0);
    Class_AdminVar::set('AVIS_MAX_SAISIE', 1000);

    $this->ksp = $this->fixture(Class_Notice::class,
                                ['id' => 233134,
                                 'titre_principal' => 'Kerbal Space Program',
                                 'clef_oeuvre' => 'KERBALSPACEPROG-SQUAD-',
                                 'clef_alpha' => 'KERBALSPACEPROG-SQUAD-']);

    $this->fixture(Class_AvisNotice::class,
                   ['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,
                    'source_author' => null,
                    'clef_oeuvre' => $this->ksp->getClefOeuvre()]);

    $this->fixture(Class_Users::class,
                   ['id' => 3,
                    'login' => 'Harlock',
                    'password' => 'arcadia']);

    $this->dispatch('/blog/viewavis/id/1/retour_avis/10');
  }


  /** @test */
  public function breadcrumbShouldContainsCoupsDeCoeurAPartager() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span',
                                      'Coups de coeur à partager');
  }
}




/** @see http://forge.afi-sa.fr/issues/142068 */
class BlogControllerAvisWithoutAuthorTest extends AbstractControllerTestCase {

  public function setUp() {
    parent::setUp();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['blog' => ['viewavis' => ['barre_nav' => 'Coups de coeur à partager']]]);

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'titre_principal' => 'Mon voisin Totoro']);

    $this->fixture(Class_AvisNotice::class,
                   ['id' => 2,
                    'id_notice' => 1,
                    'note' => 5,
                    'entete' => 'Incroyable',
                    'id_notice' => 1,
                    'avis' => 'J\'aime ce que je veux',
                    'statut' => 1,
                    'date_avis' => '2021-12-13 00:00:00',
                    'id_user' => 3]);
  }


  /** @test */
  public function fromCritiquesPageAvis2ShouldDisplayAuthorAnonymeWithoutLink() {
    $this->dispatch('/blog/viewcritiques');
    $this->assertXPath('//span[@class="auteur_critique"][text()="Anonyme "]');
  }


  /** @test */
  public function fromAvisPageAvis2ShouldDisplayAuthorAnonymeWithoutLink() {
    $this->dispatch('/blog/viewavis/id/2');
    $this->assertXPath('//span[@class="auteur_critique"][text()="Anonyme "]');
  }
}