BuildDocTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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) {
  104. print __METHOD__." invoice module not enabled\n"; die(1);
  105. }
  106. if (! $conf->commande->enabled) {
  107. print __METHOD__." order module not enabled\n"; die(1);
  108. }
  109. if (! $conf->propal->enabled) {
  110. print __METHOD__." propal module not enabled\n"; die(1);
  111. }
  112. if (! $conf->projet->enabled) {
  113. print __METHOD__." project module not enabled\n"; die(1);
  114. }
  115. if (! $conf->expedition->enabled) {
  116. print __METHOD__." shipment module not enabled\n"; die(1);
  117. }
  118. if (! $conf->ficheinter->enabled) {
  119. print __METHOD__." intervention module not enabled\n"; die(1);
  120. }
  121. if (! $conf->expensereport->enabled) {
  122. print __METHOD__." expensereport module not enabled\n"; die(1);
  123. }
  124. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  125. print __METHOD__."\n";
  126. }
  127. /**
  128. * tearDownAfterClass
  129. *
  130. * @return void
  131. */
  132. public static function tearDownAfterClass()
  133. {
  134. global $conf,$user,$langs,$db;
  135. $db->rollback();
  136. print __METHOD__."\n";
  137. }
  138. /**
  139. * Init phpunit tests
  140. *
  141. * @return void
  142. */
  143. protected function setUp()
  144. {
  145. global $conf,$user,$langs,$db;
  146. $conf=$this->savconf;
  147. $user=$this->savuser;
  148. $langs=$this->savlangs;
  149. $db=$this->savdb;
  150. print __METHOD__."\n";
  151. }
  152. /**
  153. * End phpunit tests
  154. *
  155. * @return void
  156. */
  157. protected function tearDown()
  158. {
  159. print __METHOD__."\n";
  160. }
  161. /**
  162. * testFactureBuild
  163. *
  164. * @return int
  165. */
  166. public function testFactureBuild()
  167. {
  168. global $conf,$user,$langs,$db;
  169. $conf=$this->savconf;
  170. $user=$this->savuser;
  171. $langs=$this->savlangs;
  172. $db=$this->savdb;
  173. $conf->facture->dir_output.='/temp';
  174. $localobjectcom=new Commande($this->savdb);
  175. $localobjectcom->initAsSpecimen();
  176. $localobject=new Facture($this->savdb);
  177. $localobject->createFromOrder($localobjectcom, $user);
  178. $localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
  179. // Crabe (english)
  180. $localobject->model_pdf='crabe';
  181. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  182. $this->assertLessThan($result, 0);
  183. print __METHOD__." result=".$result."\n";
  184. // Crabe (japanese)
  185. $newlangs1=new Translate("", $conf);
  186. $newlangs1->setDefaultLang('ja_JP');
  187. $localobject->model_pdf='crabe';
  188. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs1);
  189. $this->assertLessThan($result, 0);
  190. print __METHOD__." result=".$result."\n";
  191. // Crabe (saudiarabia)
  192. $newlangs2a=new Translate("", $conf);
  193. $newlangs2a->setDefaultLang('sa_SA');
  194. $localobject->model_pdf='crabe';
  195. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs2a);
  196. $this->assertLessThan($result, 0);
  197. print __METHOD__." result=".$result."\n";
  198. // Crabe (english_saudiarabia)
  199. $newlangs2b=new Translate("", $conf);
  200. $newlangs2b->setDefaultLang('en_SA');
  201. $localobject->model_pdf='crabe';
  202. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs2b);
  203. $this->assertLessThan($result, 0);
  204. print __METHOD__." result=".$result."\n";
  205. // Crabe (greek)
  206. $newlangs3=new Translate("", $conf);
  207. $newlangs3->setDefaultLang('el_GR');
  208. $localobject->model_pdf='crabe';
  209. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs3);
  210. $this->assertLessThan($result, 0);
  211. print __METHOD__." result=".$result."\n";
  212. // Crabe (chinese)
  213. $newlangs4=new Translate("", $conf);
  214. $newlangs4->setDefaultLang('zh_CN');
  215. $localobject->model_pdf='crabe';
  216. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs4);
  217. $this->assertLessThan($result, 0);
  218. print __METHOD__." result=".$result."\n";
  219. // Crabe (russian)
  220. $newlangs5=new Translate("", $conf);
  221. $newlangs5->setDefaultLang('ru_RU');
  222. $localobject->model_pdf='crabe';
  223. $result = $localobject->generateDocument($localobject->model_pdf, $newlangs5);
  224. $this->assertLessThan($result, 0);
  225. print __METHOD__." result=".$result."\n";
  226. return 0;
  227. }
  228. /**
  229. * testFactureFournisseurBuild
  230. *
  231. * @return int
  232. */
  233. public function testFactureFournisseurBuild()
  234. {
  235. global $conf,$user,$langs,$db;
  236. $conf=$this->savconf;
  237. $user=$this->savuser;
  238. $langs=$this->savlangs;
  239. $db=$this->savdb;
  240. $conf->fournisseur->facture->dir_output.='/temp';
  241. $localobject=new FactureFournisseur($this->savdb);
  242. $localobject->initAsSpecimen();
  243. // Canelle
  244. $localobject->model_pdf='canelle';
  245. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  246. $this->assertLessThan($result, 0);
  247. print __METHOD__." result=".$result."\n";
  248. return 0;
  249. }
  250. /**
  251. * testCommandeBuild
  252. *
  253. * @return int
  254. */
  255. public function testCommandeBuild()
  256. {
  257. global $conf,$user,$langs,$db;
  258. $conf=$this->savconf;
  259. $user=$this->savuser;
  260. $langs=$this->savlangs;
  261. $db=$this->savdb;
  262. $conf->commande->dir_output.='/temp';
  263. $localobject=new Commande($this->savdb);
  264. $localobject->initAsSpecimen();
  265. // Einstein
  266. $localobject->model_pdf='einstein';
  267. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  268. $this->assertLessThan($result, 0);
  269. print __METHOD__." result=".$result."\n";
  270. return 0;
  271. }
  272. /**
  273. * testCommandeFournisseurBuild
  274. *
  275. * @return int
  276. */
  277. public function testCommandeFournisseurBuild()
  278. {
  279. global $conf,$user,$langs,$db;
  280. $conf=$this->savconf;
  281. $user=$this->savuser;
  282. $langs=$this->savlangs;
  283. $db=$this->savdb;
  284. $conf->fournisseur->commande->dir_output.='/temp';
  285. $localobject=new CommandeFournisseur($this->savdb);
  286. $localobject->initAsSpecimen();
  287. // Muscadet
  288. $localobject->model_pdf='muscadet';
  289. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  290. $this->assertLessThan($result, 0);
  291. print __METHOD__." result=".$result."\n";
  292. return 0;
  293. }
  294. /**
  295. * testPropalBuild
  296. *
  297. * @return int
  298. */
  299. public function testPropalBuild()
  300. {
  301. global $conf,$user,$langs,$db;
  302. $conf=$this->savconf;
  303. $user=$this->savuser;
  304. $langs=$this->savlangs;
  305. $db=$this->savdb;
  306. $conf->propal->dir_output.='/temp';
  307. $localobject=new Propal($this->savdb);
  308. $localobject->initAsSpecimen();
  309. // Azur
  310. $localobject->model_pdf='azur';
  311. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  312. $this->assertLessThan($result, 0);
  313. print __METHOD__." result=".$result."\n";
  314. return 0;
  315. }
  316. /**
  317. * testProjectBuild
  318. *
  319. * @return int
  320. */
  321. public function testProjectBuild()
  322. {
  323. global $conf,$user,$langs,$db;
  324. $conf=$this->savconf;
  325. $user=$this->savuser;
  326. $langs=$this->savlangs;
  327. $db=$this->savdb;
  328. $conf->projet->dir_output.='/temp';
  329. $localobject=new Project($this->savdb);
  330. $localobject->initAsSpecimen();
  331. // Baleine
  332. $localobject->model_pdf='baleine';
  333. $result = $localobject->generateDocument($localobject->model_pdf, $langs);
  334. $this->assertLessThan($result, 0);
  335. print __METHOD__." result=".$result."\n";
  336. return 0;
  337. }
  338. /**
  339. * testFichinterBuild
  340. *
  341. * @return int
  342. */
  343. public function testFichinterBuild()
  344. {
  345. global $conf,$user,$langs,$db;
  346. $conf=$this->savconf;
  347. $user=$this->savuser;
  348. $langs=$this->savlangs;
  349. $db=$this->savdb;
  350. $conf->ficheinter->dir_output.='/temp';
  351. $localobject=new Fichinter($this->savdb);
  352. $localobject->initAsSpecimen();
  353. // Soleil
  354. $localobject->model_pdf='soleil';
  355. $result=fichinter_create($db, $localobject, $localobject->model_pdf, $langs);
  356. $this->assertLessThan($result, 0);
  357. print __METHOD__." result=".$result."\n";
  358. return 0;
  359. }
  360. /**
  361. * testExpeditionBuild
  362. *
  363. * @return int
  364. */
  365. public function testExpeditionBuild()
  366. {
  367. global $conf,$user,$langs,$db;
  368. $conf=$this->savconf;
  369. $user=$this->savuser;
  370. $langs=$this->savlangs;
  371. $db=$this->savdb;
  372. $conf->expedition->dir_output.='/temp';
  373. $localobject=new Expedition($this->savdb);
  374. $localobject->initAsSpecimen();
  375. // Merou
  376. $localobject->model_pdf='merou';
  377. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  378. $this->assertLessThan($result, 0);
  379. print __METHOD__." result=".$result."\n";
  380. // Rouget
  381. $localobject->model_pdf='rouget';
  382. $result= $localobject->generateDocument($localobject->model_pdf, $langs);
  383. $this->assertLessThan($result, 0);
  384. print __METHOD__." result=".$result."\n";
  385. return 0;
  386. }
  387. }