Skip to content

Commit

Permalink
Qual: Refactor ModulesInit test
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
mdeweerd committed Feb 23, 2024
1 parent 3e0b7f3 commit e41d058
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions test/phpunit/ModulesTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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
Expand Down Expand Up @@ -38,52 +39,65 @@
$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
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()
public function testModulesInit(string $modlabel)
{
global $conf,$user,$langs,$db;

$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;

$modulelist = array('Accounting','Adherent','Agenda','Api','Asset','Banque','Barcode','BlockedLog','Bom','Bookmark',
'Categorie','ClickToDial','Collab','Commande','Comptabilite','Contrat','Cron','DataPolicy','Dav','DebugBar','Deplacement','DocumentGeneration','Don','DynamicPrices',
'ECM','EmailCollector','EventOrganization','Expedition','ExpenseReport','Export','ExternalRss','ExternalSite',
'Facture','Fckeditor','Ficheinter','Fournisseur','FTP','GeoIPMaxmind','Gravatar','Holiday','HRM','Import','Incoterm','Intracommreport',
'KnowledgeManagement','Label','Ldap','Loan',
'Mailing','MailmanSpip','Margin','ModuleBuilder','Mrp','MultiCurrency',
'Notification','Oauth','OpenSurvey','Paybox','PaymentByBankTransfer','Paypal','Prelevement','Printing','Product','ProductBatch','Projet','Propale',
'ReceiptPrinter','Reception','Recruitment','Resource',
'Salaries','Service','SocialNetworks','Societe','Stock','Stripe','SupplierProposal','Syslog',
'TakePos','Tax','Ticket','User','Variants','WebServices','WebServicesClient','Website','Workflow','Workstation','Zapier');
foreach ($modulelist as $modlabel) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$modlabel.'.class.php';
$class = 'mod'.$modlabel;
$mod = new $class($db);
$this->nbLinesToShow = 0; // Only 3 lines of the log.

$result = $mod->remove();
$result = $mod->init();
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";
$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();
}
if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) {
$result = $mod->remove();
}

return 0;
Expand Down

0 comments on commit e41d058

Please sign in to comment.