BuildDocTest.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
  17. * or see http://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. 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. // Static methods
  96. public static function setUpBeforeClass()
  97. {
  98. global $conf,$user,$langs,$db;
  99. if (! $conf->facture->enabled) { print __METHOD__." invoice module not enabled\n"; die(); }
  100. if (! $conf->commande->enabled) { print __METHOD__." order module not enabled\n"; die(); }
  101. if (! $conf->propal->enabled) { print __METHOD__." propal module not enabled\n"; die(); }
  102. if (! $conf->projet->enabled) { print __METHOD__." project module not enabled\n"; die(); }
  103. if (! $conf->expedition->enabled) { print __METHOD__." shipment module not enabled\n"; die(); }
  104. if (! $conf->ficheinter->enabled) { print __METHOD__." intervention module not enabled\n"; die(); }
  105. if (! $conf->expensereport->enabled) { print __METHOD__." expensereport module not enabled\n"; die(); }
  106. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  107. print __METHOD__."\n";
  108. }
  109. // tear down after class
  110. public static function tearDownAfterClass()
  111. {
  112. global $conf,$user,$langs,$db;
  113. $db->rollback();
  114. print __METHOD__."\n";
  115. }
  116. /**
  117. * Init phpunit tests
  118. *
  119. * @return void
  120. */
  121. protected function setUp()
  122. {
  123. global $conf,$user,$langs,$db;
  124. $conf=$this->savconf;
  125. $user=$this->savuser;
  126. $langs=$this->savlangs;
  127. $db=$this->savdb;
  128. print __METHOD__."\n";
  129. }
  130. /**
  131. * End phpunit tests
  132. *
  133. * @return void
  134. */
  135. protected function tearDown()
  136. {
  137. print __METHOD__."\n";
  138. }
  139. /**
  140. * testFactureBuild
  141. *
  142. * @return int
  143. */
  144. public function testFactureBuild()
  145. {
  146. global $conf,$user,$langs,$db;
  147. $conf=$this->savconf;
  148. $user=$this->savuser;
  149. $langs=$this->savlangs;
  150. $db=$this->savdb;
  151. $conf->facture->dir_output.='/temp';
  152. $localobjectcom=new Commande($this->savdb);
  153. $localobjectcom->initAsSpecimen();
  154. $localobject=new Facture($this->savdb);
  155. $localobject->createFromOrder($localobjectcom, $user);
  156. $localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
  157. // Crabe (english)
  158. $localobject->modelpdf='crabe';
  159. $result = $localobject->generateDocument($localobject->modelpdf, $langs);
  160. $this->assertLessThan($result, 0);
  161. print __METHOD__." result=".$result."\n";
  162. // Crabe (japanese)
  163. $newlangs1=new Translate("",$conf);
  164. $newlangs1->setDefaultLang('ja_JP');
  165. $localobject->modelpdf='crabe';
  166. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs1);
  167. $this->assertLessThan($result, 0);
  168. print __METHOD__." result=".$result."\n";
  169. // Crabe (saudiarabia)
  170. $newlangs2a=new Translate("",$conf);
  171. $newlangs2a->setDefaultLang('sa_SA');
  172. $localobject->modelpdf='crabe';
  173. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2a);
  174. $this->assertLessThan($result, 0);
  175. print __METHOD__." result=".$result."\n";
  176. // Crabe (english_saudiarabia)
  177. $newlangs2b=new Translate("",$conf);
  178. $newlangs2b->setDefaultLang('en_SA');
  179. $localobject->modelpdf='crabe';
  180. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2b);
  181. $this->assertLessThan($result, 0);
  182. print __METHOD__." result=".$result."\n";
  183. // Crabe (greek)
  184. $newlangs3=new Translate("",$conf);
  185. $newlangs3->setDefaultLang('el_GR');
  186. $localobject->modelpdf='crabe';
  187. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs3);
  188. $this->assertLessThan($result, 0);
  189. print __METHOD__." result=".$result."\n";
  190. // Crabe (chinese)
  191. $newlangs4=new Translate("",$conf);
  192. $newlangs4->setDefaultLang('zh_CN');
  193. $localobject->modelpdf='crabe';
  194. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs4);
  195. $this->assertLessThan($result, 0);
  196. print __METHOD__." result=".$result."\n";
  197. // Crabe (russian)
  198. $newlangs5=new Translate("",$conf);
  199. $newlangs5->setDefaultLang('ru_RU');
  200. $localobject->modelpdf='crabe';
  201. $result = $localobject->generateDocument($localobject->modelpdf, $newlangs5);
  202. $this->assertLessThan($result, 0);
  203. print __METHOD__." result=".$result."\n";
  204. return 0;
  205. }
  206. /**
  207. * testFactureFournisseurBuild
  208. *
  209. * @return int
  210. */
  211. public function testFactureFournisseurBuild()
  212. {
  213. global $conf,$user,$langs,$db;
  214. $conf=$this->savconf;
  215. $user=$this->savuser;
  216. $langs=$this->savlangs;
  217. $db=$this->savdb;
  218. $conf->fournisseur->facture->dir_output.='/temp';
  219. $localobject=new FactureFournisseur($this->savdb);
  220. $localobject->initAsSpecimen();
  221. // Canelle
  222. $localobject->modelpdf='canelle';
  223. $result = $localobject->generateDocument($localobject->modelpdf, $langs);
  224. $this->assertLessThan($result, 0);
  225. print __METHOD__." result=".$result."\n";
  226. return 0;
  227. }
  228. /**
  229. * testCommandeBuild
  230. *
  231. * @return int
  232. */
  233. public function testCommandeBuild()
  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->commande->dir_output.='/temp';
  241. $localobject=new Commande($this->savdb);
  242. $localobject->initAsSpecimen();
  243. // Einstein
  244. $localobject->modelpdf='einstein';
  245. $result = $localobject->generateDocument($localobject->modelpdf, $langs);
  246. $this->assertLessThan($result, 0);
  247. print __METHOD__." result=".$result."\n";
  248. return 0;
  249. }
  250. /**
  251. * testCommandeFournisseurBuild
  252. *
  253. * @return int
  254. */
  255. public function testCommandeFournisseurBuild()
  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->fournisseur->commande->dir_output.='/temp';
  263. $localobject=new CommandeFournisseur($this->savdb);
  264. $localobject->initAsSpecimen();
  265. // Muscadet
  266. $localobject->modelpdf='muscadet';
  267. $result= $localobject->generateDocument($localobject->modelpdf, $langs);
  268. $this->assertLessThan($result, 0);
  269. print __METHOD__." result=".$result."\n";
  270. return 0;
  271. }
  272. /**
  273. * testPropalBuild
  274. *
  275. * @return int
  276. */
  277. public function testPropalBuild()
  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->propal->dir_output.='/temp';
  285. $localobject=new Propal($this->savdb);
  286. $localobject->initAsSpecimen();
  287. // Azur
  288. $localobject->modelpdf='azur';
  289. $result = $localobject->generateDocument($localobject->modelpdf, $langs);
  290. $this->assertLessThan($result, 0);
  291. print __METHOD__." result=".$result."\n";
  292. return 0;
  293. }
  294. /**
  295. * testProjectBuild
  296. *
  297. * @return int
  298. */
  299. public function testProjectBuild()
  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->projet->dir_output.='/temp';
  307. $localobject=new Project($this->savdb);
  308. $localobject->initAsSpecimen();
  309. // Baleine
  310. $localobject->modelpdf='baleine';
  311. $result = $localobject->generateDocument($localobject->modelpdf, $langs);
  312. $this->assertLessThan($result, 0);
  313. print __METHOD__." result=".$result."\n";
  314. return 0;
  315. }
  316. /**
  317. * testFichinterBuild
  318. *
  319. * @return int
  320. */
  321. public function testFichinterBuild()
  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->ficheinter->dir_output.='/temp';
  329. $localobject=new Fichinter($this->savdb);
  330. $localobject->initAsSpecimen();
  331. // Soleil
  332. $localobject->modelpdf='soleil';
  333. $result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs);
  334. $this->assertLessThan($result, 0);
  335. print __METHOD__." result=".$result."\n";
  336. return 0;
  337. }
  338. /**
  339. * testExpeditionBuild
  340. *
  341. * @return int
  342. */
  343. public function testExpeditionBuild()
  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->expedition->dir_output.='/temp';
  351. $localobject=new Expedition($this->savdb);
  352. $localobject->initAsSpecimen();
  353. // Merou
  354. $localobject->modelpdf='merou';
  355. $result= $localobject->generateDocument($localobject->modelpdf, $langs);
  356. $this->assertLessThan($result, 0);
  357. print __METHOD__." result=".$result."\n";
  358. // Rouget
  359. $localobject->modelpdf='rouget';
  360. $result= $localobject->generateDocument($localobject->modelpdf, $langs);
  361. $this->assertLessThan($result, 0);
  362. print __METHOD__." result=".$result."\n";
  363. return 0;
  364. }
  365. }