Skip to content
Snippets Groups Projects
UsergroupAgendaAdminTest.php 45.2 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2019, 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 UsergroupAgendaAdminIndexInvalidTest extends Admin_AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;

  public function setUp() {
    parent::setUp();
    ZendAfi_Auth::getInstance()
      ->logUser($this->fixture('Class_Users',
                               ['id' => 34,
                                'login' => 'adminportail',
                                'password' => 's3cr3t \o/',
                                'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL]));
  }


  /** @test */
  public function whenNotActivatedShouldRedirect() {
    Class_AdminVar::set('ENABLE_RENDEZ_VOUS', 0);
    $this->dispatch('/admin/usergroup-agenda');
    $this->assertRedirect();
  }


  /** @test */
  public function withoutPermissionShouldRedirect() {
    Class_AdminVar::set('ENABLE_RENDEZ_VOUS', 1);
    $this->dispatch('/admin/usergroup-agenda');
    $this->assertRedirect();
  }
}



abstract class UsergroupAgendaAdminModoPortailLoggedTestCase extends Admin_AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;

  public function setUp() {
    parent::setUp();
    Class_AdminVar::set('ENABLE_RENDEZ_VOUS', 1);

    $group = $this->fixture('Class_UserGroup_Agenda', ['id' => 4,
                                                       'libelle'=>"UtilisateursRendezvous"]);
    $group->addRight(Class_UserGroup::RIGHT_USER_RENDEZ_VOUS);

    $user = $this->fixture('Class_Users',
                           ['id' => 34,
                            'login' => 'adminportail',
                            'password' => 's3cr3t \o/',
                            'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL,
                            'user_groups' => [$group]]);

    ZendAfi_Auth::getInstance()->logUser($user);
  }
}



/** @see https://forge.afi-sa.net/issues/95499  */
class UsergroupAgendaAdminIndexWithoutCustomFieldsTest
  extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();
    $groupagenda = $this->fixture('Class_UserGroup_Agenda',
                                  ['id' => 5,
                                   'libelle' => 'MonAgenda',
                                   'model_class' => 'Class_RendezVous']);

    $this->onLoaderOfModel('Class_CustomField_Value');

    $this->dispatch('/admin/usergroup-agenda');
  }


  /** @test */
  public function shouldNotCallFindCustomFieldValues() {
    $this->assertFalse(Class_CustomField_Value::methodHasBeenCalled('findAllBy'));
  }
}




class UsergroupAgendaAdminIndexValidTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();
    $groupagenda = $this->fixture('Class_UserGroup_Agenda',
                                  ['id' => 5,
                                   'libelle' => 'MonAgenda',
                                   'model_class' => 'Class_RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 7,
                    'label' => 'Note',
                    'field_type' => Class_CustomField_Meta::TEXT_INPUT,
                    'indexable' => 1,
                    'priority' => 5,
                    'model' => 'UserGroup_Agenda']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 32,
                    'custom_field_id' => 7,
                    'value' => 'Ma petite Note',
                    'model_id' => 5
                   ]);

    $this->dispatch('/admin/usergroup-agenda');
  }


  /** @test */
  public function shouldNotRedirect() {
    $this->assertNotRedirect();
  }


  /** @test */
  public function addAgendaButtonShouldBePresent() {
    $this->assertXPathContentContains('//button[contains(@data-url, "/admin/usergroup-agenda/add")]',
                                      'Créer un agenda');
  }


  /** @test */
  public function haveButtonToutRDVShouldExist() {
    $this->assertXPathContentContains('//button[contains(@data-url, "/admin/usergroup-agenda/all")]',
                                      'Tous les rendez-vous');
  }


  /** @test */
  public function listAgendaShouldContainMonAgenda() {
    $this->assertXPathContentContains('//td', 'MonAgenda');
  }


  /** @test */
  public function listAgendaShouldContainMonAgendaEditLink() {
    $this->assertXPath('//a[contains(@href,"usergroup-agenda/edit/id/5")]');
  }


  /** @test */
  public function listAgendaShouldContainMonAgendaDeleteLink() {
    $this->assertXPath('//a[contains(@href,"usergroup-agenda/delete/id/5")]');
  }


  /** @test */
  public function listAgendaShouldNotContainUtilisateursRendezvousGroup() {
    $this->assertNotXpathContentContains('//td', 'UtilisateursRendezvous');
  }


  /** @test */
  public function listAgendaShouldContainsChampsPersonnalises() {
    $this->assertXPathContentContains('//th', 'Champs personnalisés');
  }


  /** @test */
  public function listAgendaShouldDisplayCustomMaPetiteNote() {
    $this->assertXPathContentContains('//td', 'Ma petite Note');
  }
}



class UsergroupAgendaAdminDeleteTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_UserGroup_Agenda', ['id' => 43,
                                              'model_class'=> 'Class_RendezVous',
                                              'libelle' => "MonSuperAgenda"]);

    $this->fixture('Class_RendezVous',
                   ['id' => 4,
                    'agenda' => Class_UserGroup_Agenda::find(43),
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 8,
                                                  'libelle' => 'Bellevue']),
                    'date' => '2019-03-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'with Arnaud']);

    $this->dispatch('/admin/usergroup-agenda/delete/id/43');
  }


  /** @test */
  public function agendaShouldBeDeleted() {
    $this->assertNull(Class_UserGroup_Agenda::find(43));
  }


  /** @test */
  public function rendezVousShouldBeDeleted() {
    $this->assertNull(Class_RendezVous::find(4));
  }
}




class UsergroupAgendaAdminAllTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_UserGroup_Agenda',
                   ['id' => 43,
                    'model_class'=> 'Class_RendezVous',
                    'libelle' => "MonSuperAgenda"]);

    $this->fixture('Class_RendezVous',
                   ['id' => 4,
                    'agenda' => Class_UserGroup_Agenda::find(43),
                    'group_id' => 43,
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 8,
                                                  'libelle' => 'Bellevue']),
                    'date' => '2019-03-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'with Arnaud']);


    $this->dispatch('/admin/usergroup-agenda/all');
  }

  protected function lastCallOnFindallByRendezvous(){
    Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
  }


  /** @test */
  public function searchAgendaLabelShouldBePresent() {
    $this->assertXPath('//input[@name="search_libelle"]');
  }


  /** @test */
  public function searchDateStartShouldBePresent() {
    $this->assertXPath('//input[@name="search_date_start"]');
  }


  /** @test */
  public function searchDateEndShouldBePresent() {
    $this->assertXPath('//input[@name="search_date_end"]');
  }


  /** @test */
  public function searchUserShouldBePresent() {
    $this->assertXPath('//input[@name="search_user"]');
  }


  /** @test */
  public function searchLocationShouldBePresent() {
    $this->assertXPath('//select[@name="search_location_id"]//option[@value="8"]');
  }


  /** @test */
  public function searchCommentShouldBePresent() {
    $this->assertXPath('//input[@name="search_comment"]');
  }


  /** @test */
  public function agendLabelShouldBeMonSuperAgenda() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', 'MonSuperAgenda');
  }


  /** @test */
  public function dateShouldBePresent() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', 'mar. 19 mars 2019');
  }


  /** @test */
  public function beginTimeShouldBePresent() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', '09h15');
  }


  /** @test */
  public function endTimeShouldBePresent() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', '10h30');
  }


  /** @test */
  public function locationShouldBePresent() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', 'Bellevue');
  }


  /** @test */
  public function editLinkShouldBePresent() {
    $this->assertXPath('//a[contains(@href, "/admin/rendez-vous/edit/group_id/43/id/4")]');
  }


  /** @test */
  public function duplicateLinkShouldBePresent() {
    $this->assertXPath('//a[contains(@href, "/admin/rendez-vous/duplicate/group_id/43/id/4")]');
  }


  /** @test */
  public function deleteLinkShouldBePresent() {
    $this->assertXPath('//a[contains(@href, "/admin/rendez-vous/delete/group_id/43/id/4")]');
  }
}



class UsergroupAgendaAdminAllSearchTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  protected $_users_params = [];

  public function setUp() {
    parent::setUp();
    $this->fixture('Class_UserGroup_Agenda', ['id' => 43,
                                       'model_class'=> 'Class_RendezVous',
                                       'libelle' => "MonSuperAgenda"]);

    $this->fixture('Class_UserGroup', ['id' => 43,
                                       'model_class'=> 'Class_RendezVous',
                                       'libelle' => "MonSuperAgenda"]);

    $this->fixture('Class_RendezVous',
                   ['id' => 4,
                    'agenda' => Class_UserGroup_Agenda::find(43),
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 8,
                                                  'libelle' => 'Bellevue']),
                    'date' => '2019-03-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'with Arnaud']);

    $this->onLoaderOfModel('Class_RendezVous')
         ->whenCalled('findAllBy')->answers([])
         ->whenCalled('countBy')->answers(0);

    $arcadia = $this->fixture('Class_Users',
                              ['id' => 999,
                               'login' => 'Arcadia',
                               'password' => '!Cosmos',
                               'user_groups' => [Class_UserGroup_Agenda::find(43)]]);

    $this->onLoaderOfModel('Class_UserGroup_Agenda');

    $this->fixture('Class_Lieu',
                   ['id' => 3,
                    'libelle' => 'Arcadia']);

    $this->onLoaderOfModel('Class_Users')
         ->whenCalled('findAllBy')
         ->willDo(function($params) use($arcadia)
                  {
                    $this->_users_params = $params;
                    return [ $arcadia ];
                  });

    Class_RendezVous_SearchCriteria_Date::setTimeSource(new TimeSourceForTest('2019-03-27 11:46:18'));
  }


  public function tearDown() {
    Class_RendezVous_SearchCriteria_Date::setTimeSource(null);
    parent::tearDown();
  }


  protected function dispatchWithQuery($params) {
    $this->dispatch('/admin/usergroup-agenda/all?' . http_build_query($params));
  }


  /** @test */
  public function datesFilterShouldDefaultToFromNowUntil3MonthsLater() {
    $this->dispatch('/admin/usergroup-agenda/all');
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('date >= "2019-03-27"', $params['where']);
    $this->assertContains('date <= "2019-06-27"', $params['where']);
  }


  /** @test */
  public function invalidDateStartShouldBeIgnored() {
    $this->dispatchWithQuery(['search_date_start' => 'anything']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertNotContains('date >=', $params['where']);
  }


  /** @test */
  public function validDateStartShouldBeApplied() {
    $this->dispatchWithQuery(['search_date_start' => '26/03/2019']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('date >= "2019-03-26"', $params['where']);
  }


  /** @test */
  public function invalidDateEndShouldBeIgnored() {
    $this->dispatchWithQuery(['search_date_end' => 'anything']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertNotContains('date <=', $params['where']);
  }


  /** @test */
  public function validDateEndShouldBeApplied() {
    $this->dispatchWithQuery(['search_date_end' => '26/03/2019']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('date <= "2019-03-26"', $params['where']);
  }


  /** @test */
  public function emptyDatesShouldBeKeptInParams() {
    $this->dispatchWithQuery(['search_date_end' => '', 'search_date_start' => '']);
    $this->assertXPath('//th//a[contains(@href, "search_date_start")][contains(@href, "search_date_end")]');
    $this->assertXPath('//input[@name="search_date_start"][@value=""]');
    $this->assertXPath('//input[@name="search_date_end"][@value=""]');
  }


  /** @test */
  public function userContentShouldFilterByArcadiaUserGroup() {
    $this->dispatchWithQuery(['search_user' => 'Arcadia']);
    $this->assertEquals([999], $this->_users_params['id_user']);
    $params = Class_UserGroup_Agenda::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertEquals('(id in (43))', $params['where']);
  }


  /** @test */
  public function invalidLocationIdShouldBeIgnored() {
    $this->dispatchWithQuery(['search_location_id' => 'should_ignore']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertFalse(array_key_exists('location_id', $params));
  }


  /** @test */
  public function locationIdShouldBeApplied() {
    $this->dispatchWithQuery(['search_location_id' => 3]);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertEquals(3, $params['location_id']);
  }


  /** @test */
  public function locationNoneShouldFilterAndShowNoLocationsDate() {
    $this->dispatchWithQuery(['search_location_id' => "none"]);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('location_id is null or location_id=0', $params['where']);
  }


  /** @test */
  public function commentShouldFilterOnCommentWords() {
    $this->dispatchWithQuery(['search_comment' => "nausicaa"]);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('comment like "%nausicaa%"', $params['where']);
  }


  /** @test */
  public function invalidCommentShouldBeFiltered() {
    $this->dispatchWithQuery(['search_comment' => '")); UNION SELECT ']);
    $params = Class_RendezVous::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('comment like "%UNION SELECT%"', $params['where']);
  }


  /** @test */
  public function withLibelleAgendaSuperShouldQueryOnLibelleLikeSuper() {
    $this->dispatchWithQuery(['search_libelle'=>'super']);
    $params = Class_UserGroup_Agenda::getFirstAttributeForLastCallOn('findAllBy');
    $this->assertContains('libelle like "%super%"',$params['where']);
  }
}



class UsergroupAgendaAdminAddActionTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();
    $this->dispatch('/admin/usergroup-agenda/add');
  }


  /** @test */
  public function labelShouldBePresent() {
    $this->assertXPath('//form//input[@type="text"][@name="libelle"]');
  }


  /** @test */
  public function usersComponentShouldBePresent() {
    $this->assertXPath('//script[contains(@src, "user_selection/user_selection.js")]');
    $this->assertXPath('//div[@id="user_selection_users"]');
    $this->assertXPathContentContains('//script', '$("#user_selection_users").user_selection(');
  }


  /** @test */
  public function currentUsersTableShouldBePresent() {
    $this->assertXPath('//table[@id="current_user_selection_users"]', $this->_response->getBody());
  }


  /** @test */
  public function currentUsersTableShouldContainsActionColumn() {
    $this->assertXPathContentContains('//table[@id="current_user_selection_users"]//thead//th',"Actions", $this->_response->getBody());
  }


  /** @test */
  public function currentUsersTableShouldContainAucunParticipant() {
    $this->assertXPathContentContains('//table[@id="current_user_selection_users"][contains(@data-emptymessage, "Aucun participant")]//td',
                                      "Aucun participant",
                                      $this->_response->getBody());
  }
}



class UsergroupAgendaAdminUserSelectActionTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_Users',
                   ['id' => 35,
                    'login' => 'padawan',
                    'id_site' => 4,
                    'idabon' => 1234,
                    'password' => 's3cr3t \o/',
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);

    $this->dispatch('/admin/usergroup-agenda/user-select');
  }


  /** @test */
  public function reviewCriteriaShouldNotBePresent() {
    $this->assertNotXPath('//select[@name="search_review"]');
  }


  /** @test */
  public function basketCriteriaShouldNotBePresent() {
    $this->assertNotXPath('//select[@name="search_basket"]');
  }


  /** @test */
  public function massDeleteButtonShouldNotBePresent() {
    $this->assertNotXPath('//button[contains(@onclick, "admin/users/mass-delete")]');
  }


  /** @test */
  public function useradminPortailShouldBePresent() {
    $this->assertXPathContentContains('//td','padawan');
  }


  /** @test */
  public function addLinkShouldBePresent() {
    $this->assertXPath('//a[contains(@data-userid, "35")][@data-username="padawan"]');
  }
}



class UsergroupAgendaAdminPostAddActionTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
  protected $_created_group;

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

    $this->fixture('Class_Users',
                   ['id' => 35,
                    'login' => 'padawan',
                    'id_site' => 4,
                    'idabon' => 1234,
                    'password' => 's3cr3t \o/',
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);

    $this->postDispatch('/admin/usergroup-agenda/add',
                        ['libelle' => '',
                         'users' => '999-35-888']);

    Class_UserGroup::resetCache();
    $this->_created_group = Class_UserGroup_Agenda::find(5);
  }


  /** @test */
  public function groupShouldBeCreated() {
    $this->assertNotNull($this->_created_group, $this->_response->getBody());
  }


  /** @test */
  public function padawanShouldBeInCreatedGroup() {
    $this->assertEquals('padawan', $this->_created_group->getUsers()[0]->getLogin());
  }


  /** @test */
  public function groupLabelShouldBePadawan() {
    $this->assertEquals('padawan', $this->_created_group->getLibelle());
  }
}



class UsergroupAgendaAdminEditActionTest
  extends UsergroupAgendaAdminModoPortailLoggedTestCase {

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

    $this->fixture('Class_Users',
                   ['id' => 35,
                    'login' => 'padawan',
                    'id_site' => 4,
                    'idabon' => 1234,
                    'password' => 's3cr3t \o/',
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);

    $this->fixture('Class_UserGroup_Agenda',
                   ['id'=> 45,
                    'libelle'=> 'MonAgenda',
                    'model_class' => 'Class_RendezVous',
                    'users' => [Class_Users::find(35)]]);

    $this->dispatch('/admin/usergroup-agenda/edit/id/45');
  }


  /** @test */
  public function titleShouldBeModifierLAgendaMonAgenda() {
    $this->assertXPathContentContains('//h1', 'Modifier l\'agenda "MonAgenda"');
  }


  /** @test */
  public function libelleValueShouldBeMonAgenda() {
    $this->assertXPath('//input[@name="libelle"][@value="MonAgenda"]');
  }


  /** @test */
  public function padawanShouldBeInCurrentUsersTable() {
    $this->assertXPathContentContains('//table[@id="current_user_selection_users"]//td',
                                      'padawan');
  }


  /** @test */
  public function linkToRemovePadawanFromCurrentUsersShouldBePresent() {
    $this->assertXPath('//div[@class="actions"]//a[@data-userid="35"]');
  }
}



class UsergroupAgendaAdminAllWithCustomFieldsTest
  extends UsergroupAgendaAdminModoPortailLoggedTestCase {

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

    $this->fixture('Class_Users',
                   ['id' => 35,
                    'login' => 'padawan',
                    'id_site' => 4,
                    'idabon' => 1234,
                    'password' => 's3cr3t \o/',
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);


    $this->fixture('Class_UserGroup',
                   ['id' => 43,
                    'model_class'=> 'Class_RendezVous',
                    'libelle' => "MonSuperAgenda",
                    'users' => [Class_Users::find(35)]]);

    $this->fixture('Class_UserGroup_Agenda',
                   ['id' => 43,
                    'model_class'=> 'Class_RendezVous',
                    'libelle' => "MonSuperAgenda",
                    'users' => [Class_Users::find(35)]]);

    $this->fixture('Class_RendezVous',
                   ['id' => 4,
                    'agenda' => Class_UserGroup::find(43),
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 8,
                                                  'libelle' => 'Bellevue']),
                    'date' => '2019-03-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'with Arnaud']);

    $this->fixture('Class_CustomField',
                   ['id' => 5,
                    'type' => Class_CustomField_Meta::TEXT_INPUT,
                    'label' => 'Secteur',
                    'model' => 'UserGroup_Agenda']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 12,
                    'model_id' => 43,
                    'custom_field_id' => 5,
                    'value' => 'Yonne Nord'
                   ]);

    $this->fixture('Class_CustomField',
                   ['id' => 7,
                    'priority' => 5,
                    'label' => 'Notes',
                    'field_type' => Class_CustomField_Meta::TEXT_INPUT,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 11,
                    'priority' => 5,
                    'label' => 'Public',
                    'field_type' => Class_CustomField_Meta::SELECT,
                    'options_list' => 'Adultes; Enfants; Adolescent; ',
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 12,
                    'priority' => 5,
                    'label' => 'CSP',
                    'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX,
                    'options_list' => 'Pro; Sans Emploi; Test; ',
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 10,
                    'priority' => 5,
                    'label' => 'Date suivi',
                    'field_type' => Class_CustomField_Meta::DATE,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 9,
                    'priority' => 5,
                    'label' => 'CheckList Préparation',
                    'field_type' => Class_CustomField_Meta::TEXT_AREA,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 8,
                    'priority' => 5,
                    'label' => 'Description Détaillée',
                    'field_type' => Class_CustomField_Meta::CKEDITOR,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 25,
                    'custom_field_id' => 7,
                    'model_id' => 4,
                    'value' => 'ma blue note jolie']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 26,
                    'custom_field_id' => 11,
                    'model_id' => 5,
                    'value' => 'Adultes']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 27,
                    'custom_field_id' => 12,
                    'model_id' => 4,
                    'value' => 'Pro']);

    Class_RendezVous::setTimeSource(new TimeSourceForTest('2019-01-01 11:46:18'));
    $this->dispatch('/admin/usergroup-agenda/all');
  }



  public function tearDown() {
    Class_RendezVous::setTimeSource(new TimeSourceForTest(null));
    parent::tearDown();
  }


  /** @test */
  public function inputSecteurShouldBePresentInSearch() {
    $this->assertXPath('//input[@name="search_field_5"]');
  }


  /** @test */
  public function buttonExporterShouldBePresent() {
    $this->assertXPathContentContains('//button[contains(@data-url, "/admin/usergroup-agenda/export")]',
                                      'Exporter cette liste');
  }


  /** @test */
  public function searchOnNotesShouldBeDisplayed() {
    $this->assertXPathContentContains('//label[@for="search_field_7"]','Notes',$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_7"]');
  }


  /** @test */
  public function searchForField8ShouldDisplayInputText() {
    $this->assertXPathContentContains('//label[@for="search_field_8"]','Description Détaillée',$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_8"][@type="text"]',$this->_response->getBody());
  }


  /** @test */
  public function searchForField9ShouldDisplayInputText() {
    $this->assertXPathContentContains('//label[@for="search_field_9"]','CheckList',$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_9"][@type="text"]',$this->_response->getBody());
  }


  /** @test */
  public function searchForDateField10ShouldDisplaytwoInputBox() {
    $this->assertXPathContentContains('//label[@for="search_field_10"]','Date suivi',$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_10_start"][@type="text"]',$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_10_end"][@type="text"]',$this->_response->getBody());
  }


  /** @test */
  public function searchForSelectField11ShouldDisplayCheckboxes() {
    $this->assertXPathContentContains('//label[@data-name="search_field_11[]"]','Public',$this->_response->getBody());
    $this->assertXPathCount('//input[@name="search_field_11[]"][@type="checkbox"]',3,$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_11[]"][@value="Adultes"]',$this->_response->getBody());
  }


  /** @test */
  public function searchForSelectField12ShouldDisplayCheckboxes() {
    $this->assertXPathContentContains('//label[@data-name="search_field_12[]"]','CSP',$this->_response->getBody());
    $this->assertXPathCount('//input[@name="search_field_12[]"][@type="checkbox"]',3,$this->_response->getBody());
    $this->assertXPath('//input[@name="search_field_12[]"][@value="Pro"]',$this->_response->getBody());
  }


  /** @test */
  public function searchResultsShouldDisplayColumnChampsPersonnalises() {
    $this->assertXPathContentContains('//th', 'Autres informations', $this->_response->getBody());
  }


  /** @test */
  public function searchResultsShouldDisplayColumnReferents() {
    $this->assertXPathContentContains('//th', 'Participants');
  }


  /** @test */
  public function shouldContainsUserName() {
    $this->assertXPathContentContains('//td', 'padawan');
  }


  /** @test */
  public function customFieldHeaderSecteurShouldBeDisplayed() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td', 'Secteur');
  }


  /** @test */
  public function customFieldYonneNordShouldBeDisplayed() {
    $this->assertXPathContentContains('//table[@id="rendez-vous"]//td','Yonne Nord');
  }
}




abstract class UsergroupAgendaAdminSearchCustomFieldsActionTestCase
  extends UsergroupAgendaAdminModoPortailLoggedTestCase {

  public function setUp() {
    parent::setUp();
    $this->fixture('Class_UserGroup_Agenda', ['id' => 43,
                                              'model_class'=> 'Class_RendezVous',
                                              'libelle' => "MonSuperAgenda"]);

    $this->fixture('Class_RendezVous',
                   ['id' => 4,
                    'agenda' => Class_UserGroup_Agenda::find(43),
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 8,
                                                  'libelle' => 'Bellevue']),
                    'date' => '2019-03-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'with Arnaud']);

    $this->fixture('Class_RendezVous',
                   ['id' => 5,
                    'agenda' => Class_UserGroup_Agenda::find(43),
                    'location' => $this->fixture('Class_Lieu',
                                                 ['id' => 12,
                                                  'libelle' => 'Bron']),
                    'date' => '2019-07-19',
                    'begin_time' => '09:15',
                    'end_time' => '10:30',
                    'comment' => 'test']);

    $this->onLoaderOfModel('Class_RendezVous');

    $this->fixture('Class_CustomField',
                   ['id' => 5,
                    'type' => Class_CustomField_Meta::TEXT_INPUT,
                    'label' => 'Secteur',
                    'model' => 'UserGroup_Agenda']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 12,
                    'model_id' => 43,
                    'custom_field_id' => 5,
                    'value' => 'Yonne Nord'
                   ]);

    $this->fixture('Class_CustomField_Meta',
                   ['id' => 1,
                    'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX,
                    'options_list' => 'fromage;dessert;l\'association',
                    'indexable' => 1,
                   ]);

    $this->fixture('Class_CustomField',
                   ['id' => 3,
                    'meta_id' => 1,
                    'model' => 'RendezVous'
                   ]);

    $this->fixture('Class_CustomField',
                   ['id' => 7,
                    'priority' => 5,
                    'field_type' => Class_CustomField_Meta::TEXT_INPUT,
                    'indexable' => 1,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField',
                   ['id' => 10,
                    'priority' => 5,
                    'field_type' => Class_CustomField_Meta::SELECT,
                    'options_list' => 'included; not included',
                    'indexable' => 1,
                    'model' => 'RendezVous']);

    $this->fixture('Class_CustomField_Meta',
                   ['id' => 2,
                    'field_type' => Class_CustomField_Meta::DATE,
                    'indexable' => 1,
                   ]);

    $this->fixture('Class_CustomField',
                   ['id' => 11,
                    'priority' => 5,
                    'meta_id' => 2,
                    'indexable' => 1,