BuildDocTest.php 14 KB

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