Skip to content
Snippets Groups Projects
UsersControllerRolesTest.php 4.89 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2023, 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
 */


abstract class UsersControllerRolesTestCase
  extends Admin_AbstractControllerTestCase {

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

    $this->fixture(Class_Bib::class,
                   ['id' => 1,
                    'libelle' => 'Annecy']);
    $this->fixture(Class_Bib::class,
                   ['id' => 2,
                    'libelle' => 'Meythet']);

    $this->fixture(Class_Users::class,
                   ['id' => 10,
                    'idabon' => '65656',
                    'login' => 'bobo',
                    'password' => 'oo',
                    'mail' => 'bobo@bo.com',
                    'id_site' => 1,
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
                    'last_login' => 0]);
    $this->fixture(Class_Users::class,
                   ['id' => 20,
                    'idabon' => '656789',
                    'login' => 'tutu',
                    'password' => 'ru',
                    'mail' => 'tutu@ru.com',
                    'id_site' => 2,
                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
                    'last_login' => 0]);

    ZendAfi_Auth::getInstance()->logUser($this->_createUser());

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


  protected function _createUser() : ?Class_Users {
    return null;
  }
}




class UsersControllerRolesAdminBibTest
  extends UsersControllerRolesTestCase {

  protected function _createUser() : ?Class_Users {
    $admin_bib = $this->fixture(Class_Users::class,
                                ['id' => 1,
                                 'login' => 'toto',
                                 'password' => 'ro',
                                 'mail' => 'toto@ro.com',
                                 'id_site' => 1,
                                 'managed_libraries' => '1;2',
                                 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB,
                                 'last_login' => 0]);

    $user_group = $this->fixture(Class_UserGroup::class,
                                 ['id' => 28,
                                  'libelle' => 'Admin Bib',
                                  'rights' => [Class_UserGroup::RIGHT_USER_SIGB_USER_READ]]);

    $admin_bib->addUserGroup($user_group);

    return $admin_bib;
  }


  /** @test */
  public function pageShouldContainsH1_GestionDesUtilisateurs() {
    $this->assertXPathContentContains('//h1', 'Gestion des utilisateurs');
  }


  /** @test */
  public function inputBibliothequeShouldNotExist() {
    $this->assertNotXPath('//select[@id="search_id_site"]');
  }


  /** @test */
  public function usersTableShouldContainIdentifiantBobo() {
    $this->assertXPath('//table[@id="users_table"]/tbody/tr/td[text()="bobo"]');
  }


  /** @test */
  public function usersTableShouldNotContainIdentifiantTutu() {
    $this->assertNotXPath('//table[@id="users_table"]//td[text()="tutu"]');
  }
}




class UsersControllerRolesAdminPortailTest
  extends UsersControllerRolesTestCase {

  protected function _createUser() : ?Class_Users {
    return $this->fixture(Class_Users::class,
                          ['id' => 1,
                           'login' => 'toto',
                           'password' => 'ro',
                           'mail' => 'toto@ro.com',
                           'id_site' => 1,
                           'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL,
                           'last_login' => 0]);
  }


  /** @test */
  public function pageShouldContainsH1_GestionDesUtilisateurs() {
    $this->assertXPathContentContains('//h1', 'Gestion des utilisateurs');
  }


  /** @test */
  public function inputBibliothequeShouldExist() {
    $this->assertXPath('//select[@id="search_id_site"]');
  }


  /** @test */
  public function usersTableShouldContainIdentifiantBobo() {
    $this->assertXPath('//table[@id="users_table"]/tbody/tr/td[text()="bobo"]');
  }


  /** @test */
  public function usersTableShouldContainIdentifiantTutu() {
    $this->assertXPath('//table[@id="users_table"]/tbody/tr/td[text()="tutu"]');
  }
}