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

/test/phpunit/CommonObjectTest.php

https://github.com/asterix14/dolibarr
PHP | 194 lines | 112 code | 27 blank | 55 comment | 2 complexity | ad39ee6d92d8bbb1a2b62fc3078a3572 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/CommonObjectTest.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. require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php';
  30. if (empty($user->id))
  31. {
  32. print "Load permissions for admin user nb 1\n";
  33. $user->fetch(1);
  34. $user->getrights();
  35. }
  36. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  37. /**
  38. * Class for PHPUnit tests
  39. *
  40. * @backupGlobals disabled
  41. * @backupStaticAttributes enabled
  42. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  43. */
  44. class CommonObjectTest extends PHPUnit_Framework_TestCase
  45. {
  46. protected $savconf;
  47. protected $savuser;
  48. protected $savlangs;
  49. protected $savdb;
  50. /**
  51. * Constructor
  52. * We save global variables into local variables
  53. *
  54. * @return CommonObjectTest
  55. */
  56. function CommonObjectTest()
  57. {
  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. // Static methods
  69. public static function setUpBeforeClass()
  70. {
  71. global $conf,$user,$langs,$db;
  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. */
  101. public function testVerifyNumRef()
  102. {
  103. global $conf,$user,$langs,$db;
  104. $conf=$this->savconf;
  105. $user=$this->savuser;
  106. $langs=$this->savlangs;
  107. $db=$this->savdb;
  108. $localobject=new Commande($this->savdb);
  109. $result=$localobject->ref='refthatdoesnotexists';
  110. $result=$localobject->VerifyNumRef();
  111. print __METHOD__." result=".$result."\n";
  112. $this->assertEquals($result, 0);
  113. return $result;
  114. }
  115. /**
  116. *
  117. */
  118. public function testFetchUser()
  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. $localobject->fetch(1);
  127. $result=$localobject->fetch_user(1);
  128. print __METHOD__." result=".$result."\n";
  129. $this->assertLessThan($localobject->user->id, 0);
  130. return $result;
  131. }
  132. /**
  133. *
  134. */
  135. public function testFetchProjet()
  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=new Commande($this->savdb);
  143. $localobject->fetch(1);
  144. $result=$localobject->fetch_projet();
  145. print __METHOD__." result=".$result."\n";
  146. $this->assertLessThanOrEqual($result,0);
  147. return $result;
  148. }
  149. /**
  150. *
  151. */
  152. public function testFetchClient()
  153. {
  154. global $conf,$user,$langs,$db;
  155. $conf=$this->savconf;
  156. $user=$this->savuser;
  157. $langs=$this->savlangs;
  158. $db=$this->savdb;
  159. $localobject=new Commande($this->savdb);
  160. $localobject->fetch(1);
  161. $result=$localobject->fetch_thirdparty();
  162. print __METHOD__." result=".$result."\n";
  163. $this->assertLessThanOrEqual($result,0);
  164. return $result;
  165. }
  166. }
  167. ?>