ModulesTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file test/phpunit/ModulesTest.php
  20. * \ingroup test
  21. * \brief PHPUnit test
  22. * \remarks To run this script as CLI: phpunit filename.php
  23. */
  24. global $conf,$user,$langs,$db;
  25. //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
  26. //require_once 'PHPUnit/Autoload.php';
  27. require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
  28. if (empty($user->id)) {
  29. print "Load permissions for admin user nb 1\n";
  30. $user->fetch(1);
  31. $user->getrights();
  32. }
  33. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  34. /**
  35. * Class for PHPUnit tests
  36. *
  37. * @backupGlobals disabled
  38. * @backupStaticAttributes enabled
  39. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  40. */
  41. class ModulesTest extends PHPUnit\Framework\TestCase
  42. {
  43. protected $savconf;
  44. protected $savuser;
  45. protected $savlangs;
  46. protected $savdb;
  47. /**
  48. * Constructor
  49. * We save global variables into local variables
  50. *
  51. * @return BuildDocTest
  52. */
  53. public function __construct()
  54. {
  55. parent::__construct();
  56. //$this->sharedFixture
  57. global $conf,$user,$langs,$db;
  58. $this->savconf=$conf;
  59. $this->savuser=$user;
  60. $this->savlangs=$langs;
  61. $this->savdb=$db;
  62. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  63. //print " - db ".$db->db;
  64. print "\n";
  65. }
  66. /**
  67. * setUpBeforeClass
  68. *
  69. * @return void
  70. */
  71. public static function setUpBeforeClass()
  72. {
  73. global $conf,$user,$langs,$db;
  74. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  75. print __METHOD__."\n";
  76. }
  77. /**
  78. * tearDownAfterClass
  79. *
  80. * @return void
  81. */
  82. public static function tearDownAfterClass()
  83. {
  84. global $conf,$user,$langs,$db;
  85. $db->rollback();
  86. print __METHOD__."\n";
  87. }
  88. /**
  89. * Init phpunit tests
  90. *
  91. * @return void
  92. */
  93. protected function setUp()
  94. {
  95. global $conf,$user,$langs,$db;
  96. $conf=$this->savconf;
  97. $user=$this->savuser;
  98. $langs=$this->savlangs;
  99. $db=$this->savdb;
  100. print __METHOD__."\n";
  101. }
  102. /**
  103. * End phpunit tests
  104. *
  105. * @return void
  106. */
  107. protected function tearDown()
  108. {
  109. print __METHOD__."\n";
  110. }
  111. /**
  112. * testModulesInit
  113. *
  114. * @return int
  115. */
  116. public function testModulesInit()
  117. {
  118. global $conf,$user,$langs,$db;
  119. $conf=$this->savconf;
  120. $user=$this->savuser;
  121. $langs=$this->savlangs;
  122. $db=$this->savdb;
  123. $modulelist=array('Accounting','Adherent','Agenda','Api','Asset','Banque','Barcode','BlockedLog','Bom','Bookmark',
  124. 'Categorie','ClickToDial','Collab','Commande','Comptabilite','Contrat','Cron','DataPolicy','Dav','DebugBar','Deplacement','DocumentGeneration','Don','DynamicPrices',
  125. 'ECM','EmailCollector','EventOrganization','Expedition','ExpenseReport','Export','ExternalRss','ExternalSite',
  126. 'Facture','Fckeditor','Ficheinter','Fournisseur','FTP','GeoIPMaxmind','Gravatar','Holiday','HRM','Import','Incoterm','Intracommreport',
  127. 'KnowledgeManagement','Label','Ldap','Loan',
  128. 'Mailing','MailmanSpip','Margin','ModuleBuilder','Mrp','MultiCurrency',
  129. 'Notification','Oauth','OpenSurvey','Paybox','PaymentByBankTransfer','Paypal','Prelevement','Printing','Product','ProductBatch','Projet','Propale',
  130. 'ReceiptPrinter','Reception','Recruitment','Resource',
  131. 'Salaries','Service','SocialNetworks','Societe','Stock','Stripe','SupplierProposal','Syslog',
  132. 'TakePos','Tax','Ticket','User','Variants','WebServices','WebServicesClient','Website','Workflow','Workstation','Zapier');
  133. foreach ($modulelist as $modlabel) {
  134. require_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$modlabel.'.class.php';
  135. $class='mod'.$modlabel;
  136. $mod=new $class($db);
  137. $result=$mod->remove();
  138. $result=$mod->init();
  139. $this->assertLessThan($result, 0, $modlabel);
  140. print __METHOD__." test remove/init for module ".$modlabel.", result=".$result."\n";
  141. if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) {
  142. $result=$mod->remove();
  143. }
  144. }
  145. return 0;
  146. }
  147. }