PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/test/phpunit/CommandeTest.php

https://github.com/asterix14/dolibarr
PHP | 273 lines | 146 code | 34 blank | 93 comment | 2 complexity | e8a4d83aa2f875781b97fd0a801bd668 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/CommandeTest.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/commande/class/commande.class.php';
  29. if (empty($user->id))
  30. {
  31. print "Load permissions for admin user nb 1\n";
  32. $user->fetch(1);
  33. $user->getrights();
  34. }
  35. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  36. /**
  37. * Class for PHPUnit tests
  38. *
  39. * @backupGlobals disabled
  40. * @backupStaticAttributes enabled
  41. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  42. */
  43. class CommandeTest extends PHPUnit_Framework_TestCase
  44. {
  45. protected $savconf;
  46. protected $savuser;
  47. protected $savlangs;
  48. protected $savdb;
  49. /**
  50. * Constructor
  51. * We save global variables into local variables
  52. *
  53. * @return CommandeTest
  54. */
  55. function CommandeTest()
  56. {
  57. //$this->sharedFixture
  58. global $conf,$user,$langs,$db;
  59. $this->savconf=$conf;
  60. $this->savuser=$user;
  61. $this->savlangs=$langs;
  62. $this->savdb=$db;
  63. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  64. //print " - db ".$db->db;
  65. print "\n";
  66. }
  67. // Static methods
  68. public static function setUpBeforeClass()
  69. {
  70. global $conf,$user,$langs,$db;
  71. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  72. print __METHOD__."\n";
  73. }
  74. public static function tearDownAfterClass()
  75. {
  76. global $conf,$user,$langs,$db;
  77. $db->rollback();
  78. print __METHOD__."\n";
  79. }
  80. /**
  81. */
  82. protected function setUp()
  83. {
  84. global $conf,$user,$langs,$db;
  85. $conf=$this->savconf;
  86. $user=$this->savuser;
  87. $langs=$this->savlangs;
  88. $db=$this->savdb;
  89. print __METHOD__."\n";
  90. //print $db->getVersion()."\n";
  91. }
  92. /**
  93. */
  94. protected function tearDown()
  95. {
  96. print __METHOD__."\n";
  97. }
  98. /**
  99. */
  100. public function testCommandeCreate()
  101. {
  102. global $conf,$user,$langs,$db;
  103. $conf=$this->savconf;
  104. $user=$this->savuser;
  105. $langs=$this->savlangs;
  106. $db=$this->savdb;
  107. $localobject=new Commande($this->savdb);
  108. $localobject->initAsSpecimen();
  109. $result=$localobject->create($user);
  110. $this->assertLessThan($result, 0);
  111. print __METHOD__." result=".$result."\n";
  112. return $result;
  113. }
  114. /**
  115. * @depends testCommandeCreate
  116. * The depends says test is run only if previous is ok
  117. */
  118. public function testCommandeFetch($id)
  119. {
  120. global $conf,$user,$langs,$db;
  121. $conf=$this->savconf;
  122. $user=$this->savuser;
  123. $langs=$this->savlangs;
  124. $db=$this->savdb;
  125. $localobject=new Commande($this->savdb);
  126. $result=$localobject->fetch($id);
  127. $this->assertLessThan($result, 0);
  128. print __METHOD__." id=".$id." result=".$result."\n";
  129. return $localobject;
  130. }
  131. /**
  132. * @depends testCommandeFetch
  133. * The depends says test is run only if previous is ok
  134. */
  135. /* public function testCommandeUpdate($localobject)
  136. {
  137. global $conf,$user,$langs,$db;
  138. $conf=$this->savconf;
  139. $user=$this->savuser;
  140. $langs=$this->savlangs;
  141. $db=$this->savdb;
  142. $localobject->note='New note after update';
  143. $result=$localobject->update($user);
  144. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  145. $this->assertLessThan($result, 0);
  146. return $localobject->id;
  147. }
  148. */
  149. /**
  150. * @depends testCommandeFetch
  151. * The depends says test is run only if previous is ok
  152. */
  153. public function testCommandeValid($localobject)
  154. {
  155. global $conf,$user,$langs,$db;
  156. $conf=$this->savconf;
  157. $user=$this->savuser;
  158. $langs=$this->savlangs;
  159. $db=$this->savdb;
  160. $result=$localobject->valid($user);
  161. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  162. $this->assertLessThan($result, 0);
  163. return $localobject;
  164. }
  165. /**
  166. * @depends testCommandeValid
  167. * The depends says test is run only if previous is ok
  168. */
  169. public function testCommandeCancel($localobject)
  170. {
  171. global $conf,$user,$langs,$db;
  172. $conf=$this->savconf;
  173. $user=$this->savuser;
  174. $langs=$this->savlangs;
  175. $db=$this->savdb;
  176. $result=$localobject->cancel($user);
  177. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  178. $this->assertLessThan($result, 0);
  179. return $localobject;
  180. }
  181. /**
  182. * @depends testCommandeCancel
  183. * The depends says test is run only if previous is ok
  184. */
  185. public function testCommandeOther($localobject)
  186. {
  187. global $conf,$user,$langs,$db;
  188. $conf=$this->savconf;
  189. $user=$this->savuser;
  190. $langs=$this->savlangs;
  191. $db=$this->savdb;
  192. /*$result=$localobject->setstatus(0);
  193. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  194. $this->assertLessThan($result, 0);
  195. */
  196. $localobject->info($localobject->id);
  197. print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
  198. $this->assertNotEquals($localobject->date_creation, '');
  199. return $localobject->id;
  200. }
  201. /**
  202. * @depends testCommandeOther
  203. * The depends says test is run only if previous is ok
  204. */
  205. public function testCommandeDelete($id)
  206. {
  207. global $conf,$user,$langs,$db;
  208. $conf=$this->savconf;
  209. $user=$this->savuser;
  210. $langs=$this->savlangs;
  211. $db=$this->savdb;
  212. $localobject=new Commande($this->savdb);
  213. $result=$localobject->fetch($id);
  214. $result=$localobject->delete($user);
  215. print __METHOD__." id=".$id." result=".$result."\n";
  216. $this->assertLessThan($result, 0);
  217. return $result;
  218. }
  219. /**
  220. *
  221. */
  222. public function testVerifyNumRef()
  223. {
  224. global $conf,$user,$langs,$db;
  225. $conf=$this->savconf;
  226. $user=$this->savuser;
  227. $langs=$this->savlangs;
  228. $db=$this->savdb;
  229. $localobject=new Commande($this->savdb);
  230. $result=$localobject->ref='refthatdoesnotexists';
  231. $result=$localobject->VerifyNumRef();
  232. print __METHOD__." result=".$result."\n";
  233. $this->assertEquals($result, 0);
  234. return $result;
  235. }
  236. }
  237. ?>