forked from rackspace/php-opencloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTest.php
More file actions
93 lines (91 loc) · 2.24 KB
/
UserTest.php
File metadata and controls
93 lines (91 loc) · 2.24 KB
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
<?php
/**
* Unit Tests
*
* @copyright 2012-2013 Rackspace Hosting, Inc.
* See COPYING for licensing information
*
* @version 1.0.0
* @author Glen Campbell <glen.campbell@rackspace.com>
*/
require_once('stub_conn.inc');
require_once('user.inc');
require_once('dbservice.inc');
class UserTest extends PHPUnit_Framework_TestCase
{
private
$inst,
$user;
public function __construct() {
$conn = new StubConnection('http://example.com', 'SECRET');
$useraas = new OpenCloud\DbService(
$conn, 'cloudDatabases', 'DFW', 'publicURL');
$this->inst = new OpenCloud\DbService\Instance($useraas);
$this->inst->id = '12345678';
$this->user = new OpenCloud\DbService\User($this->inst);
}
/**
* Tests
*/
public function test__construct() {
$this->assertEquals(
'OpenCloud\DbService\User',
get_class(new OpenCloud\DbService\User($this->inst)));
$u = new OpenCloud\DbService\User(
$this->inst,
'glen',
array('one','two'));
$this->assertEquals('glen', $u->name);
$this->assertEquals(2, count($u->databases));
}
public function testUrl() {
$this->user->name = 'TEST';
$this->assertEquals(
'https://dfw.databases.api.rackspacecloud.com/v1.0/'.
'TENANT-ID/instances/12345678/users/TEST',
$this->user->Url());
}
public function testInstance() {
$this->assertEquals(
'OpenCloud\DbService\Instance',
get_class($this->user->Instance()));
}
public function testService() {
$this->assertEquals(
'OpenCloud\DbService',
get_class($this->user->Service()));
}
public function testAddDatabase() {
$this->user->AddDatabase('FOO');
$this->assertEquals(
TRUE,
in_array('FOO', $this->user->databases));
}
public function testCreate() {
$response = $this->user->Create(array(
'name' => 'FOOBAR',
'password' => 'BAZ'));
$this->assertLessThan(
205,
$response->HttpStatus());
$this->assertEquals(
'FOOBAR',
$this->user->name);
$this->assertEquals(
'BAZ',
$this->user->password);
}
/**
* @expectedException OpenCloud\DbService\UserUpdateError
*/
public function testUpdate() {
$this->user->Update();
}
public function testDelete() {
$this->user->name = 'GLEN';
$response = $this->user->Delete();
$this->assertLessThan(
205,
$response->HttpStatus());
}
}