Skip to content
Snippets Groups Projects
FormationsControllerTest.php 6.3 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 AbstractFormationsControllerTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setup() {
    parent::setup();

    ZendAfi_Auth::getInstance()->clearIdentity();
    $test_time = new TimeSourceForTest('2014-05-09 14:00:00');

    Class_Formation::setTimeSource($test_time);
    Class_SessionFormation::setTimeSource($test_time);



    $session_full = $this->fixture('Class_SessionFormation',
                                  ['id' => 1,
                                   'formation_id' => 1,
                                   'date_debut' => '2014-07-10',
                                   'date_limite_inscription' => '2014-07-01',
                                   'effectif_min' => 1,
                                   'effectif_max' => 1,
                                   'stagiaires' => []]);

    $session_canceled = $this->fixture('Class_SessionFormation',
                                       ['id' => 1,
                                        'formation_id' => 1,
                                        'date_debut' => '2014-07-10',
                                        'effectif_min' => 1,
                                        'effectif_max' => 10,
                                        'stagiaires' => []]);
    $session_canceled->beAnnule();
    $_bonlieu = $this->fixture('Class_Lieu',
                                     ['id' => 100,
                                      'libelle' => 'Bonlieu',
                                      'adresse' => "1, rue Jean-Jaures\nBP 294",
                                      'code_postal' => 74007,
                                      'ville' => 'Annecy',
                                      'latitude' => '45.902179',
                                      'longitude' => '6.128715']);


    $_session_java_fevrier = $this->fixture('Class_SessionFormation',
                                                  ['id' => 31,
                                                   'formation_id' => 3,
                                                   'effectif_min' => 2,
                                                   'effectif_max' => 5,
                                                   'lieu' => $_bonlieu,
                                                   'date_debut' => '2015-02-10',
                                                   'date_fin' => '2015-02-20',
                                                   'stagiaires' => [],
                                                   'date_limite_inscription' => '2015-01-20']);

    $session_subscription_exhausted = $this->fixture('Class_SessionFormation',
                                                     ['id' => 1,
                                                      'formation_id' => 1,
                                                      'date_debut' => '2014-07-10',
                                                      'date_limite_inscription' => '2014-01-10',
                                                      'effectif_min' => 1,
                                                      'effectif_max' => 10,
                                                      'stagiaires' => []]);

    $formation = $this->fixture('Class_Formation',
                   ['id' => 1,
                    'libelle' => 'Farming cerths',
                    'sessions' => [$session_full,
                                   $session_canceled,
                                   $_session_java_fevrier,
                                   $session_subscription_exhausted]]);
  }



class FormationsControllerFormationsSessionFevrierJavaTest extends AbstractFormationsControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/formations/detail-session/id/31', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsPopupLinkToInscrire() {
    $this->assertXPathContentContains('//a[contains(@href, "auth/popup-login/")]',
                                      'S\'inscrire', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function ddShouldContainsNombreDeParticipants() {
    $this->assertXPathContentContains('//dl/dd', 'minimum: 2, maximum: 5, actuel: 0');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function ddShouldContainsAdresseBonlieu() {
    $this->assertXPathContentContains('//dd', 'Bonlieu');
    $this->assertXPathContentContains('//dd', '1, rue Jean-Jaures');
    $this->assertXPathContentContains('//dd', '74007 Annecy');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function ddShouldContainsGoogleMap() {
    $this->assertXPath('//dd//img[@src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&zoom=15&size=300x300&center=45.902179%2C6.128715&markers=45.902179%2C6.128715"]');
  }
}




class FormationsControllerAnonymousTest extends AbstractFormationsControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/formations', true);
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function sessionShouldDisplaySubscribeTime() {
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertXPathContentContains('//tbody//tr/td/span',
                                      'Date de limite d\'inscription:');
  }
class FormationsControllerFormationsSessionJuilletPythonDetailRetourFicheTest extends AbstractFormationsControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/formations/detail-session/id/31?retour=/opac/abonne/fiche');
  }

  /** @test */
  public function pageShouldContainsAButtontoGoBackToFicheAbonne() {
    $this->assertXPathContentContains('//a[contains(@href, "abonne/fiche")]', 'Retour', $this->_response->getBody());
  }