Passed
Branch develop (944e2a)
by
unknown
27:19
created

MyObjectTest::testMyObjectDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 15
rs 9.9
1
<?php
2
/* Copyright (C) 2007-2017 Laurent Destailleur  <[email protected]>
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
19
/**
20
 * \file    test/phpunit/MyObjectTest.php
21
 * \ingroup mymodule
22
 * \brief   PHPUnit test for MyObject class.
23
 */
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/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
41
/**
42
 * Class MyObjectTest
43
 * @package Testmymodule
44
 */
45
class MyObjectTest extends \PHPUnit_Framework_TestCase
46
{
47
	protected $savconf;
48
	protected $savuser;
49
	protected $savlangs;
50
	protected $savdb;
51
52
	/**
53
	 * Constructor
54
	 * We save global variables into local variables
55
	 *
56
	 * @return MyObject
57
	 */
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
74
	/**
75
	 * Global test setup
76
	 * @return void
77
	 */
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
86
	/**
87
	 * Unit test setup
88
	 * @return void
89
	 */
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
101
	/**
102
	 * Unit test teardown
103
	 * @return void
104
	 */
105
	protected function tearDown()
106
	{
107
		print __METHOD__."\n";
108
	}
109
110
	/**
111
	 * Global test teardown
112
	 * @return void
113
	 */
114
	public static function tearDownAfterClass()
115
	{
116
		global $conf, $user, $langs, $db;
117
		$db->rollback();
118
119
		print __METHOD__."\n";
120
	}
121
122
123
	/**
124
	 * A sample test
125
	 *
126
	 * @return bool
127
	 */
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
144
	/**
145
	 * testMyObjectCreate
146
	 *
147
	 * @return int
148
	 */
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
167
	/**
168
	 * testMyObjectDelete
169
	 *
170
	 * @param	int		$id		Id of object
171
	 * @return	void
172
	 *
173
	 * @depends	testMyObjectCreate
174
	 * The depends says test is run only if previous is ok
175
	 */
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
}
193