Skip to content
Snippets Groups Projects
DatasControllerTest.php 3.62 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
Patrick Barroca's avatar
Patrick Barroca committed
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */


class DatasControllerTest 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();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->fixture('Class_Formation',
                   ['id'=> 22,
                    'sessions' => [$this->fixture('Class_SessionFormation',
                                                  ['id'=>88,
                                                   'date_debut' => '2014-12-12',
                                                   'date_fin' => '2015-01-25']),
                                   $this->fixture('Class_SessionFormation',
                                                  ['id'=>89,
                                                   'date_debut' => '2014-12-12',
                                                   'date_fin' => '2015-01-25']),
                                   $this->fixture('Class_SessionFormation',
                                                  ['id'=>90,
                                                   'date_debut' => '2014-12-12',
                                                   'date_fin' => '2015-01-25']),
                                   $this->fixture('Class_SessionFormation',
                                                  ['id'=>91,
                                                   'date_debut' => '2014-12-12',
                                                   'date_fin' => '2015-01-25'])
                    ]
                   ]);

    $this->fixture('Class_CustomField',
                   ['id' => 19,
                    'model' => 'SessionFormation',
                    'meta' => $this->fixture('Class_CustomField_Meta',
                                             ['id' => 1,
                                              'label' => 'thématique'])]);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 23,
                    'custom_field_id' => 19,
                    'value' => 'Macramé']);
  }

Patrick Barroca's avatar
Patrick Barroca committed
  protected function assertBody($content) {
    $this->assertEquals($content, $this->_response->getBody());
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function fieldsOfSessionFormationShouldReturnJson() {
    $this->dispatch('/opac/datas/fields/model/SessionFormation');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertBody('[{"priority":0,"id":19,"model":"SessionFormation","meta_id":1,"label":"th\u00e9matique","field_type":"text","options_list":"","indexable":0}]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function valuesOfFieldThematiqueShouldReturnJson() {
    $this->dispatch('/opac/datas/values/field/19');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertBody('[{"value":"Macram\u00e9","id":23,"custom_field_id":19}]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  public function numberOfSessionForFormationShouldReturnJson() {
    $this->dispatch('/opac/datas/numberof/model/Class_Formation/id/22/children/Sessions');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertBody('4');
Patrick Barroca's avatar
Patrick Barroca committed
  }