PageRenderTime 154ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/test/phpunit/SocieteTest.php

https://github.com/asterix14/dolibarr
PHP | 324 lines | 189 code | 47 blank | 88 comment | 4 complexity | 84ef64c236e0b31dfe2611cf059536be 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/SocieteTest.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/societe/class/societe.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 SocieteTest 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 SocieteTest
  54. */
  55. function SocieteTest()
  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. if ($conf->global->SOCIETE_CODECLIENT_ADDON != 'mod_codeclient_monkey') { print __METHOD__." third party ref checker must be setup to 'mod_codeclient_monkey' not to '".$conf->global->SOCIETE_CODECLIENT_ADDON."'.\n"; die(); }
  72. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  73. print __METHOD__."\n";
  74. }
  75. public static function tearDownAfterClass()
  76. {
  77. global $conf,$user,$langs,$db;
  78. $db->rollback();
  79. print __METHOD__."\n";
  80. }
  81. /**
  82. */
  83. protected function setUp()
  84. {
  85. global $conf,$user,$langs,$db;
  86. $conf=$this->savconf;
  87. $user=$this->savuser;
  88. $langs=$this->savlangs;
  89. $db=$this->savdb;
  90. print __METHOD__."\n";
  91. }
  92. /**
  93. */
  94. protected function tearDown()
  95. {
  96. print __METHOD__."\n";
  97. }
  98. /**
  99. */
  100. public function testSocieteCreate()
  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 Societe($this->savdb);
  108. $localobject->initAsSpecimen();
  109. $result=$localobject->create($user);
  110. print __METHOD__." result=".$result."\n";
  111. $this->assertLessThanOrEqual($result, 0);
  112. return $result;
  113. }
  114. /**
  115. * @depends testSocieteCreate
  116. * The depends says test is run only if previous is ok
  117. */
  118. public function testSocieteFetch($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 Societe($this->savdb);
  126. $result=$localobject->fetch($id);
  127. print __METHOD__." id=".$id." result=".$result."\n";
  128. $this->assertLessThan($result, 0);
  129. $result=$localobject->verify();
  130. print __METHOD__." id=".$id." result=".$result."\n";
  131. $this->assertEquals($result, 0);
  132. return $localobject;
  133. }
  134. /**
  135. * @depends testSocieteFetch
  136. * The depends says test is run only if previous is ok
  137. */
  138. public function testSocieteUpdate($localobject)
  139. {
  140. global $conf,$user,$langs,$db;
  141. $conf=$this->savconf;
  142. $user=$this->savuser;
  143. $langs=$this->savlangs;
  144. $db=$this->savdb;
  145. $localobject->note='New note after update';
  146. //$localobject->note_public='New note public after update';
  147. $localobject->name='New name';
  148. $localobject->address='New address';
  149. $localobject->zip='New zip';
  150. $localobject->town='New town';
  151. $localobject->status=0;
  152. $localobject->tel='New tel';
  153. $localobject->fax='New fax';
  154. $localobject->email='New email';
  155. $localobject->url='New url';
  156. $localobject->idprof1='new idprof1';
  157. $localobject->idprof2='new idprof2';
  158. $localobject->idprof3='new idprof3';
  159. $localobject->idprof4='new idprof4';
  160. $result=$localobject->update($localobject->id,$user);
  161. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  162. $this->assertLessThan($result, 0);
  163. $result=$localobject->update_note($localobject->note);
  164. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  165. $this->assertLessThan($result, 0);
  166. //$result=$localobject->update_note_public($localobject->note_public);
  167. //print __METHOD__." id=".$localobject->id." result=".$result."\n";
  168. //$this->assertLessThan($result, 0);
  169. $newobject=new Societe($this->savdb);
  170. $result=$newobject->fetch($localobject->id);
  171. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  172. $this->assertLessThan($result, 0);
  173. $this->assertEquals($localobject->note, $newobject->note);
  174. //$this->assertEquals($localobject->note_public, $newobject->note_public);
  175. $this->assertEquals($localobject->name, $newobject->name);
  176. $this->assertEquals($localobject->address, $newobject->address);
  177. $this->assertEquals($localobject->zip, $newobject->zip);
  178. $this->assertEquals($localobject->town, $newobject->town);
  179. $this->assertEquals($localobject->status, $newobject->status);
  180. $this->assertEquals($localobject->tel, $newobject->tel);
  181. $this->assertEquals($localobject->fax, $newobject->fax);
  182. $this->assertEquals($localobject->email, $newobject->email);
  183. $this->assertEquals($localobject->url, $newobject->url);
  184. $this->assertEquals($localobject->idprof1, $newobject->idprof1);
  185. $this->assertEquals($localobject->idprof2, $newobject->idprof2);
  186. $this->assertEquals($localobject->idprof3, $newobject->idprof3);
  187. $this->assertEquals($localobject->idprof4, $newobject->idprof4);
  188. return $localobject;
  189. }
  190. /**
  191. * @depends testSocieteUpdate
  192. * The depends says test is run only if previous is ok
  193. */
  194. public function testSocieteOther($localobject)
  195. {
  196. global $conf,$user,$langs,$db;
  197. $conf=$this->savconf;
  198. $user=$this->savuser;
  199. $langs=$this->savlangs;
  200. $db=$this->savdb;
  201. $result=$localobject->factures_impayes();
  202. print __METHOD__." id=".$localobject->id." result=".join(',',$result)."\n";
  203. //$this->assertLessThan($result, 0);
  204. $result=$localobject->set_as_client();
  205. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  206. $this->assertLessThan($result, 0);
  207. $result=$localobject->set_price_level(1,$user);
  208. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  209. $this->assertLessThan($result, 0);
  210. $result=$localobject->set_remise_client(10,'Gift',$user);
  211. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  212. $this->assertLessThan($result, 0);
  213. $result=$localobject->getNomUrl(1);
  214. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  215. $this->assertNotEquals($result, '');
  216. $result=$localobject->getFullAddress();
  217. print __METHOD__." id=".$localobject->id." result=".$result."\n";
  218. $this->assertContains("New address\nNew zip New town", $result);
  219. $result=$localobject->isInEEC();
  220. print __METHOD__." id=".$localobject->id." pays_code=".$this->pays_code." result=".$result."\n";
  221. $this->assertTrue(true, $result);
  222. $localobject->info($localobject->id);
  223. print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
  224. $this->assertNotEquals($localobject->date_creation, '');
  225. return $localobject->id;
  226. }
  227. /**
  228. * @depends testSocieteOther
  229. * The depends says test is run only if previous is ok
  230. */
  231. public function testSocieteDelete($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 Societe($this->savdb);
  239. $result=$localobject->fetch($id);
  240. $result=$localobject->delete($id);
  241. print __METHOD__." id=".$id." result=".$result."\n";
  242. $this->assertLessThan($result, 0);
  243. return $result;
  244. }
  245. /**
  246. *
  247. */
  248. /*public function testVerifyNumRef()
  249. {
  250. global $conf,$user,$langs,$db;
  251. $conf=$this->savconf;
  252. $user=$this->savuser;
  253. $langs=$this->savlangs;
  254. $db=$this->savdb;
  255. $localobject=new Adherent($this->savdb);
  256. $result=$localobject->ref='refthatdoesnotexists';
  257. $result=$localobject->VerifyNumRef();
  258. print __METHOD__." result=".$result."\n";
  259. $this->assertEquals($result, 0);
  260. return $result;
  261. }*/
  262. /**
  263. */
  264. public function testSocieteStatic()
  265. {
  266. global $conf,$user,$langs,$db;
  267. $conf=$this->savconf;
  268. $user=$this->savuser;
  269. $langs=$this->savlangs;
  270. $db=$this->savdb;
  271. $localobject=new Societe($db);
  272. return;
  273. }
  274. }
  275. ?>