Skip to content
Snippets Groups Projects
AbonneControllerMultimediaTest.php 41.1 KiB
Newer Older
llaffont's avatar
llaffont committed
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
 * BOKEH is free software; you can redistribute it and/or modify
llaffont's avatar
llaffont committed
 * 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,
llaffont's avatar
llaffont committed
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Patrick Barroca's avatar
Patrick Barroca committed
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
llaffont's avatar
llaffont committed
 * 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
llaffont's avatar
llaffont committed
 */

require_once 'AbstractControllerTestCase.php';
require_once 'application/modules/opac/controllers/AbonneController.php';
trait TAbonneControllerMultimediaFixtureHoldSuccessOnSept12 {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _launch() {
/*    $this->onLoaderOfModel('Class_Multimedia_Location')
      ->whenCalled('findByIdOrigine')
      ->answers(Class_Multimedia_Location::newInstanceWithId(1));


    $this->onLoaderOfModel('Class_Multimedia_Device')
      ->whenCalled('findByIdOrigineAndLocation')
      ->answers(Class_Multimedia_Device::newInstanceWithId(1));*/
    $this->fixture('Class_Multimedia_Device',
                   ['id' => 1,
                    'id_origine' => '1-1',
                    'group' => $this->fixture('Class_Multimedia_DeviceGroup',
                                                 ['id' => 1,
                                                  'location' => $this->fixture('Class_Multimedia_Location',
                                                                               ['id' => 1, 'id_origine' => 1,
                                                                                'ouvertures' => $this->fixture('Class_Ouverture',
                                                                                                                      ['id' => 1,
                                                                                                                       'Jour' => '2012-09-12',
                                                                                                                       'horaires' => ['08:00', '12:00', '12:00', '18:00']])
                                                                               ])
                                                 ])
                          ]);



    $this->onLoaderOfModel('Class_Multimedia_DeviceHold')
      ->whenCalled('getHoldOnDeviceAtTime')
      ->answers(Class_Multimedia_DeviceHold::newInstanceWithId(333)
        ->setIdUser($this->_user->getId())
        ->setEnd(strtotime('2012-09-12 16:40:00')));

    parent::_launch();
  }
}




trait TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _initUser() {
    $this->_user = AbonneControllerMultimediaUsersFixtures::getLaurent();
    $this->_group= 'Devs agiles';
  }
abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_json, $_auth;

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

    $this->_auth = Storm_Test_ObjectWrapper::mock()
      ->whenCalled('authenticateLoginPassword')->answers(false)
      ->whenCalled('hasIdentity')->answers(false)
      ->whenCalled('getIdentity')->answers(null)
      ->whenCalled('newAuthSIGB')->answers('auth_sigb')
      ->whenCalled('newAuthDb')->answers('auth_db');

    ZendAfi_Auth::setInstance($this->_auth);
  }


  public function tearDown() {
    ZendAfi_Auth::setInstance(null);
    parent::tearDown();
  }

  /**
   * @param $url string
   * @return stdClass
   */
  protected function getJson($url) {
    $this->dispatch($url, true);
    return json_decode($this->_response->getBody());
  }


  /**
   * @param $user Class_Users
   */
  protected function _expectUserToLoad($user) {
    $this->_auth
      ->whenCalled('authenticateLoginPassword')
      ->with($user->getLogin(), $user->getPassword(), ['auth_sigb', 'auth_db'])
      ->willDo(
        function() use ($user) {
          $this->_auth
            ->whenCalled('getIdentity')
            ->answers($user);
          return true;
        });

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')
      ->whenCalled('findFirstBy')
      ->with(array('login'=> $user->getLogin()))
      ->answers($user)

      ->whenCalled('findFirstBy')
      ->answers(null);
  }


  /**
   * @param $user Class_Users
   * @param $group_label string
   */
  protected function _expectGroupForUser($user, $group_label) {
    $this->fixture('Class_UserGroupMembership',
                   ['id' => 1,
                    'user'=>$user,
                    'user_group'=> $this->fixture('Class_UserGroup',
                                                  ['id'=>1,
                                                   'libelle'=>$group_label,
                                                  'group_type' => Class_UserGroup::TYPE_MULTIMEDIA])
                   ]);

  }
class AbonneControllerMultimediaAuthenticateValidationTest extends AbonneControllerMultimediaAuthenticateTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_expectUserToLoad(AbonneControllerMultimediaUsersFixtures::getLaurent());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function responseShouldNotBeARedirect() {
    $json = $this->getJson('/abonne/authenticate/login/any/password/any');
    $this->assertNotRedirect();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function controllerActionShouldBeAbonneAuthenticate() {
    $this->getJson('/abonne/authenticate/login/any/password/any');
    $this->assertController('abonne');
    $this->assertAction('authenticate');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutPosteShouldReturnErrorMissingParameter() {
    $json = $this->getJson('/abonne/authenticate/login/any');
    $this->assertEquals('MissingParameter', $json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutSiteShouldReturnErrorMissingParameter() {
    $json = $this->getJson('/abonne/authenticate/login/any/password/any/poste/1');
    $this->assertEquals('MissingParameter', $json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function getAbonneZorkShouldReturnErrorUserNotFound() {
    $json = $this->getJson('/abonne/authenticate/login/any/password/toto/poste/1/site/1');
    $this->assertEquals("UserNotFound", $json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function authenticateAbonneLaurentPasswordXXXShouldReturnWrongPassword() {
    $json = $this->getJson('/abonne/authenticate/login/laurent/password/xxx/poste/1/site/1');
    $this->assertEquals("PasswordIsWrong", $json->error);
  }
class AbonneControllerMultimediaAuthenticateMireilleTest extends AbonneControllerMultimediaAuthenticateTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $user = AbonneControllerMultimediaUsersFixtures::getMireille();
    $this->_expectUserToLoad($user);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_json = $this->getJson('/abonne/authenticate/login/mireille/password/afi/poste/1/site/1');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldReturnSubscriptionExpired() {
    $this->assertEquals('SubscriptionExpired', $this->_json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function dateFinShouldNotBePresent() {
    $this->assertFalse(isset($this->_json->date_fin));
  }
class AbonneControllerMultimediaAuthenticateInviteNonAfiMultimediaTest extends AbonneControllerMultimediaAuthenticateTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $user = AbonneControllerMultimediaUsersFixtures::getInvite();
    $this->_expectUserToLoad($user);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_json = $this->getJson('/abonne/authenticate/login/invite/password/invite/poste/1/site/1');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldReturnSubscriptionExpired() {
    $this->assertEquals('SubscriptionExpired', $this->_json->error);
  }

}

class AbonneControllerMultimediaAuthenticateInviteAfiMultimediaTest extends AbonneControllerMultimediaAuthenticateTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $user = AbonneControllerMultimediaUsersFixtures::getInvite();
    $this->_expectUserToLoad($user);
    $this->_expectGroupForUser($user, 'Abonne multimedia');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_json = $this->getJson('/abonne/authenticate/login/invite/password/invite/poste/1/site/1');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldReturnDeviceNotFound() {
    $this->assertEquals('DeviceNotFound', $this->_json->error);
  }
abstract class AbonneControllerMultimediaAuthenticateValidTestCase extends AbonneControllerMultimediaAuthenticateTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_user;
  protected $_group;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    Class_Multimedia_Location::setTimeSource(new TimeSourceForTest('2012-09-12 09:00:00'));
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_initUser();
    $this->_expectUserToLoad($this->_user);
    $this->_expectGroupForUser($this->_user, $this->_group);
    $this->_launch();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _initUser() {}
abstract class AbonneControllerMultimediaCheckedHoldableDayTestCase extends AbonneControllerMultimediaAuthenticateValidTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _launch() {
    $this->_json = $this->getJson(sprintf('/abonne/authenticate/login/%s/password/%s/poste/1/site/1/mode/holdable-day',
                                          $this->_user->getLogin(),
                                          $this->_user->getPassword()));
  }
}


class AbonneControllerMultimediaHoldableDay extends AbonneControllerMultimediaCheckedHoldableDayTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
    use
    TAbonneControllerMultimediaFixtureHoldSuccessOnSept12,
    TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
Patrick Barroca's avatar
Patrick Barroca committed
    /** @test */
    public function shouldHaveAuth() {
      $this->assertEquals(1, $this->_json->auth);
    }
Patrick Barroca's avatar
Patrick Barroca committed
    /** @test */
    public function shouldHaveHoldedDay() {
      $this->assertEquals(1, $this->_json->holding);
    }
abstract class AbonneControllerMultimediaHoldedTestCase extends AbonneControllerMultimediaAuthenticateValidTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _launch() {
    $this->_json = $this->getJson(sprintf('/abonne/authenticate/login/%s/password/%s/poste/1/site/1/mode/hold',
                                          $this->_user->getLogin(),
                                          $this->_user->getPassword()));
  }
class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneControllerMultimediaHoldedTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  use
    TAbonneControllerMultimediaFixtureHoldSuccessOnSept12,
    TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldNotReturnError() {
    $this->assertFalse(property_exists($this->_json, 'error'));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function idShoudBe8() {
    $this->assertEquals('8', $this->_json->id);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function loginShoudBelaurent() {
    $this->assertEquals('laurent', $this->_json->login);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function passwordShoudBeAfi() {
    $this->assertEquals('afi', $this->_json->password);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function nomShoudBelaffont() {
    $this->assertEquals('laffont', $this->_json->nom);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function prenomShoudBelaurent() {
    $this->assertEquals('laurent', $this->_json->prenom);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function dateNaissanceShoudBe1978_02_17() {
    $this->assertEquals('1978/02/17', $this->_json->date_naissance);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function groupShoudBeAdulteAbonneAdminAndAgile() {
    $this->assertEquals(array('adulte','abonne', 'abonne_sigb', 'Devs agiles'),
                        $this->_json->groupes);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldHaveAuth() {
    $this->assertEquals(1, $this->_json->auth);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldHaveHold() {
    $this->assertEquals(1, $this->_json->holded);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function holdShouldLastUntil16h40() {
    $this->assertEquals('2012-09-12T16:40:00+02:00', $this->_json->until);
  }
class AbonneControllerMultimediaAuthenticateLaurentDeviceNotHeldByUserTest extends AbonneControllerMultimediaHoldedTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  use TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _launch() {
    $this->onLoaderOfModel('Class_Multimedia_Location')
      ->whenCalled('findByIdOrigine')
      ->answers($location = Class_Multimedia_Location::newInstanceWithId(1)
                ->setAuthDelay(1)
                ->setAutohold(1));
Patrick Barroca's avatar
Patrick Barroca committed
    $this->onLoaderOfModel('Class_Multimedia_Device')
      ->whenCalled('findByIdOrigineAndLocation')
      ->answers(Class_Multimedia_Device::newInstanceWithId(1)
                ->setGroup(Class_Multimedia_DeviceGroup::newInstanceWithId(34)->setLocation($location)));
Patrick Barroca's avatar
Patrick Barroca committed
    $this->onLoaderOfModel('Class_Multimedia_DeviceHold')
      ->whenCalled('getHoldOnDeviceAtTime')
      ->answers(Class_Multimedia_DeviceHold::newInstanceWithId(333)
                ->setIdUser(9878)
                ->setStart(strtotime('2012-09-12 08:30:00'))
                ->setEnd(strtotime('2012-09-12 16:40:00')));
Patrick Barroca's avatar
Patrick Barroca committed
    parent::_launch();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function jsonShouldContainsErrorDeviceNotHeldByUser() {
    $this->assertEquals('DeviceNotHeldByUser', $this->_json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function loginShoudBelaurent() {
    $this->assertEquals('laurent', $this->_json->login);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function authShouldBeZero() {
    $this->assertEquals('0', $this->_json->auth);
  }
class AbonneControllerMultimediaAuthenticateLaurentDeviceNotFoundTest extends AbonneControllerMultimediaHoldedTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  use TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
  protected function _launch() {
    $this->onLoaderOfModel('Class_Multimedia_Location')
      ->whenCalled('findByIdOrigine')
      ->answers(Class_Multimedia_Location::newInstanceWithId(1));
Patrick Barroca's avatar
Patrick Barroca committed
    $this->onLoaderOfModel('Class_Multimedia_Device')
      ->whenCalled('findByIdOrigineAndLocation')
      ->answers(null);
Patrick Barroca's avatar
Patrick Barroca committed
    parent::_launch();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function jsonShouldContainsErrorDeviceNotFound() {
    $this->assertEquals('DeviceNotFound', $this->_json->error);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function loginShoudBelaurent() {
    $this->assertEquals('laurent', $this->_json->login);
  }
class AbonneControllerMultimediaAuthenticateArnaudTest extends AbonneControllerMultimediaHoldedTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  use TAbonneControllerMultimediaFixtureHoldSuccessOnSept12;
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _initUser() {
    $this->_user = AbonneControllerMultimediaUsersFixtures::getArnaud();
    $this->_group= 'Patrons';
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function groupsShouldBeAbonneAndPatrons() {
    $this->assertEquals(array('abonne_sigb', 'Patrons'), $this->_json->groupes);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldNotReturnError() {
    $this->assertFalse(property_exists($this->_json, 'error'));
  }
class AbonneControllerMultimediaAuthenticateBaptisteTest extends AbonneControllerMultimediaHoldedTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  use TAbonneControllerMultimediaFixtureHoldSuccessOnSept12;
Patrick Barroca's avatar
Patrick Barroca committed
  protected function _initUser() {
    $this->_user = AbonneControllerMultimediaUsersFixtures::getBaptiste();
    $this->_group= 'Devs Oldschool';
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function groupsShouldBeMineurAbonneAndOldSchool() {
    $this->assertEquals(['mineur','abonne_sigb', 'Devs Oldschool'],
                        $this->_json->groupes);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function dateFinShouldBe3000_01_01() {
    $this->assertEquals('3000-01-01', $this->_json->date_fin);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function dateDebutShouldBe1978_05_23() {
    $this->assertEquals('1978-05-23', $this->_json->date_debut);
  }
/* Début test du workflow de réservation */
abstract class AbonneControllerMultimediaHoldTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_session;
  protected $_bean;

  public function setUp() {
    parent::setUp();
    $this->_session = new Zend_Session_Namespace('abonneController');
    $this->_session->holdBean = $this->_bean = new Class_Multimedia_ReservationBean();

    Class_Users::getIdentity()
      ->setUserGroups([Class_UserGroup::newInstanceWithId(12)
                       ->setMaxDay(120)
                       ->setMaxWeek(240)
                       ->setMaxMonth(360)]);

    $this
      ->onLoaderOfModel('Class_Multimedia_DeviceHold')
      ->whenCalled('getDurationForUserBetweenTimes')
      ->answers(0);
  }


  protected function _prepareLocationInSession() {
    $this->_bean->location = 123;

    Class_Bib::newInstanceWithId(3)
      ->setLibelle('Médiathèque d\'Antibes');


    Class_Multimedia_Location::newInstanceWithId(123)
      ->setIdSite(3)
      ->setLibelle('Antibes')
      ->setSlotSize(30)
      ->setMaxSlots(4)
      ->setHoldDelayMin(0)
      ->setHoldDelayMax(60)
      ->setOuvertures([Class_Ouverture::chaqueLundi('08:30', '12:00', '12:00', '17:45')->setId(1)->cache(),
                       Class_Ouverture::chaqueMercredi('08:30', '12:00', '12:00', '17:45')->setId(3)->cache(),
                       Class_Ouverture::chaqueJeudi('08:30', '12:00', '12:00', '17:45')->setId(4)->cache()])
      ->setGroups([Class_Multimedia_DeviceGroup::newInstanceWithId(3)
                   ->setLibelle('Musique')
                   ->setDevices([Class_Multimedia_Device::getLoader()
                                 ->newInstanceWithId(1)
                                 ->setLibelle('Poste 1')
                                 ->setOs('Ubuntu Lucid')
                                 ->setDisabled(0),

                                 Class_Multimedia_Device::getLoader()
                                 ->newInstanceWithId(3)
                                 ->setLibelle('Poste 3')
                                 ->setOs('OSX')
                                 ->setDisabled(0)]),

                   Class_Multimedia_DeviceGroup::newInstanceWithId(5)
                   ->setLibelle('Jeunesse')
                   ->setDevices([
                                 Class_Multimedia_Device::getLoader()
                                 ->newInstanceWithId(2)
                                 ->setLibelle('Poste 2')
                                 ->setOs('Windows XP')
                                 ->setDisabled(0),

                                 Class_Multimedia_Device::getLoader()
                                 ->newInstanceWithId(4)
                                 ->setLibelle('Poste 4')
                                 ->setOs('Amiga OS')
                                 ->setDisabled(0)])
                   ]);
  }


  protected function _prepareDayInSession() {
    $this->_bean->day = '2012-09-12';
  }


  protected function _prepareTimeAndDurationInSession() {
    $this->_bean->time = '9:45';
    $this->_bean->duration = 45;
  }


  protected function _prepareGroupInSession() {
    $this->_bean->group = 5;
  }


  protected function _assertCurrentTimelineStep($step) {
    $this->_assertTimeLineStepWithClass($step, 'selected');
  }


  protected function _assertPassedTimelineStep($step) {
    $this->_assertTimeLineStepWithClass($step, 'passed');
  }


  protected function _assertTimeLineStepWithClass($step, $class) {
    $this->assertXPathContentContains('//div[@class="timeline"]//li[@class="' . $class . '"]',
                                      $step);
  }
abstract class AbonneControllerMultimediaHoldLocationTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Location')
        ->whenCalled('findAllBy')
        ->answers([
                   Class_Multimedia_Location::newInstanceWithId(1)
                   ->setLibelle('Salle 1')
                   ->setBib(Class_Bib::newInstanceWithId(1)->setLibelle('Médiathèque Antibes'))
                   ->setOuvertures([Class_Ouverture::chaqueLundi('8:00', '12:00', '13:00', '18:00')->cache()]),

                   Class_Multimedia_Location::newInstanceWithId(2)
                   ->setLibelle('Salle 2')
                   ->setBib(Class_Bib::newInstanceWithId(2)->setLibelle('Médiathèque Roquefort'))
                   ->setOuvertures([Class_Ouverture::chaqueMercredi('8:00', '12:00', '13:00', '18:00')->cache()]),

                   Class_Multimedia_Location::newInstanceWithId(3)
                   ->setLibelle('Salle 3')
                   ->setBib(Class_Bib::newInstanceWithId(3)->setLibelle('Médiathèque Valbonne'))
                   ->setOuvertures([]),

                   Class_Multimedia_Location::newInstanceWithId(5)
                   ->setLibelle('Erreur')
                   ->setBib(null)
                   ->setOuvertures([])
                   ]);
    $this->dispatch('/abonne/multimedia-hold-location', true);
  }


  /** @test */
  public function bodyShouldContainsClass_abonne_multimedia_hold_location() {
    $this->assertXPath('//body[contains(@class, "abonne_multimedia-hold-location")]');
  }


  /** @test */
  public function currentTimelineStepShouldBeLieu() {
    $this->_assertCurrentTimelineStep('Lieu');
  }


  /** @test */
  public function locationSalle1ShouldBePresent() {
    $this->assertXPathContentContains('//a[contains(@href, "/multimedia-hold-location/location/1")]', 'Médiathèque Antibes');
  }


  /** @test */
  public function locationSalle2ShouldBePresent() {
    $this->assertXPathContentContains('//a[contains(@href, "/multimedia-hold-location/location/2")]', 'Médiathèque Roquefort');
  }


  /** @test */
  public function locationSalle3WithoutAnyOuvertureShouldNotBePresent() {
    $this->assertNotXPath('//a[contains(@href, "/multimedia-hold-location/location/3")]');
  }


/* Validation du lieu, on est redirigé sur l'écran choix du jour */
class AbonneControllerMultimediaHoldLocationChoiceTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/abonne/multimedia-hold-location/location/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRedirectToNextStep() {
    $this->assertRedirectTo('/abonne/multimedia-hold-day');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function beanShouldHaveLocationSet() {
    $this->assertEquals(1, $this->_session->holdBean->location);
  }
class AbonneControllerMultimediaHoldDayTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->dispatch('/abonne/multimedia-hold-day', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function bodyShouldContainsClass_abonne_multimedia_hold_location() {
    $this->assertXPath('//body[contains(@class, "abonne_multimedia-hold-day")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function currentTimelineStepShouldBeJour() {
    $this->_assertCurrentTimelineStep('Jour');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function timelineStepShouldBePassed() {
    $this->_assertPassedTimelineStep('Lieu');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function calendarShouldBePresent() {
    $this->assertXPath('//div[@class="calendar"]');
  }


/* Validation du second écran choix du jour, redirection vers le choix de l'heure */
class AbonneControllerMultimediaHoldDayChoiceTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->dispatch('/abonne/multimedia-hold-day/day/2012-09-12', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRedirectToNextStep() {
    $this->assertRedirectTo('/abonne/multimedia-hold-hours');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function beanShouldHaveDaySet() {
    $this->assertEquals('2012-09-12', $this->_session->holdBean->day);
  }


/* Validation du second écran mais l'utilisateur a dépassé son quota de réservation */
class AbonneControllerMultimediaHoldDayChoiceWithOverQuotaTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
Patrick Barroca's avatar
Patrick Barroca committed
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
      ->whenCalled('getDurationForUserBetweenTimes')
      ->answers(8000);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/abonne/multimedia-hold-day/day/2012-09-12', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldNotRedirect() {
    $this->assertNotRedirect();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function quotaErrorShouldBePresent() {
    $this->assertXPathContentContains('//div', 'Quota déjà atteint ce jour');
  }



/* Troisième écran choix de l'heure de début de réservation */
class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
Patrick Barroca's avatar
Patrick Barroca committed
    Class_Multimedia_Location::setTimeSource(new TimeSourceForTest('2012-09-12 09:00:00'));
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/abonne/multimedia-hold-hours', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function currentTimelineStepShouldBeHoraires() {
    $this->_assertCurrentTimelineStep('Horaires');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function listOfStartTimesShouldBePresent() {
    $this->assertXPathCount('//select[@id="time"]/option', 17, $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function startingAt10ShouldBePossible() {
    $this->assertXPathContentContains('//option[@value="10:00"]', '10h00');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function startingAt8AndHalfShouldNotBePossible() {
    $this->assertNotXpath('//option[@value="08:30"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function oneHourDurationOptionShouldBePresent() {
    $this->assertXPathContentContains('//option[@value="60"]', '1h');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function oneHourAndAHalfDurationLinkShouldBePresent() {
    $this->assertXPathContentContains('//option[@value="90"]', '1h30mn');
  }


/* Troisième écran choix de l'heure, redirection sur le choix du poste */
class AbonneControllerMultimediaHoldHoursChoiceTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
    $this->dispatch('/abonne/multimedia-hold-hours/time/' . urlencode('9:45') . '/duration/45', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRedirectToNextStep() {
    $this->assertRedirectTo('/abonne/multimedia-hold-group');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function beanShouldHaveTimeAndDurationSet() {
    $this->assertEquals('9:45', $this->_session->holdBean->time);
    $this->assertEquals('45', $this->_session->holdBean->duration);
  }


/* Troisième écran choix d'une heure déjà allouée */
class AbonneControllerMultimediaHoldHoursChooseAlreadyHeldTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
        ->whenCalled('countBetweenTimesForUser')
        ->answers(1);
    $this->dispatch('/abonne/multimedia-hold-hours/time/' . urlencode('9:45') . '/duration/45', true);
  }


  /** @test */
  public function errorMessageShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="error"]', 'Vous avez déjà une réservation dans ce créneau horaire');
  }
/* Quatrième écran choix du groupe de postes */
class AbonneControllerMultimediaHoldGroupTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
    $this->_prepareTimeAndDurationInSession();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/abonne/multimedia-hold-group', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsLinkToGroupMusique() {
    $this->assertXPathContentContains('//a[contains(@href, "/multimedia-hold-group/group/3")]', 'Musique');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsLinkToGroupJeunesse() {
    $this->assertXPathContentContains('//a[contains(@href, "/multimedia-hold-group/group/5")]', 'Jeunesse');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function currentTimelineShouldBeSecteur() {
    $this->_assertCurrentTimelineStep('Secteur');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function timelinePreviousActionsShouldHaveLink() {
    $this->assertXPathContentContains('//div[@class="timeline"]//li//a[contains(@href, abonne/multimedia-hold-location)]', 'Lieu');
    $this->assertXPathContentContains('//div[@class="timeline"]//li//a[contains(@href, abonne/multimedia-hold-day)]', 'Jour');
    $this->assertXPathContentContains('//div[@class="timeline"]//li//a[contains(@href, abonne/multimedia-hold-hours)]', 'Horaires');
    $this->assertNotXPathContentContains('//div[@class="timeline"]//li//a', 'Secteur');
    $this->assertNotXPathContentContains('//div[@class="timeline"]//li//a', 'Poste');
    $this->assertNotXPathContentContains('//div[@class="timeline"]//li//a', 'Confirmation');
  }
}




/* Quatrième écran validation du choix du groupe de postes, redirection vers le choix du poste */
class AbonneControllerMultimediaHoldGroupChoiceTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
    $this->_prepareTimeAndDurationInSession();
    $this->dispatch('/abonne/multimedia-hold-group/group/5', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function shouldRedirectToStepHoldDevice() {
    $this->assertRedirectTo('/abonne/multimedia-hold-device');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function beanShouldHaveGroupSetToFive() {
    $this->assertEquals(5, $this->_session->holdBean->group);
  }
/* Quatrième écran validation du choix du groupe de postes, redirection vers le choix du poste */
class AbonneControllerMultimediaHoldGroupChoiceErrorTest extends AbonneControllerMultimediaHoldTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutHoursShouldRedirectToHoldHours() {
    $this->_prepareLocationInSession();
    $this->_prepareDayInSession();
    $this->dispatch('/abonne/multimedia-hold-group/group/5', true);
    $this->assertRedirectTo('/abonne/multimedia-hold-hours');
  }


  /** @test */
  public function withoutDayShouldRedirectToHoldDay() {
    $this->_prepareLocationInSession();
    $this->_prepareTimeAndDurationInSession();
    $this->dispatch('/abonne/multimedia-hold-group/group/5', true);
    $this->assertRedirectTo('/abonne/multimedia-hold-day');
  }


  /** @test */
  public function withoutLocationShouldRedirectToHoldLocation() {
    $this->_prepareDayInSession();
    $this->_prepareTimeAndDurationInSession();
    $this->dispatch('/abonne/multimedia-hold-group/group/5', true);
    $this->assertRedirectTo('/abonne/multimedia-hold-location');
  }