Skip to content
Snippets Groups Projects
RechercheControllerPrintActionTest.php 8.44 KiB
Newer Older
Ghislain Loas's avatar
Ghislain Loas committed
<?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 RechercheControllerPrintActionLinkTest extends AbstractControllerTestCase {
efalcy's avatar
efalcy committed
  protected $_storm_default_to_volatile = true;
efalcy's avatar
efalcy committed
  public function setUp() {
Ghislain Loas's avatar
Ghislain Loas committed
  parent::setUp();

efalcy's avatar
efalcy committed
  $this->fixture('Class_ModeleFusion', ['id' => 1,
                                        'nom' => 'recherche',
                                        'contenu' => '<p> {notices.each[<img src="{url_vignette}"/>  {titre_principal} <div>{article.contenu}</div>
efalcy's avatar
efalcy committed
                                        'type' => 'Notice_List']);

    $this->fixture('Class_Catalogue',
                   ['id'=>3,
                    'libelle' => 'Nouveautés',
                    'auteur' => 'Paul']);

    $mock_sql = $this->mock()
                     ->whenCalled('fetchAll')
                     ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('+(APaul)' IN BOOLEAN MODE) order by annee desc", true, false)
                     ->answers([ [1, ''] ])
efalcy's avatar
efalcy committed
                     ->whenCalled('fetchAll')
                     ->answers([$this->fixture('Class_Notice',
                                               ['id' => 1])->toArray()])
                     ->beStrict();
efalcy's avatar
efalcy committed
    Zend_Registry::set('sql', $mock_sql);
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1', true);
  }
Ghislain Loas's avatar
Ghislain Loas committed


  /** @test */
efalcy's avatar
efalcy committed
  public function printLinkShouldBePresent() {
Laurent's avatar
Laurent committed
    $this->assertXPathContentContains('//a[contains(@href, "/recherche/print/id_catalogue/3/id_module/9/aleatoire/1/filtres/APaul%3B/ids/1/strategy/Notice_List/modele_fusion/1")][@target="_blank"]',
                                      'Imprimer',
                                      $this->_response->getBody());
efalcy's avatar
efalcy committed
  }
Ghislain Loas's avatar
Ghislain Loas committed
}



class RechercheControllerPrintActionWithRecordsTest extends AbstractControllerTestCase {
efalcy's avatar
efalcy committed
  protected $_storm_default_to_volatile = true;
efalcy's avatar
efalcy committed
  public function setUp() {
Ghislain Loas's avatar
Ghislain Loas committed
  parent::setUp();

efalcy's avatar
efalcy committed
  $this->fixture('Class_ModeleFusion', ['id' => 1,
                                        'nom' => 'recherche',
                                        'contenu' => '<p> {notices.each[<img src="{url_vignette}"/>  <h1>{titre_principal}</h1> <div>{article.contenu}</div> <div>{resume}</div>
Ghislain Loas's avatar
Ghislain Loas committed
]}</p>']);

efalcy's avatar
efalcy committed
  Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 10,
                                                                          'titre' => 'pomme',
                                                                          'contenu' => '<p>blabla</p>',
                                                                          'notice' => new Class_Notice(),
                                                                          'type_doc_id' => Class_TypeDoc::ARTICLE]));
efalcy's avatar
efalcy committed
  Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 12,
                                                                          'titre' => 'transmetropolitan',
                                                                          'contenu' => '<p>bd</p>',
                                                                          'notice' => new Class_Notice(),
                                                                          'type_doc_id' => Class_TypeDoc::ARTICLE]));
  $this->dispatch("/recherche/print/expressionRecherche/pomme/strategy/Notice_List/ids/2;1/modele_fusion/1",true);
efalcy's avatar
efalcy committed
  }
efalcy's avatar
efalcy committed
  /** @test */
  public function articlePommeShouldBeIndexed() {
    $this->assertNotNull(Class_Notice::findFirstBy(['titres' => 'POMME POM']));
  }
efalcy's avatar
efalcy committed
  /** @test */
  public function recordPommeShouldBeLinkedToPommeArticle() {
    $this->assertNotNull(Class_Notice::findFirstBy(['titres' => 'POMME POM'])->getArticle());
  }
efalcy's avatar
efalcy committed
  /** @test */
  public function displayShouldprintContent() {
    $this->assertXPathContentContains("//div//p", "bd", $this->_response->getBody());
  }
Ghislain Loas's avatar
Ghislain Loas committed


  /** @test */
efalcy's avatar
efalcy committed
  public function contenuShouldContainsTransmetropolitan() {
    $this->assertXPathContentContains("//div//h1[1]", "transmetropolitan", $this->_response->getBody());
  }
efalcy's avatar
efalcy committed
  public function pommeShouldBeDisplayedAfterTransmetropolitan() {
    $this->assertXPathContentContains("//h1[2]", "pomme", $this->_response->getBody());
  }
  /** @test */
  public function displayShouldNotPrintTagResume() {
    $this->assertNotXPathContentContains("//div", '{resume}');
  }




class RechercheControllerViewNoticePrintActionWithRecordsTest extends AbstractControllerTestCase {
efalcy's avatar
efalcy committed
  protected $_storm_default_to_volatile = true;
efalcy's avatar
efalcy committed
  public function setUp() {
  parent::setUp();
  Class_AdminVar::set("AVIS_MIN_SAISIE", 5);
  Class_AdminVar::set("AVIS_MAX_SAISIE", 500);
efalcy's avatar
efalcy committed
  $this->fixture('Class_ModeleFusion', ['id' => 1,
                                        'nom' => 'article',
                                        'contenu' => '<p><h1> {notice.titre_principal}</h1> <div>{notice.article.contenu} </div>
<div>{notice.resume} </div>
{notice.avis[<p>{avis}</p>]}
</p>',
                                        'type' => 'Notice_View']);
efalcy's avatar
efalcy committed
  Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 12,
                                                                          'titre' => 'transmetropolitan',
                                                                          'contenu' => '<p>bd</p>',
                                                                          'notice' => new Class_Notice(),
                                                                          'type_doc_id' => Class_TypeDoc::ARTICLE]));
  $avis = [
           $this->fixture('Class_AvisNotice', [
                                               'id' => 1,
                                               'id_user' => 1,
                                               'avis' => 'Lies are news and truth is obsolete.',
                                               'entete' => 'quotes',
                                               'note' => 4,
                                               'clef_oeuvre' => 'TRANSMETROPOLITAN---',
                                               'notice' => 1,
                                               'date_avis' => '2012-01-01',
                                               ]),
           $this->fixture('Class_AvisNotice', [
                                               'id' => 2,
                                               'id_user' => 1,
                                               'avis' => "The point is, the only real tools we have are our eyes and our heads. It's not the act of seeing with our eyes alone; it's correctly comprehending what we see. Treating life as an autopsy",
        'entete' => 'quotes',
                                               'note' => 4,
                                               'notice' => 1,
                                               'clef_oeuvre' => 'TRANSMETROPOLITAN---',
                                               'date_avis' => '2012-01-01',
                                               ]),
  ];



  $this->dispatch("/recherche/print/expressionRecherche/pomme/strategy/Notice_View/id/1/modele_fusion/1",true);
efalcy's avatar
efalcy committed
  }
efalcy's avatar
efalcy committed
  /** @test */
  public function displayShouldprintContent() {
    $this->assertXPathContentContains("//div//p", "bd", $this->_response->getBody());
  }
efalcy's avatar
efalcy committed
  public function contenuShouldContainsTransmetropolitan() {
    $this->assertXPathContentContains("//div//h1[1]", "transmetropolitan", $this->_response->getBody());
  }
  public function avisShouldBeDisplayed() {
    $this->assertXPathContentContains('//div//p', "Lies are news and truth is obsolete.",$this->_response->getBody());
  }


  /** @test */
  public function displayShouldNotPrintNoticeDotResume() {
    $this->assertNotXPathContentContains("//div", '{notice.resume}');
  }