Skip to content
Snippets Groups Projects
NoticeAjaxControllerItemsTest.php 5.55 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
 */


abstract class NoticeAjaxControllerItemsTestCase 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();
    $this->fixture('Class_IntBib',
                   ['id' => 3,
                    'comm_sigb' => Class_IntBib::COM_VSMART
                   ]);


Patrick Barroca's avatar
Patrick Barroca committed
    $itemA = $this->fixture('Class_Exemplaire',
                            ['id' => 12,
                             'id_bib' => 3,
                             'id_int_bib' => 3,
                             'cote' => 'A',
                             'dispo' => 'Non',
                             'zone995' => serialize([['code' => '9', 'valeur' => '12']])]);
Patrick Barroca's avatar
Patrick Barroca committed
    $itemB = $this->fixture('Class_Exemplaire',
                            ['id' => 134,
                             'id_bib' => 3,
                             'id_int_bib' => 3,
                             'cote' => 'B',
                             'dispo' => 'Non',
                             'zone995' => serialize([['code' => '9', 'valeur' => '345']])]);
Patrick Barroca's avatar
Patrick Barroca committed
    $itemC = $this->fixture('Class_Exemplaire',
                            ['id' => 67,
                             'id_bib' => 3,
                             'id_int_bib' => 3,
                             'cote' => 'C',
                             'dispo' => 'Non',
                             'zone995' => serialize([])]);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->fixture('Class_Notice',
                   ['id' => 731325,
Patrick Barroca's avatar
Patrick Barroca committed
                    'exemplaires' => [$itemA, $itemB, $itemC]]);
    $sigb_exemplaire = new Class_WebService_SIGB_Exemplaire(1);


    $mock_sigb_comm = $this->mock()
                           ->whenCalled('getExemplaire')
                           ->answers($sigb_exemplaire);

    Class_WebService_SIGB_VSmart::setService($mock_sigb_comm);

Patrick Barroca's avatar
Patrick Barroca committed
    $this->_prepareFixtures();
    $this->dispatch('/noticeajax/exemplaires/id/731325', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _prepareFixtures() {
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  protected function assertXPathContentOrder($query, $contents=[]) {
    $doc = new DOMDocument();
    @$doc->loadHTML($this->_response->getBody());
    $xpath = new DOMXPath($doc);
    $nodes = $xpath->query($query);
Patrick Barroca's avatar
Patrick Barroca committed
    foreach($contents as $k => $v)
      $this->assertEquals($v, $nodes->item($k)->textContent,
                          sprintf('Failed asserting that %s appears in position %s',
                                  $v, $k));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldDisplayListSummary() {
    $this->assertXPathContentContains('//summary', 'Liste des exemplaires');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function coteAShouldBePresent() {
    $this->assertXPathContentContains('//td[@class="cote"]', 'A',
                                      $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function coteBShouldBePresent() {
    $this->assertXPathContentContains('//td[@class="cote"]', 'B',
                                      $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function coteCShouldBePresent() {
    $this->assertXPathContentContains('//td[@class="cote"]', 'C',
                                      $this->_response->getBody());
  }
}



class NoticeAjaxControllerItemsWithoutOrderTest
Patrick Barroca's avatar
Patrick Barroca committed
  extends NoticeAjaxControllerItemsTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _prepareFixtures() {
    $config = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
    $config['exemplaires']['grouper'] = '1';
    Class_Profil::getCurrentProfil()->setCfgNotice($config);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function orderShouldBeABC() {
    $this->assertXPathContentOrder('//td[@class="cote"]',
                                   ['A', 'B', 'C']);
  }
}



class NoticeAjaxControllerItemsWithOrder995Dollar9AscTest
Patrick Barroca's avatar
Patrick Barroca committed
  extends NoticeAjaxControllerItemsTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _prepareFixtures() {
    $config = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
    $config['exemplaires']['grouper'] = '1';
    $config['exemplaires']['order_by'] = '9';
    Class_Profil::getCurrentProfil()->setCfgNotice($config);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function orderShouldBeCAB() {
    $this->assertXPathContentOrder('//td[@class="cote"]',
                                   ['C', 'A', 'B']);
  }
}



class NoticeAjaxControllerItemsWithOrder995Dollar9DescTest
Patrick Barroca's avatar
Patrick Barroca committed
  extends NoticeAjaxControllerItemsTestCase {

  protected function _prepareFixtures() {
    $config = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
    $config['exemplaires']['grouper'] = '1';
    $config['exemplaires']['order_by'] = '9';
    $config['exemplaires']['order_direction'] = 'DESC';
    Class_Profil::getCurrentProfil()->setCfgNotice($config);
  }


  /** @test */
  public function orderShouldBeCAB() {
    $this->assertXPathContentOrder('//td[@class="cote"]',
                                   ['B', 'A', 'C']);
  }