-
Notifications
You must be signed in to change notification settings - Fork 0
/
RODSAccountTest.php
370 lines (292 loc) · 14 KB
/
RODSAccountTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
require_once dirname(__FILE__) . '/../../src/RODSAccount.class.php';
require_once dirname(__FILE__) . '/../../src/connection/RODSConn.class.php';
require_once dirname(__FILE__) . '/../../src/RODSConnManager.class.php';
require_once dirname(__FILE__) . '/../../src/ProdsPath.class.php';
require_once dirname(__FILE__) . '/../../src/ProdsDir.class.php';
require_once dirname(__FILE__) . '/../../src/RODSException.class.php';
require_once dirname(__FILE__) . '/../../src/RODSDirStats.class.php';
require_once dirname(__FILE__) . '/stubProdsDir.class.php';
/**
* Test class for RODSAccount.
* Generated by PHPUnit on 2011-02-24 at 16:39:16.
*/
class RODSAccountTest extends PHPUnit_Framework_TestCase {
/**
* @var RODSAccount
*/
protected $rodsAcct;
protected $id = "1";
protected $name = "me";
protected $zone = "myZone";
protected $host = "myirods.myhost.mycom";
protected $port = "1111";
protected $passwd = "meme";
protected $type = "rodsuser";
protected $ctime = "01298479459";
protected $mtime = "01298479459";
protected $comment = "foo";
protected $info = "bar";
protected $dn = "";
protected $resc = "demo";
protected $auth_type = "irods";
protected $ticket = "myticket";
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->rodsAcct = new RODSAccount(
$this->host,
$this->port,
$this->name,
$this->passwd,
$this->zone,
$this->resc,
$this->auth_type,
$this->ticket);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {
unset($this->rodsAcct);
}
/**
* @todo Implement testFromURI().
*/
public function testFromURI() {
// empty uri
$this->rodsAcct = $this->rodsAcct->fromURI("");
$this->assertEquals("", $this->rodsAcct->user);
//invalid format uri
$this->rodsAcct = $this->rodsAcct->fromURI("wrongformat");
$this->assertEquals("", $this->rodsAcct->user);
//valid uri
$this->rodsAcct = $this->rodsAcct->fromURI("[email protected]:1111/myZone/home/notme");
$this->assertEquals("notme", $this->rodsAcct->user);
}
/**
* @todo Implement testEquals().
*/
public function testEquals() {
$newAcct = new RODSAccount("another_irods.notmyhost.mmm", "1112", "notme", "mememe", "notmyZone");
$this->assertEquals(FALSE, $this->rodsAcct->Equals($newAcct));
$newAcct = new RODSAccount($this->host, $this->port, $this->name, $this->passwd, $this->zone);
$this->assertEquals(TRUE, $this->rodsAcct->Equals($newAcct));
}
/**
* @todo Implement testGetSignature().
*/
public function testGetSignature() {
// test_ret value should be 'd84456497b1b340d8f4f751d36fd2d8d'
$expected_ret = bin2hex(md5("$this->name.$this->zone:this->pass@$this->host:$this->port.$this->ticket", TRUE));
$actual_ret = $this->rodsAcct->getSignature();
//$this->assertEquals($expected_ret, $actual_ret, TRUE);
$this->assertEquals($expected_ret, $actual_ret);
}
/**
* @todo Implement test__toString().
*/
public function test__toString() {
$expected = $this->name . "." . $this->zone . ":(password hidden)@" . $this->host . ":" . $this->port;
//$this->assertEquals("me.myZone:(password hidden)@myirods.myhost.mycom:1111", $this->rodsAcct->__toString());
$this->assertEquals($expected, $this->rodsAcct->__toString());
}
/**
* @todo Implement testToURI().
*/
public function testToURI() {
$expected = $this->name . "." . $this->zone . "@" . $this->host . ":" . $this->port;
//$this->assertEquals($this->rodsAcct->toURI(), "[email protected]:1111");
$this->assertEquals($expected, $this->rodsAcct->toURI());
// also add test for when zone is empty
}
/**
* @todo Implement testGetUserInfo().
*/
public function testGetUserInfo() {
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
// THIS TEST NEEDS TO BE FIXED - it causes a segmentation violation on Hudson (different PHP version?)
// No RODSConnMOck defined? Or perhaps need to use stubRODSConn instead
// set up mock parameters
$retval = stubGetUserInfo();
$mocked_rodsconn_methods = array('getUserInfo');
$mocked_rodsconn_construct_params = array(&$this->rodsAcct);
$mocked_rodsaccount_methods = array('getRODSConnection');
$mocked_rodsaccount_construct_params = array($this->host, $this->port, $this->name, $this->passwd, $this->zone);
// need to stub out RODSAccount methods getRODSConnection and releaseRODSConnection
// getRODS connection stub must return mocked RODSConn object
// first mock RODSConn
$conn_stub = $this->getMock('RODSConn', $mocked_conn_methods, $mocked_rodsconn_construct_params, 'RODSConnMock');
$conn_stub->expects($this->any())->method('getUserInfo')->will($this->returnValue($retval));
$acct_stub = $this->getMock('RODSAccount', $mocked_rodsaccount_methods, $mocked_rodsaccount_construct_params, 'RODSAccountMock');
$acct_stub->expects($this->any())->method('getRODSConnection')->will($this->returnValue($conn_stub));
// now setup mock for RODSConnManager
//$conn_mgr_stub = $this->getMock('RODSConnManager', $mocked_rodsconnmanager_methods, $mocked_rodsconnmanager_construct_params, 'RODSConnManagerMock');
//$conn_mgr_stub->staticExpects($this->any())->method('getConn')->with($mocked_rodsconnmanager_getconn_params)->will($this->returnValue($retval));
//set up overload for constructors
set_new_overload(array($this, 'newCallback'));
// now run actual tests
//var_dump($acct_stub);
$this->assertEmpty($acct_stub->getRODSConnection());
unset_new_overload();
}
/**
* @todo Implement testGetTempPassword().
*/
public function testGetTempPassword() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetUserHomeDir().
*/
public function testGetUserHomeDir() {
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
// THIS TEST NEEDS TO BE FIXED - it causes a segmentation violation on Hudson (different PHP version?)
// No RODSConnMOck defined? Or perhaps need to use stubRODSConn instead
// need to get fake info from getUserInfo()
// test with/without $init_path set
// need to Mock ProdsDir and method exists()
// ProdsDir has 2 constructor args:
// (RODSAccount &$account, $path_str, $verify=false, RODSDirStats $stats=NULL)
// set up mock parameters
$retval = $this->stubGetUserInfo();
$mocked_rodsacct_methods = array('getUserInfo');
$mocked_rodsacct_construct_params = array($this->host, $this->port, $this->name, $this->passwd, $this->zone);
$acct_stub = $this->getMock('RODSAccount', $mocked_rodsacct_methods, $mocked_rodsacct_construct_params);
$acct_stub->expects($this->once())->method('getUserInfo')->will($this->returnValue($retval));
//set up overload for constructors
set_new_overload(array($this, 'newCallback'));
// now run actual tests
// test null zone code path and init_zone not set
$acct_stub->zone = null;
$p = $acct_stub->getUserHomeDir();
$this->assertEquals("//home/". $this->name, $p->path_str);
// test what path is taken when zone is not null and when init_path is set
$acct_stub->expects($this->never())->method('getUserInfo')->will($this->returnValue($retval));
$acct_stub->zone = $this->zone;
$init_val = "/thiszone/testhome/me";
$p = $acct_stub->getUserHomeDir($init_val);
$this->assertEquals($init_val, $p->path_str);
unset_new_overload();
}
/**
* @todo Implement testGetUserHomeDirURI().
*/
public function testGetUserHomeDirURI() {
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
// THIS TEST NEEDS TO BE FIXED - it causes a segmentation violation on Hudson (different PHP version?)
// No RODSConnMOck defined? Or perhaps need to use stubRODSConn instead
// set up mock parameters
$retval = $this->stubGetUserInfo();
$mocked_rodsacct_methods = array('getUserInfo');
$mocked_rodsacct_construct_params = array($this->host, $this->port, $this->name, $this->passwd, $this->zone);
$acct_stub = $this->getMock('RODSAccount', $mocked_rodsacct_methods, $mocked_rodsacct_construct_params);
$acct_stub->expects($this->any())->method('getUserInfo')->will($this->returnValue($retval));
//set up overload for constructors
set_new_overload(array($this, 'newCallback'));
// now run actual tests
$p = $acct_stub->getUserHomeDirURI();
$expected = $this->name . "." . $acct_stub->zone . "@" . $acct_stub->host . ":" . $acct_stub->port . "/" . $acct_stub->zone . "/home/" . $acct_stub->user;
$this->assertEquals($expected, $p);
$init_val = "/thiszone/testhome/me";
$p = $acct_stub->getUserHomeDirURI($init_val);
$expected = $this->name . "." . $acct_stub->zone . "@" . $acct_stub->host . ":" . $acct_stub->port . $init_val;
$this->assertEquals($expected, $p);
unset_new_overload();
}
/**
* @todo Implement testGetUserTrashDir().
*/
public function testGetUserTrashDir() {
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
// THIS TEST NEEDS TO BE FIXED - it causes a segmentation violation on Hudson (different PHP version?)
// No RODSConnMOck defined? Or perhaps need to use stubRODSConn instead
// set up mock parameters
$retval = $this->stubGetUserInfo();
$mocked_rodsacct_methods = array('getUserInfo');
$mocked_rodsacct_construct_params = array($this->host, $this->port, $this->name, $this->passwd, $this->zone);
$acct_stub = $this->getMock('RODSAccount', $mocked_rodsacct_methods, $mocked_rodsacct_construct_params);
$acct_stub->expects($this->once())->method('getUserInfo')->will($this->returnValue($retval));
//set up overload for constructors
set_new_overload(array($this, 'newCallback'));
// now run actual tests
// test getUserInfo() is called when zone is null
$acct_stub->zone = null;
$p = $acct_stub->getUserTrashDir();
$this->assertInstanceOf("stubProdsDir", $p);
$this->assertEquals("//trash/home/" . $acct_stub->user, $p->path_str);
// test what path is taken when zone is not null
$acct_stub->zone = $this->zone;
$acct_stub->expects($this->never())->method('getUserInfo')->will($this->returnValue($retval));
$p = $acct_stub->getUserTrashDir();
$this->assertInstanceOf("stubProdsDir", $p);
$this->assertEquals("/" . $acct_stub->zone . "/trash/home/" . $acct_stub->user, $p->path_str);
unset_new_overload();
}
/**
* @todo Implement testGetUserTrashDirURI().
*/
public function testGetUserTrashDirURI() {
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
// THIS TEST NEEDS TO BE FIXED - it causes a segmentation violation on Hudson (different PHP version?)
// No RODSConnMOck defined? Or perhaps need to use stubRODSConn instead
// set up mock parameters
$retval = $this->stubGetUserInfo();
$mocked_rodsacct_methods = array('getUserInfo');
$mocked_rodsacct_construct_params = array($this->host, $this->port, $this->name, $this->passwd, $this->zone);
$acct_stub = $this->getMock('RODSAccount', $mocked_rodsacct_methods, $mocked_rodsacct_construct_params);
$acct_stub->expects($this->once())->method('getUserInfo')->will($this->returnValue($retval));
//set up overload for constructors
set_new_overload(array($this, 'newCallback'));
// now run actual tests
$acct_stub->zone = null;
$p = $acct_stub->getUserTrashDirURI();
$expected = $acct_stub->user . "@" . $acct_stub->host . ":" . $acct_stub->port . "//trash/home/" . $acct_stub->user;
$this->assertEquals($expected, $p);
// noew test with zone set - getUserInfo() should never be called
$acct_stub->zone = $this->zone;
$acct_stub->expects($this->never())->method('getUserInfo')->will($this->returnValue($retval));
$p = $acct_stub->getUserTrashDirURI();
$expected = $acct_stub->user . "." . $acct_stub->zone . "@" . $acct_stub->host . ":" . $acct_stub->port . "/" . $acct_stub->zone . "/trash/home/" . $acct_stub->user;
$this->assertEquals($expected, $p);
unset_new_overload();
}
protected function newCallback($className) {
switch($className) {
case 'RODSConn': return RODSConnMock;
case 'ProdsDir': return stubProdsDir;
default: return $className;
}
}
protected function stubGetUserInfo() {
// set up mock parameters
$retval = array();
$retval['id'] = "1";
$retval['name'] = $this->name;
$retval['type'] = $this->type;
$retval['zone'] = $this->zone;
$retval['dn'] = $this->dn;
$retval['info'] = $this->info;
$retval['comment'] = $this->comment;
$retval['ctime'] = $this->ctime;
$retval['mtime'] = $this->mtime;
return $retval;
}
}
?>