Skip to content
Snippets Groups Projects
DynamicFacetsControllerTest.php 11.2 KiB
Newer Older
Laurent's avatar
Laurent committed
<?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
 */


class Cosmo_DynamicFacetsControllerIndexTest extends CosmoControllerTestCase {
Laurent's avatar
Laurent committed
  public function setUp() {
Laurent's avatar
Laurent committed

    $this->fixture('Class_CodifThesaurus',
                   ['id' => 3,
                    'libelle' => 'Document',
                    'libelle_facette' => 'Document',
                    'id_thesaurus' => 'DOCU',
                    'id_origine' => null,
                    'code' => 'DOCU',
                    'rule_zone' => '345',
                    'rule_label_field' => 't',
                    'rule_id_field' => '9']);
    $this->dispatch('/cosmo/facets/index', true);
  }
  /** @test */
  public function titleShouldBeDynamicFacets() {
    $this->assertXpathContentContains('//h1' , 'Facettes dynamiques');
Laurent's avatar
Laurent committed

Laurent's avatar
Laurent committed

Laurent's avatar
Laurent committed
  /** @test */
  public function addButtonShouldBePresent() {
    $this->assertXpath('//button[contains(@data-url, "/cosmo/facets/add")]');
  }
Laurent's avatar
Laurent committed


  /** @test */
  public function documentShouldBeDisplayed() {
    $this->assertXpathContentContains('//td', 'Document');
  }
Laurent's avatar
Laurent committed

Laurent's avatar
Laurent committed

  /** @test */
  public function documentEditLinkShouldBeDisplayed() {
    $this->assertXpath('//td//a[contains(@href, "/facets/edit/id/3")]');
  }
Laurent's avatar
Laurent committed

  /** @test */
  public function documentDeleteLinkShouldBeDisplayed() {
    $this->assertXpath('//td//a[contains(@href, "/facets/delete/id/3")]');
  }
}
Laurent's avatar
Laurent committed

Laurent's avatar
Laurent committed

class Cosmo_DynamicFacetsControllerAddTest extends CosmoControllerTestCase {
  public function setUp() {
    parent::setUp();
    $this->dispatch('/cosmo/facets/add', true);
  }

  /** @test */
  public function titleShouldBePresent() {
    $this->assertXpathContentContains('//h1', 'Ajouter une facette dynamique');
  }
Laurent's avatar
Laurent committed

  /** @test */
  public function labelShouldDefaultToNouvelleFacette() {
    $this->assertXpath('//input[@name="libelle"][@value="** nouvelle facette dynamique **"]');
  }
Laurent's avatar
Laurent committed

  /** @test */
  public function zoneShouldBePresent() {
    $this->assertXPath('//input[@name="rule_zone"]');
  }
  /** @test */
  public function labelFieldShouldBePresent() {
    $this->assertXPath('//select[@name="rule_label_field"]');
  }
Laurent's avatar
Laurent committed


  /** @test */
  public function idFieldShouldBePresent() {
    $this->assertXPath('//select[@name="rule_id_field"]');
  }
  /** @test */
  public function labelForBokehShouldBePresent() {
    $this->assertXPath('//input[@name="libelle_facette"][@value="** nouvelle facette dynamique **"]');
  }


  /** @test */
  public function inputLabelStartPosShouldBeNumberWithValueOne() {
    $this->assertXPath('//input[@name="rule_label_start_pos"][@type="number"][@min="1"][@value="1"]');
  }


  /** @test */
  public function inputLabelLengthShouldBeNumberWithValueZero() {
    $this->assertXPath('//input[@name="rule_label_length"][@type="number"][@min="0"][@value="0"]');
  }
class Cosmo_DynamicFacetsControllerAddPostValidTest extends CosmoControllerTestCase {
  protected $model;
  public function setUp() {
    parent::setUp();
    $this->postDispatch('/cosmo/facets/add', ['libelle'          => 'New facet name',
                                              'rule_zone'        => '609',
                                              'rule_label_field' => 'a',
                                              'rule_id_field'    => '9',
                                              'rule_label_start_pos' => '2',
                                              'rule_label_length' => '4']);
    Class_CodifThesaurus::clearCache();
    $this->model = Class_CodifThesaurus::findFirstBy(['libelle' => 'New facet name']);
  }
  /** @test */
  public function labelShouldBeNewFacetName() {
    $this->assertEquals('New facet name', $this->model->getLibelle());
  }
  /** @test */
  public function idThesaurusShouldBeNEWF() {
    $this->assertEquals('NEWF', $this->model->getIdThesaurus());
  }

  /** @test */
  public function zoneShouldBe609() {
    $this->assertEquals('609', $this->model->getRuleZone());
  }
  /** @test */
  public function labelFieldShouldBeA() {
    $this->assertEquals('a', $this->model->getRuleLabelField());
  }


  /** @test */
  public function idFieldShouldBe9() {
    $this->assertEquals('9', $this->model->getRuleIdField());
  }


  /** @test */
  public function rulesLabelStartPosShouldBeTwo() {
    $this->assertEquals('2', $this->model->getRulesAsArray()['rule_label_start_pos']);
  }


  /** @test */
  public function rulesLabelLengthShouldBeFour() {
    $this->assertEquals('4', $this->model->getRulesAsArray()['rule_label_length']);
  }
class Cosmo_DynamicFacetsControllerValidateTest extends CosmoControllerTestCase {
  /** @test */
  public function idThesaurusShouldBeDOC0() {
    $this->postDispatch('/cosmo/facets/add', ['libelle' => 'doc',
                                              'rule_zone' => '033',
                                              'rule_label_field' => '8',
                                              'rule_label_start_pos' => '1',
                                              'rule_label_length' => '0']);
    $this->assertEquals('DOC0',
                        Class_CodifThesaurus::findFirstBy(['libelle'=>'doc'])->getIdThesaurus());
  }
  /** @test */
  public function withExistingIdThesaurusDOCXNewIdThesaurusShouldBeDOC1() {
    $this->fixture('Class_CodifThesaurus',
                   ['libelle' => 'doc that i love',
                    'id_thesaurus' => 'DOC0',
                    'rule_zone' => '345',
                    'rule_label_field' => 't',
                    'rule_label_start_pos' => '1',
                    'rule_label_length' => '0']);
    $this->postDispatch('/cosmo/facets/add', ['libelle' => 'doc',
                                              'rule_zone' => '345',
                                              'rule_label_field' => '3',
                                              'rule_label_start_pos' => '1',
                                              'rule_label_length' => '0']);
    $this->assertEquals('DOC1',
                        Class_CodifThesaurus::findFirstBy(['libelle'=>'doc'])->getIdThesaurus());
  public function withExistingIdThesaurusDOCUNewIdThesaurusShouldBeDOC0() {
    $this->fixture('Class_CodifThesaurus',
                   ['libelle' => 'doc that i love',
                    'id_thesaurus' => 'DOCU',
                    'rule_zone' => '345',
                    'rule_label_field' => 't',
                    'rule_label_start_pos' => '1',
                    'rule_label_length' => '0']);
    $this->postDispatch('/cosmo/facets/add', ['libelle' => 'docu',
                                              'rule_zone' => '345',
                                              'rule_label_field' => '3',
                                              'rule_label_start_pos' => '1',
                                              'rule_label_length' => '0']);
    $this->assertEquals('DOC0',
                        Class_CodifThesaurus::findFirstBy(['libelle'=>'docu'])->getIdThesaurus());
  /** @test */
  public function withSpecialCharsNewIdThesaurusShouldBeFourLetters() {
    $this->postDispatch('/cosmo/facets/add', ['libelle' => 'Année top 5',
                                              'rule_zone' => '066',
                                              'rule_label_field' => '6',
                                              'rule_label_start_pos' => '1',
                                              'rule_label_length' => '0']);

    $this->assertEquals('ANNE',
                        Class_CodifThesaurus::findFirstBy(['libelle'=>'Année top 5'])->getIdThesaurus());
  }
}
class Cosmo_DynamicFacetsControllerEditTest extends CosmoControllerTestCase {
  public function setUp() {
    parent::setUp();
    $this->fixture('Class_CodifThesaurus',
                   ['id' => 3,
                    'libelle' => 'Document',
                    'libelle_facette' => 'Document',
                    'id_thesaurus' => 'DOCU',
                    'id_origine' => null,
                    'code' => 'DOCU',
                    'rule_zone' => '345',
                    'rule_label_field' => 't',
                    'rule_id_field' => '9']);
    $this->dispatch('/cosmo/facets/edit/id/3', true);
  }
  /** @test */
  public function titleShouldBePresent() {
    $this->assertXpathContentContains('//h1', 'Modifier une facette dynamique');
  }

  /** @test */
  public function labelShouldBeDocument() {
    $this->assertXpath('//input[@name="libelle"][@value="Document"]');
  }
  /** @test */
  public function zoneShouldBe345() {
    $this->assertXPath('//input[@name="rule_zone"][@value="345"]');
  }


  /** @test */
  public function labelFieldShouldBeT() {
    $this->assertXPath('//select[@name="rule_label_field"]//option[@value="t"][@selected]');
  }


  /** @test */
  public function idFieldShouldBe9() {
    $this->assertXPath('//select[@name="rule_id_field"]//option[@value="9"][@selected]');
  }
  /** @test */
  public function idThesaurusShouldBeDocu() {
    $this->assertXPath('//input[@name="id_thesaurus"][@value="DOCU"]');
  }

class Cosmo_DynamicFacetsControllerEditPostTest extends CosmoControllerTestCase {
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_CodifThesaurus',
                   ['id' => 3,
                    'libelle' => 'Document',
                    'libelle_facette' => 'Document',
                    'id_thesaurus' => 'DOCU',
                    'id_origine' => null,
                    'code' => 'DOCU',
                    'rule_zone' => '345',
                    'rule_label_field' => 't',
                    'rule_id_field' => '9',
                    'rule_label_start_pos' => '1',
                    'rule_label_length' => '0']);

    $this->postDispatch('/cosmo/facets/edit/id/3',
                        ['libelle' => 'Document',
                         'libelle_facette' => 'Document',
                         'rule_zone' => '609',
                         'rule_label_field' => 'a',
                         'rule_id_field' => '3',
                         'rule_label_start_pos' => '1',
                         'rule_label_length' => '0']);
  }


  /** @test */
  public function shouldRedirectToEdit() {
    $this->assertRedirectTo('/cosmo/facets/edit/id/3');
  }


  /** @test */
  public function shouldNotifySave() {
    $this->assertFlashMessengerContentContains('Facette dynamique "Document" sauvegardée');
  }


  /** @test */
  public function ruleZoneShouldBecome609() {
    $this->assertEquals('609', Class_CodifThesaurus::find(3)->getRuleZone());
  }
}