BuildDocTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file test/phpunit/BuildDocTest.php
  22. * \ingroup test
  23. * \brief PHPUnit test
  24. * \remarks To run this script as CLI: phpunit filename.php
  25. */
  26. global $conf,$user,$langs,$db;
  27. //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
  28. //require_once 'PHPUnit/Autoload.php';
  29. require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
  30. require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php';
  31. require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.facture.class.php';
  32. require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php';
  33. require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.commande.class.php';
  34. require_once dirname(__FILE__).'/../../htdocs/comm/propal/class/propal.class.php';
  35. require_once dirname(__FILE__).'/../../htdocs/fichinter/class/fichinter.class.php';
  36. require_once dirname(__FILE__).'/../../htdocs/expedition/class/expedition.class.php';
  37. require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php';
  38. require_once dirname(__FILE__).'/../../htdocs/projet/class/task.class.php';
  39. require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.product.class.php';
  40. require_once dirname(__FILE__).'/../../htdocs/core/lib/pdf.lib.php';
  41. require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/doc/pdf_crabe.modules.php';
  42. require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/doc/pdf_azur.modules.php';
  43. require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/doc/pdf_einstein.modules.php';
  44. require_once dirname(__FILE__).'/../../htdocs/core/modules/project/doc/pdf_baleine.modules.php';
  45. require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php';
  46. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_merou.modules.php';
  47. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_rouget.modules.php';
  48. // Mother classes of pdf generators
  49. require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/modules_facture.php';
  50. require_once dirname(__FILE__).'/../../htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php';
  51. require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/modules_commande.php';
  52. require_once dirname(__FILE__).'/../../htdocs/core/modules/supplier_order/modules_commandefournisseur.php';
  53. require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/modules_propale.php';
  54. require_once dirname(__FILE__).'/../../htdocs/core/modules/project/modules_project.php';
  55. require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/modules_fichinter.php';
  56. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/modules_expedition.php';
  57. require_once dirname(__FILE__).'/../../htdocs/core/modules/modExpenseReport.class.php';
  58. if (empty($user->id)) {
  59. print "Load permissions for admin user nb 1\n";
  60. $user->fetch(1);
  61. $user->getrights();
  62. }
  63. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  64. /**
  65. * Class for PHPUnit tests
  66. *
  67. * @backupGlobals disabled
  68. * @backupStaticAttributes enabled
  69. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  70. */
  71. class BuildDocTest extends PHPUnit\Framework\TestCase
  72. {
  73. protected $savconf;
  74. protected $savuser;
  75. protected $savlangs;
  76. protected $savdb;
  77. /**
  78. * Constructor
  79. * We save global variables into local variables
  80. *
  81. * @param string $name Name
  82. * @return BuildDocTest
  83. */
  84. public function __construct($name = '')
  85. {
  86. parent::__construct($name);
  87. //$this->sharedFixture
  88. global $conf,$user,$langs,$db;
  89. $this->savconf=$conf;
  90. $this->savuser=$user;
  91. $this->savlangs=$langs;
  92. $this->savdb=$db;
  93. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  94. //print " - db ".$db->db;
  95. print "\n";
  96. }
  97. /**
  98. * setUpBeforeClass
  99. *
  100. * @return void
  101. */
  102. public static function setUpBeforeClass(): void
  103. {
  104. global $conf,$user,$langs,$db;
  105. if (!isModEnabled('facture')) {
  106. print __METHOD__." invoice module not enabled\n"; die(1);
  107. }
  108. if (!isModEnabled('commande')) {
  109. print __METHOD__." order module not enabled\n"; die(1);
  110. }
  111. if (!isModEnabled('propal')) {
  112. print __METHOD__." propal module not enabled\n"; die(1);
  113. }
  114. if (!isModEnabled('projet')) {
  115. print __METHOD__." project module not enabled\n"; die(1);
  116. }
  117. if (!isModEnabled('expedition')) {
  118. print __METHOD__." shipment module not enabled\n"; die(1);
  119. }
  120. if (!isModEnabled('ficheinter')) {
  121. print __METHOD__." intervention module not enabled\n"; die(1);
  122. }
  123. if (!isModEnabled('expensereport')) {
  124. print __METHOD__." expensereport module not enabled\n"; die(1);
  125. }
  126. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  127. print __METHOD__."\n";
  128. }
  129. /**
  130. * tearDownAfterClass
  131. *
  132. * @return void
  133. */
  134. public static function tearDownAfterClass(): void
  135. {
  136. global $conf,$user,$langs,$db;
  137. $db->rollback();
  138. print __METHOD__."\n";
  139. }
  140. /**
  141. * Init phpunit tests
  142. *
  143. * @return void
  144. */
  145. protected function setUp(): void
  146. {
  147. global $conf,$user,$langs,$db;
  148. $conf=$this->savconf;
  149. $user=$this->savuser;
  150. $langs=$this->savlangs;
  151. $db=$this->savdb;
  152. print __METHOD__."\n";
  153. }
  154. /**
  155. * End phpunit tests
  156. *
  157. * @return void
  158. */
  159. protected function tearDown(): void
  160. {
  161. print __METHOD__."\n";
  162. }
  163. /**
  164. * testFactureBuild
  165. *
  166. * @return int
  167. */
  168. public function testFactureBuild()
  169. {
  170. global $conf,$user,$langs,$db;
  171. $conf=$this->savconf;
  172. $user=$this->savuser;
  173. $langs=$this->savlangs;
  174. $db=$this->savdb;
  175. $conf->facture->dir_output.='/temp';
  176. $localobjectcom=new Commande($db);
  177. $localobjectcom->initAsSpecimen();
  178. $localobject=new Facture($db);
  179. $localobject->createFromOrder($localobjectcom, $user);
  180. $localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
  181. // Crabe (english)
  182. $localobject->model_pdf='crabe';
  183. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  184. $this->assertLessThan($result, 0);
  185. print __METHOD__." result=".$result."\n";
  186. // Crabe (japanese)
  187. $newlangs1=new Translate("", $conf);
  188. $newlangs1->setDefaultLang('ja_JP');
  189. $localobject->model_pdf='crabe';
  190. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs1);
  191. $this->assertLessThan($result, 0);
  192. print __METHOD__." result=".$result."\n";
  193. // Crabe (saudiarabia)
  194. $newlangs2a=new Translate("", $conf);
  195. $newlangs2a->setDefaultLang('sa_SA');
  196. $localobject->model_pdf='crabe';
  197. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs2a);
  198. $this->assertLessThan($result, 0);
  199. print __METHOD__." result=".$result."\n";
  200. // Crabe (english_saudiarabia)
  201. $newlangs2b=new Translate("", $conf);
  202. $newlangs2b->setDefaultLang('en_SA');
  203. $localobject->model_pdf='crabe';
  204. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs2b);
  205. $this->assertLessThan($result, 0);
  206. print __METHOD__." result=".$result."\n";
  207. // Crabe (greek)
  208. $newlangs3=new Translate("", $conf);
  209. $newlangs3->setDefaultLang('el_GR');
  210. $localobject->model_pdf='crabe';
  211. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs3);
  212. $this->assertLessThan($result, 0);
  213. print __METHOD__." result=".$result."\n";
  214. // Crabe (chinese)
  215. $newlangs4=new Translate("", $conf);
  216. $newlangs4->setDefaultLang('zh_CN');
  217. $localobject->model_pdf='crabe';
  218. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs4);
  219. $this->assertLessThan($result, 0);
  220. print __METHOD__." result=".$result."\n";
  221. // Crabe (russian)
  222. $newlangs5=new Translate("", $conf);
  223. $newlangs5->setDefaultLang('ru_RU');
  224. $localobject->model_pdf='crabe';
  225. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs5);
  226. $this->assertLessThan($result, 0);
  227. print __METHOD__." result=".$result."\n";
  228. return 0;
  229. }
  230. /**
  231. * testFactureFournisseurBuild
  232. *
  233. * @return int
  234. */
  235. public function testFactureFournisseurBuild()
  236. {
  237. global $conf,$user,$langs,$db;
  238. $conf=$this->savconf;
  239. $user=$this->savuser;
  240. $langs=$this->savlangs;
  241. $db=$this->savdb;
  242. $conf->fournisseur->facture->dir_output.='/temp';
  243. $localobject=new FactureFournisseur($db);
  244. $localobject->initAsSpecimen();
  245. // Canelle
  246. $localobject->model_pdf='canelle';
  247. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  248. $this->assertLessThan($result, 0);
  249. print __METHOD__." result=".$result."\n";
  250. return 0;
  251. }
  252. /**
  253. * testCommandeBuild
  254. *
  255. * @return int
  256. */
  257. public function testCommandeBuild()
  258. {
  259. global $conf,$user,$langs,$db;
  260. $conf=$this->savconf;
  261. $user=$this->savuser;
  262. $langs=$this->savlangs;
  263. $db=$this->savdb;
  264. $conf->commande->dir_output.='/temp';
  265. $localobject=new Commande($db);
  266. $localobject->initAsSpecimen();
  267. // Einstein
  268. $localobject->model_pdf='einstein';
  269. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  270. $this->assertLessThan($result, 0);
  271. print __METHOD__." result=".$result."\n";
  272. return 0;
  273. }
  274. /**
  275. * testCommandeFournisseurBuild
  276. *
  277. * @return int
  278. */
  279. public function testCommandeFournisseurBuild()
  280. {
  281. global $conf,$user,$langs,$db;
  282. $conf=$this->savconf;
  283. $user=$this->savuser;
  284. $langs=$this->savlangs;
  285. $db=$this->savdb;
  286. $conf->fournisseur->commande->dir_output.='/temp';
  287. $localobject=new CommandeFournisseur($db);
  288. $localobject->initAsSpecimen();
  289. // Muscadet
  290. $localobject->model_pdf='muscadet';
  291. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  292. $this->assertLessThan($result, 0);
  293. print __METHOD__." result=".$result."\n";
  294. return 0;
  295. }
  296. /**
  297. * testPropalBuild
  298. *
  299. * @return int
  300. */
  301. public function testPropalBuild()
  302. {
  303. global $conf,$user,$langs,$db;
  304. $conf=$this->savconf;
  305. $user=$this->savuser;
  306. $langs=$this->savlangs;
  307. $db=$this->savdb;
  308. $conf->propal->dir_output.='/temp';
  309. $localobject=new Propal($db);
  310. $localobject->initAsSpecimen();
  311. // Azur
  312. $localobject->model_pdf='azur';
  313. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  314. $this->assertLessThan($result, 0);
  315. print __METHOD__." result=".$result."\n";
  316. return 0;
  317. }
  318. /**
  319. * testProjectBuild
  320. *
  321. * @return int
  322. */
  323. public function testProjectBuild()
  324. {
  325. global $conf,$user,$langs,$db;
  326. $conf=$this->savconf;
  327. $user=$this->savuser;
  328. $langs=$this->savlangs;
  329. $db=$this->savdb;
  330. $conf->project->dir_output.='/temp';
  331. $localobject=new Project($db);
  332. $localobject->initAsSpecimen();
  333. // Baleine
  334. $localobject->model_pdf='baleine';
  335. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  336. $this->assertLessThan($result, 0);
  337. print __METHOD__." result=".$result."\n";
  338. return 0;
  339. }
  340. /**
  341. * testFichinterBuild
  342. *
  343. * @return int
  344. */
  345. public function testFichinterBuild()
  346. {
  347. global $conf,$user,$langs,$db;
  348. $conf=$this->savconf;
  349. $user=$this->savuser;
  350. $langs=$this->savlangs;
  351. $db=$this->savdb;
  352. $conf->ficheinter->dir_output.='/temp';
  353. $localobject=new Fichinter($db);
  354. $localobject->initAsSpecimen();
  355. // Soleil
  356. $localobject->model_pdf='soleil';
  357. $result=fichinter_create($db, $localobject, $localobject->model_pdf, $langs);
  358. $this->assertLessThan($result, 0);
  359. print __METHOD__." result=".$result."\n";
  360. return 0;
  361. }
  362. /**
  363. * testExpeditionBuild
  364. *
  365. * @return int
  366. */
  367. public function testExpeditionBuild()
  368. {
  369. global $conf,$user,$langs,$db;
  370. $conf=$this->savconf;
  371. $user=$this->savuser;
  372. $langs=$this->savlangs;
  373. $db=$this->savdb;
  374. $conf->expedition->dir_output.='/temp';
  375. $localobject=new Expedition($db);
  376. $localobject->initAsSpecimen();
  377. // Merou
  378. $localobject->model_pdf='merou';
  379. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  380. $this->assertLessThan($result, 0);
  381. print __METHOD__." result=".$result."\n";
  382. // Rouget
  383. $localobject->model_pdf='rouget';
  384. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  385. $this->assertLessThan($result, 0);
  386. print __METHOD__." result=".$result."\n";
  387. return 0;
  388. }
  389. }