From 5d908557c14636ed8b01cd7c236e96d7af00a5e6 Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 23 Feb 2024 11:35:24 +0100 Subject: [PATCH] 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. --- test/phpunit/ModulesTest.php | 60 ++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index 0d36b498c91a6..2745b87529028 100644 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alexandre Janniaux + * Copyright (C) 2024 MDW * * 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 @@ -38,6 +39,8 @@ $conf->global->MAIN_DISABLE_ALL_MAILS = 1; +use PHPUnit\Framework\TestCase; + /** * Class for PHPUnit tests * @@ -45,45 +48,56 @@ * @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 List of module labels to test (class is mod) + */ + 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) + * * @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;