Skip to content
Snippets Groups Projects
UsersControllerManagedLibrariesTest.php 5.95 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2024, 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 UsersControllerManagedLibrariesGuestTest extends AbstractControllerTestCase {

  public function setUp()
  {
    parent::setUp();
    $this->fixture(Class_Users::class, ['id' => 458,
                                        'prenom' => 'Mimi',
                                        'nom' => 'Mathy',
                                        'login' => 'mmathy',
                                        'mail'=> 'mmathy@gmail.com',
                                        'pseudo' => 'mimi',
                                        'password' => 'secret',
                                        'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE,
                                        'idabon' => '',
                                        'id_site' => '',
                                        'ordreabon' => 1,
                                        'date_debut' => '19-07-2009',
                                        'date_fin' => '19-07-2050',
                                        'telephone' => '',
                                        'mobile' => '',
                                        'adresse' => '',
                                        'code_postal' => '',
                                        'ville' => '',
                                        'subscription_type' => '',
                                        'last_login' => null,
                                        'civilite' => '']);

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


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


  /** @test */
  public function onLoadScriptShouldContainExpectedJS()
  {
    $this->assertXPathContentContains('//script', '$(function(){if ($(\'#role_level\').val() < 3) { $(\'#managed_libraries\').parent().parent().hide() } else { $(\'#managed_libraries\').parent().parent().show() }});');
  }


  /** @test */
  public function onChangeRoleLevelShouldContainExpectedJS()
  {
    $this->assertXPath('//select[@name="role_level"][@onchange="if (event.target.value < 3) { $(\'#managed_libraries\').parent().parent().hide() } else { $(\'#managed_libraries\').parent().parent().show() }"]');
  }
}




class UsersControllerManagedLibrariesPostGuestTest extends AbstractControllerTestCase {

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

    $this->fixture(Class_Bib::class,
                   ['id' => 100,
                    'libelle' => 'Poiter']);

    $this->postDispatch('/admin/users/add',
                        ['login' => 'mdavis',
                         'password' => 'tutu',
                         'nom' => 'Davis',
                         'prenom' => 'Miles',
                         'pseudo' => '',
                         'mail' => 'mdavis@free.fr',
                         'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE,
                         'id_site' => '100',
                         'managed_libraries' => '3;5;31',
                         'idabon' => '3444',
                         'ordreabon' => '',
                         'telephone' => '',
                         'adresse' => '',
                         'code_postal' => '',
                         'ville' => '',
                         'naissance' => '',
                         'mobile' => '',
                         'date_debut' => '',
                         'date_fin' => '',
                         'civilite' => 1,
                         'user_group_ids' => '']);
  }


  /** @test */
  public function mimiMathyManagedLibrariesShouldBeEmpty()
  {
    $this->assertEquals('', Class_Users::findFirstBy(['idabon' => '3444'])->getManagedLibraries());
  }
}




class UsersControllerManagedLibrariesPostAdminTest extends AbstractControllerTestCase {

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

    $this->fixture(Class_Bib::class,
                   ['id' => 100,
                    'libelle' => 'Poiter']);

    $this->postDispatch('/admin/users/add',
                        ['login' => 'mdavis',
                         'password' => 'tutu',
                         'nom' => 'Davis',
                         'prenom' => 'Miles',
                         'pseudo' => '',
                         'mail' => 'mdavis@free.fr',
                         'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_BIB,
                         'id_site' => '100',
                         'managed_libraries' => '3;5;31',
                         'idabon' => '3444',
                         'ordreabon' => '',
                         'telephone' => '',
                         'adresse' => '',
                         'code_postal' => '',
                         'ville' => '',
                         'naissance' => '',
                         'mobile' => '',
                         'date_debut' => '',
                         'date_fin' => '',
                         'civilite' => 1,
                         'user_group_ids' => '']);
  }


  /** @test */
  public function mimiMathyManagedLibrariesShouldBeEmpty()
  {
    $this->assertEquals('3;5;31', Class_Users::findFirstBy(['idabon' => '3444'])->getManagedLibraries());
  }
}