Skip to content
Snippets Groups Projects
RechercheControllerReservationTest.php 55.9 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
 * 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).
 *
Laurent's avatar
Laurent committed
 * 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
Laurent's avatar
Laurent committed
 * along with BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

abstract class RechercheControllerReservationTestCase
  extends AbstractControllerTestCase {

  protected $_json, $_xpath,
    $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->fixture(Class_CodifAnnexe::class,
                   ['id' => 2,
                    'code' => '36',
                    'id_origine' => '36',
                    'libelle' => 'Annecy']);
    $this->fixture(Class_CodifAnnexe::class,
                   ['id' => 3,
                    'code' => '37',
                    'id_origine' => '37',
                    'libelle' => 'Cran']);
    $this->fixture(Class_Notice::class,
                   ['id' => 124,
                    'titre' => 'Aimer'
                   ]);

    $this->fixture(Class_IntBib::class,
                   ['id' => 12,
                    'sigb_comm' => Class_IntBib::COM_NANOOK,
                    'comm_params' => ['url_serveur' => 'http://valensol.net']]);

    $this->fixture(Class_Exemplaire::class,
                   ['id' => 13425,
                    'id_origine' => 12,
                    'id_int_bib' => 12,
                    'notice_id' => 124,
                    'code_barres' => '1242',
                   ]);

abstract class RechercheControllerReservationWithPickupChoiceTestCase
  extends RechercheControllerReservationTestCase {

  public function setUp() {
    parent::setUp();
    Class_CosmoVar::setValueOf('site_retrait_resa',
                               Class_CosmoVar::PICKUP_LOCATION_CHOICE);
  }
}



class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest
  extends RechercheControllerReservationWithPickupChoiceTestCase {

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

    $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=13425',true);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_json = json_decode($this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRenderAnnecyCheckedRadio() {
    $this->_xpath->assertXPath($this->_json->content,
                               '//input[@name="code_annexe"][@value="36"][@checked="checked"]',$this->_json->content);
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRenderCranRadio() {
    $this->_xpath->assertXPath($this->_json->content,
                               '//input[@name="code_annexe"][@value="37"]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function layoutShouldBeEmpty() {
    $this->_xpath->assertNotXPath($this->_json->content, '//div[@id="banniere"]');
  }
class RechercheControllerReservationPickupAjaxActionPostTest
  extends RechercheControllerReservationWithPickupChoiceTestCase {
  /** @test */
  public function responseShouldRedirectToReservationajaxAction() {
Ghislain Loas's avatar
Ghislain Loas committed
    $this->postDispatch('recherche/reservation-pickup-ajax',
                        ['id_bib' => 2,
                         'id_origine' => 12,
                         'copy_id' => 13425,
    $this->assertRedirectTo('/recherche/reservationajax/code_annexe/36');
  /** @test */
  public function withoutAvailablePickupLocationPostResponseShouldAnswerError() {
    Class_CodifAnnexe::deleteBy([]);
    $this->postDispatch('recherche/reservation-pickup-ajax',
                        ['id_bib' => 2,
                         'id_origine' => 12,
                         'copy_id' => 13425,
                         'code_annexe' => '36']);
    $json = json_decode($this->_response->getBody(), true);
    $this->assertContains('Aucun site de retrait disponible', $json['content']);
  }


  /** @test */
  public function withoutAvailablePickupLocationGETResponseShouldAnswerError() {
    Class_CodifAnnexe::deleteBy([]);
    $this->dispatch('recherche/reservation-pickup-ajax/id_bib/2/id_origine/12/copy_id/13425');
    $json = json_decode($this->_response->getBody(), true);
    $this->assertContains('Aucun site de retrait disponible', $json['content']);
  }


  /** @test */
  public function withPopupAndInspectorGadgetResponseShouldStillSendJSON() {
    Zend_Registry::get('session')->inspectorCalls = [serialize(new Class_InspectorGadget_ServiceCall('I', 'love', 'milk', 'coffee', '418'))];

    $this->postDispatch('recherche/reservation-pickup-ajax/render/popup/inspector_gadget/1',
                        ['id_bib' => 2,
                         'id_origine' => 12,
                         'copy_id' => 13425,
                         'code_annexe' => '36']);
    $this->assertNotNull($json = json_decode($this->_response->getBody(), true));
    $this->assertContains('<script>location.reload();</script>', $json['content']);
  }


Ghislain Loas's avatar
Ghislain Loas committed
  /** @test */
  public function responseShouldContainsJsonRedirectToReservationajaxAction() {
    $this->postDispatch('recherche/reservation-pickup-ajax/render/popup',
                        ['id_bib' => 2,
                         'id_origine' => 12,
                         'copy_id' => 13425,
Ghislain Loas's avatar
Ghislain Loas committed
    $json = json_decode($this->_response->getBody(), true);
    $this->assertContains('<script>location.reload();</script>', $json['content']);
class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch
  extends RechercheControllerReservationWithPickupChoiceTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
      ->fixture(Class_IntBib::class,
                ['id' => 1,
                 'comm_sigb' => Class_IntBib::COM_NANOOK,
                 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]);

    $this->jajm = $this
      ->fixture(Class_Users::class,
                ['id' => 1,
Loading full blame...