PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/phpunit/BuildDocTest.php

https://github.com/asterix14/dolibarr
PHP | 319 lines | 201 code | 52 blank | 66 comment | 7 complexity | 8b202d70dc11d15b36d09e6435098ba6 MD5 | raw file
Possible License(s): LGPL-2.0
  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 2 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, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. /**
  19. * \file test/phpunit/BuildDocTest.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. require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php';
  29. require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php';
  30. require_once dirname(__FILE__).'/../../htdocs/comm/propal/class/propal.class.php';
  31. require_once dirname(__FILE__).'/../../htdocs/fichinter/class/fichinter.class.php';
  32. require_once dirname(__FILE__).'/../../htdocs/expedition/class/expedition.class.php';
  33. require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php';
  34. require_once dirname(__FILE__).'/../../htdocs/projet/class/task.class.php';
  35. require_once dirname(__FILE__).'/../../htdocs/core/lib/pdf.lib.php';
  36. require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/doc/pdf_crabe.modules.php';
  37. require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/doc/pdf_oursin.modules.php';
  38. require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/pdf_edison.modules.php';
  39. require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/pdf_einstein.modules.php';
  40. require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/pdf_propale_azur.modules.php';
  41. require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/pdf_propale_jaune.modules.php';
  42. require_once dirname(__FILE__).'/../../htdocs/core/modules/project/pdf/pdf_baleine.modules.php';
  43. require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/pdf_soleil.modules.php';
  44. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/pdf/pdf_expedition_merou.modules.php';
  45. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/pdf/pdf_expedition_rouget.modules.php';
  46. // Mother classes of pdf generators
  47. require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/modules_facture.php';
  48. require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/modules_commande.php';
  49. require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/modules_propale.php';
  50. require_once dirname(__FILE__).'/../../htdocs/core/modules/project/modules_project.php';
  51. require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/modules_fichinter.php';
  52. require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/pdf/ModelePdfExpedition.class.php';
  53. if (empty($user->id))
  54. {
  55. print "Load permissions for admin user nb 1\n";
  56. $user->fetch(1);
  57. $user->getrights();
  58. }
  59. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  60. /**
  61. * Class for PHPUnit tests
  62. *
  63. * @backupGlobals disabled
  64. * @backupStaticAttributes enabled
  65. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  66. */
  67. class BuildDocTest extends PHPUnit_Framework_TestCase
  68. {
  69. protected $savconf;
  70. protected $savuser;
  71. protected $savlangs;
  72. protected $savdb;
  73. /**
  74. * Constructor
  75. * We save global variables into local variables
  76. *
  77. * @return BuildDocTest
  78. */
  79. function BuildDocTest()
  80. {
  81. //$this->sharedFixture
  82. global $conf,$user,$langs,$db;
  83. $this->savconf=$conf;
  84. $this->savuser=$user;
  85. $this->savlangs=$langs;
  86. $this->savdb=$db;
  87. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  88. //print " - db ".$db->db;
  89. print "\n";
  90. }
  91. // Static methods
  92. public static function setUpBeforeClass()
  93. {
  94. global $conf,$user,$langs,$db;
  95. if (! $conf->facture->enabled) { print __METHOD__." invoice module not enabled\n"; die(); }
  96. if (! $conf->commande->enabled) { print __METHOD__." order module not enabled\n"; die(); }
  97. if (! $conf->propale->enabled) { print __METHOD__." propal module not enabled\n"; die(); }
  98. if (! $conf->projet->enabled) { print __METHOD__." project module not enabled\n"; die(); }
  99. if (! $conf->expedition->enabled) { print __METHOD__." shipment module not enabled\n"; die(); }
  100. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  101. print __METHOD__."\n";
  102. }
  103. public static function tearDownAfterClass()
  104. {
  105. global $conf,$user,$langs,$db;
  106. $db->rollback();
  107. print __METHOD__."\n";
  108. }
  109. /**
  110. */
  111. protected function setUp()
  112. {
  113. global $conf,$user,$langs,$db;
  114. $conf=$this->savconf;
  115. $user=$this->savuser;
  116. $langs=$this->savlangs;
  117. $db=$this->savdb;
  118. print __METHOD__."\n";
  119. }
  120. /**
  121. */
  122. protected function tearDown()
  123. {
  124. print __METHOD__."\n";
  125. }
  126. /**
  127. */
  128. public function testFactureBuild()
  129. {
  130. global $conf,$user,$langs,$db;
  131. $conf=$this->savconf;
  132. $user=$this->savuser;
  133. $langs=$this->savlangs;
  134. $db=$this->savdb;
  135. $conf->facture->dir_output.='/temp';
  136. $localobject=new Facture($this->savdb);
  137. $localobject->initAsSpecimen();
  138. $localobject->socid=1;
  139. // Crabe
  140. $localobject->modelpdf='crabe';
  141. $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs);
  142. $this->assertLessThan($result, 0);
  143. print __METHOD__." result=".$result."\n";
  144. // Oursin
  145. $localobject->modelpdf='oursin';
  146. $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs);
  147. $this->assertLessThan($result, 0);
  148. print __METHOD__." result=".$result."\n";
  149. return 0;
  150. }
  151. /**
  152. */
  153. public function testCommandeBuild()
  154. {
  155. global $conf,$user,$langs,$db;
  156. $conf=$this->savconf;
  157. $user=$this->savuser;
  158. $langs=$this->savlangs;
  159. $db=$this->savdb;
  160. $conf->commande->dir_output.='/temp';
  161. $localobject=new Commande($this->savdb);
  162. $localobject->initAsSpecimen();
  163. $localobject->socid=1;
  164. // Einstein
  165. $localobject->modelpdf='einstein';
  166. $result=commande_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  167. $this->assertLessThan($result, 0);
  168. print __METHOD__." result=".$result."\n";
  169. // Edison
  170. $localobject->modelpdf='edison';
  171. $result=commande_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  172. $this->assertLessThan($result, 0);
  173. print __METHOD__." result=".$result."\n";
  174. return 0;
  175. }
  176. /**
  177. */
  178. public function testPropalBuild()
  179. {
  180. global $conf,$user,$langs,$db;
  181. $conf=$this->savconf;
  182. $user=$this->savuser;
  183. $langs=$this->savlangs;
  184. $db=$this->savdb;
  185. $conf->propale->dir_output.='/temp';
  186. $localobject=new Propal($this->savdb);
  187. $localobject->initAsSpecimen();
  188. $localobject->socid=1;
  189. // Einstein
  190. $localobject->modelpdf='azur';
  191. $result=propale_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  192. $this->assertLessThan($result, 0);
  193. print __METHOD__." result=".$result."\n";
  194. // Edison
  195. $localobject->modelpdf='jaune';
  196. $result=propale_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  197. $this->assertLessThan($result, 0);
  198. print __METHOD__." result=".$result."\n";
  199. return 0;
  200. }
  201. /**
  202. */
  203. public function testProjectBuild()
  204. {
  205. global $conf,$user,$langs,$db;
  206. $conf=$this->savconf;
  207. $user=$this->savuser;
  208. $langs=$this->savlangs;
  209. $db=$this->savdb;
  210. $conf->project->dir_output.='/temp';
  211. $localobject=new Project($this->savdb);
  212. $localobject->initAsSpecimen();
  213. $localobject->socid=1;
  214. // Soleil
  215. $localobject->modelpdf='baleine';
  216. $result=project_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  217. $this->assertLessThan($result, 0);
  218. print __METHOD__." result=".$result."\n";
  219. return 0;
  220. }
  221. /**
  222. */
  223. public function testFichinterBuild()
  224. {
  225. global $conf,$user,$langs,$db;
  226. $conf=$this->savconf;
  227. $user=$this->savuser;
  228. $langs=$this->savlangs;
  229. $db=$this->savdb;
  230. $conf->fichinter->dir_output.='/temp';
  231. $localobject=new Fichinter($this->savdb);
  232. $localobject->initAsSpecimen();
  233. $localobject->socid=1;
  234. // Soleil
  235. $localobject->modelpdf='soleil';
  236. $result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs);
  237. $this->assertLessThan($result, 0);
  238. print __METHOD__." result=".$result."\n";
  239. return 0;
  240. }
  241. /**
  242. */
  243. public function testExpeditionBuild()
  244. {
  245. global $conf,$user,$langs,$db;
  246. $conf=$this->savconf;
  247. $user=$this->savuser;
  248. $langs=$this->savlangs;
  249. $db=$this->savdb;
  250. $conf->expedition->dir_output.='/temp';
  251. $localobject=new Expedition($this->savdb);
  252. $localobject->initAsSpecimen();
  253. $localobject->socid=1;
  254. // Soleil
  255. $localobject->modelpdf='merou';
  256. $result=expedition_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  257. $this->assertLessThan($result, 0);
  258. print __METHOD__." result=".$result."\n";
  259. // Soleil
  260. $localobject->modelpdf='rouget';
  261. $result=expedition_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
  262. $this->assertLessThan($result, 0);
  263. print __METHOD__." result=".$result."\n";
  264. return 0;
  265. }
  266. }
  267. ?>