dolibarr  13.0.2
MyObjectTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) ---Put here your own copyright and developer email---
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  */
18 
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/mymodule/class/myobject.class.php';
30 
31 if (empty($user->id)) {
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 $langs->load("main");
39 
40 
46 {
47  protected $savconf;
48  protected $savuser;
49  protected $savlangs;
50  protected $savdb;
51 
58  public function __construct()
59  {
60  parent::__construct();
61 
62  //$this->sharedFixture
63  global $conf, $user, $langs, $db;
64  $this->savconf = $conf;
65  $this->savuser = $user;
66  $this->savlangs = $langs;
67  $this->savdb = $db;
68 
69  print __METHOD__." db->type=".$db->type." user->id=".$user->id;
70  //print " - db ".$db->db;
71  print "\n";
72  }
73 
78  public static function setUpBeforeClass()
79  {
80  global $conf, $user, $langs, $db;
81  $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
82 
83  print __METHOD__."\n";
84  }
85 
90  protected function setUp()
91  {
92  global $conf, $user, $langs, $db;
93  $conf = $this->savconf;
94  $user = $this->savuser;
95  $langs = $this->savlangs;
96  $db = $this->savdb;
97 
98  print __METHOD__."\n";
99  }
100 
105  protected function tearDown()
106  {
107  print __METHOD__."\n";
108  }
109 
114  public static function tearDownAfterClass()
115  {
116  global $conf, $user, $langs, $db;
117  $db->rollback();
118 
119  print __METHOD__."\n";
120  }
121 
122 
128  public function testSomething()
129  {
130  global $conf, $user, $langs, $db;
131  $conf = $this->savconf;
132  $user = $this->savuser;
133  $langs = $this->savlangs;
134  $db = $this->savdb;
135 
136  $result = true;
137 
138  print __METHOD__." result=".$result."\n";
139  $this->assertTrue($result);
140 
141  return $result;
142  }
143 
149  public function testMyObjectCreate()
150  {
151  global $conf, $user, $langs, $db;
152  $conf = $this->savconf;
153  $user = $this->savuser;
154  $langs = $this->savlangs;
155  $db = $this->savdb;
156 
157  $localobject = new MyObject($this->savdb);
158  $localobject->initAsSpecimen();
159  $result = $localobject->create($user);
160 
161  print __METHOD__." result=".$result."\n";
162  $this->assertLessThan($result, 0);
163 
164  return $result;
165  }
166 
176  public function testMyObjectDelete($id)
177  {
178  global $conf, $user, $langs, $db;
179  $conf = $this->savconf;
180  $user = $this->savuser;
181  $langs = $this->savlangs;
182  $db = $this->savdb;
183 
184  $localobject = new MyObject($this->savdb);
185  $result = $localobject->fetch($id);
186  $result = $localobject->delete($user);
187 
188  print __METHOD__." id=".$id." result=".$result."\n";
189  $this->assertLessThan($result, 0);
190  return $result;
191  }
192 }
tearDown()
Unit test teardown.
setUp()
Unit test setup.
Class for MyObject.
__construct()
Constructor We save global variables into local variables.
testMyObjectDelete($id)
testMyObjectDelete
testSomething()
A sample test.
static tearDownAfterClass()
Global test teardown.
print
Draft customers invoices.
Definition: index.php:89
testMyObjectCreate()
testMyObjectCreate
static setUpBeforeClass()
Global test setup.