FactureFournisseurTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
  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/FactureFournisseurTest.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/fourn/class/fournisseur.facture.class.php';
  30. if (empty($user->id)) {
  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 FactureFournisseurTest 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 FactureFournisseurTest
  54. */
  55. public function __construct()
  56. {
  57. parent::__construct();
  58. //$this->sharedFixture
  59. global $conf,$user,$langs,$db;
  60. $this->savconf=$conf;
  61. $this->savuser=$user;
  62. $this->savlangs=$langs;
  63. $this->savdb=$db;
  64. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  65. //print " - db ".$db->db;
  66. print "\n";
  67. }
  68. /**
  69. * setUpBeforeClass
  70. *
  71. * @return void
  72. */
  73. public static function setUpBeforeClass()
  74. {
  75. global $conf,$user,$langs,$db;
  76. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  77. print __METHOD__."\n";
  78. }
  79. /**
  80. * tearDownAfterClass
  81. *
  82. * @return void
  83. */
  84. public static function tearDownAfterClass()
  85. {
  86. global $conf,$user,$langs,$db;
  87. $db->rollback();
  88. print __METHOD__."\n";
  89. }
  90. /**
  91. * Init phpunit tests
  92. *
  93. * @return void
  94. */
  95. protected function setUp()
  96. {
  97. global $conf,$user,$langs,$db;
  98. $conf=$this->savconf;
  99. $user=$this->savuser;
  100. $langs=$this->savlangs;
  101. $db=$this->savdb;
  102. print __METHOD__."\n";
  103. }
  104. /**
  105. * End phpunit tests
  106. *
  107. * @return void
  108. */
  109. protected function tearDown()
  110. {
  111. print __METHOD__."\n";
  112. }
  113. /**
  114. * testFactureFournisseurCreate
  115. *
  116. * @return int
  117. */
  118. public function testFactureFournisseurCreate()
  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 FactureFournisseur($this->savdb);
  126. $localobject->initAsSpecimen();
  127. $result=$localobject->create($user);
  128. $this->assertLessThan($result, 0, $localobject->errorsToString());
  129. print __METHOD__." result=".$result."\n";
  130. return $result;
  131. }
  132. /**
  133. * testFactureFournisseurFetch
  134. *
  135. * @param int $id If supplier invoice
  136. * @return void
  137. *
  138. * @depends testFactureFournisseurCreate
  139. * The depends says test is run only if previous is ok
  140. */
  141. public function testFactureFournisseurFetch($id)
  142. {
  143. global $conf,$user,$langs,$db;
  144. $conf=$this->savconf;
  145. $user=$this->savuser;
  146. $langs=$this->savlangs;
  147. $db=$this->savdb;
  148. $localobject=new FactureFournisseur($this->savdb);
  149. $result=$localobject->fetch($id);
  150. $this->assertLessThan($result, 0, $localobject->errorsToString());
  151. print __METHOD__." id=".$id." result=".$result."\n";
  152. return $localobject;
  153. }
  154. /**
  155. * testFactureFournisseurUpdate
  156. *
  157. * @param FactureFournisseur $localobject Supplier invoice
  158. * @return int
  159. *
  160. * @depends testFactureFournisseurFetch
  161. * The depends says test is run only if previous is ok
  162. */
  163. public function testFactureFournisseurUpdate($localobject)
  164. {
  165. global $conf,$user,$langs,$db;
  166. $conf=$this->savconf;
  167. $user=$this->savuser;
  168. $langs=$this->savlangs;
  169. $db=$this->savdb;
  170. $localobject->note='New note after update';
  171. $result=$localobject->update($user);
  172. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  173. $this->assertLessThan($result, 0, $localobject->errorsToString());
  174. return $localobject;
  175. }
  176. /**
  177. * testFactureFournisseurValid
  178. *
  179. * @param FactureFournisseur $localobject Supplier invoice
  180. * @return void
  181. *
  182. * @depends testFactureFournisseurUpdate
  183. * The depends says test is run only if previous is ok
  184. */
  185. public function testFactureFournisseurValid($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->validate($user);
  193. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  194. $this->assertLessThan($result, 0, $localobject->errorsToString());
  195. return $localobject;
  196. }
  197. /**
  198. * testFactureFournisseurOther
  199. *
  200. * @param FactureFournisseur $localobject Supplier invoice
  201. * @return void
  202. *
  203. * @depends testFactureFournisseurValid
  204. * The depends says test is run only if previous is ok
  205. */
  206. public function testFactureFournisseurOther($localobject)
  207. {
  208. global $conf,$user,$langs,$db;
  209. $conf=$this->savconf;
  210. $user=$this->savuser;
  211. $langs=$this->savlangs;
  212. $db=$this->savdb;
  213. /*$result=$localobject->setstatus(0);
  214. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  215. $this->assertLessThan($result, 0);
  216. */
  217. $localobject->info($localobject->id);
  218. print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
  219. $this->assertNotEquals($localobject->date_creation, '');
  220. return $localobject->id;
  221. }
  222. /**
  223. * testFactureFournisseurDelete
  224. *
  225. * @param int $id Id of supplier invoice
  226. * @return void
  227. *
  228. * @depends testFactureFournisseurOther
  229. * The depends says test is run only if previous is ok
  230. */
  231. public function testFactureFournisseurDelete($id)
  232. {
  233. global $conf,$user,$langs,$db;
  234. $conf=$this->savconf;
  235. $user=$this->savuser;
  236. $langs=$this->savlangs;
  237. $db=$this->savdb;
  238. $localobject=new FactureFournisseur($this->savdb);
  239. $result=$localobject->fetch($id);
  240. $result=$localobject->delete($user);
  241. print __METHOD__." id=".$id." result=".$result."\n";
  242. $this->assertLessThan($result, 0, $localobject->errorsToString());
  243. return $result;
  244. }
  245. }