mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
* Fix: Correct CommonClassTest's constructor # Fix: Correct CommonClassTest's constructor Dataproviders did not work because of the issue with the constructor * Qual: Refactor module name list, add mapping to class name # Qual: Refactor module name list, add mapping to class name Based on ModuleTest and search for modules in the code, complete the list of modules and map to the class names. This will allow reuse in the ModuleTest. * Qual: Refactor ModulesInit test # Qual: Refactor ModulesInit test Use the updated common module mapping list, more complete than the original list. Also refactor the test to use a data provider. * Fix: valid module test must now use array_key_exists # Fix: valid module test must now use array_key_exists Because of the introduction of null key values, isset on the array no longer works, using array_key_exists to test if the modulename is valid. * fixup! Qual: Refactor module name list, add mapping to class name * Qual: Less verbosity for tests # Qual: Less verbosity for tests The verbosity on setup/teardown/... is not really usefull and makes the log less readable. Reducing the verbosity while allowing to set an environment variable PHPUNIT_DEBUG to enable it.
106 lines
3.0 KiB
PHP
106 lines
3.0 KiB
PHP
<?php
|
|
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
|
|
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
* or see https://www.gnu.org/
|
|
*/
|
|
|
|
/**
|
|
* \file test/phpunit/ModulesTest.php
|
|
* \ingroup test
|
|
* \brief PHPUnit test
|
|
* \remarks To run this script as CLI: phpunit filename.php
|
|
*/
|
|
|
|
global $conf,$user,$langs,$db;
|
|
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
|
|
//require_once 'PHPUnit/Autoload.php';
|
|
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
|
require_once dirname(__FILE__).'/CommonClassTest.class.php';
|
|
|
|
if (empty($user->id)) {
|
|
print "Load permissions for admin user nb 1\n";
|
|
$user->fetch(1);
|
|
$user->getrights();
|
|
}
|
|
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Class for PHPUnit tests
|
|
*
|
|
* @backupGlobals disabled
|
|
* @backupStaticAttributes enabled
|
|
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
|
*/
|
|
class ModulesTest extends CommonClassTest // TestCase //CommonClassTest
|
|
{
|
|
/**
|
|
* Return list of modules for which to test initialisation
|
|
*
|
|
* @return array<array{0:string}> List of module labels to test (class is mod<module_label>)
|
|
*/
|
|
public function moduleInitListProvider()
|
|
{
|
|
$full_list = self::VALID_MODULE_MAPPING;
|
|
$filtered_list = array_map(function ($value) {
|
|
return array($value);
|
|
}, array_filter($full_list, function ($value) {
|
|
return $value !== null;
|
|
}));
|
|
return $filtered_list;
|
|
}
|
|
|
|
/**
|
|
* testModulesInit
|
|
*
|
|
* @param string $modlabel Module label (class is mod<modlabel>)
|
|
*
|
|
* @return int
|
|
*
|
|
* @dataProvider moduleInitListProvider
|
|
*/
|
|
public function testModulesInit(string $modlabel)
|
|
{
|
|
global $conf,$user,$langs,$db;
|
|
|
|
$conf = $this->savconf;
|
|
$user = $this->savuser;
|
|
$langs = $this->savlangs;
|
|
$db = $this->savdb;
|
|
|
|
$this->nbLinesToShow = 0; // Only 3 lines of the log.
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$modlabel.'.class.php';
|
|
$class = 'mod'.$modlabel;
|
|
$mod = new $class($db);
|
|
|
|
$result = $mod->remove();
|
|
$result = $mod->init();
|
|
|
|
$this->assertLessThan($result, 0, $modlabel." ".$mod->error);
|
|
print __METHOD__." test remove/init for module ".$modlabel.", result=".$result."\n";
|
|
|
|
if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) {
|
|
$result = $mod->remove();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|