forked from rackspace/php-opencloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTest.php
More file actions
100 lines (95 loc) · 2.49 KB
/
BaseTest.php
File metadata and controls
100 lines (95 loc) · 2.49 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
94
95
96
97
98
99
100
<?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>
*/
define('RAXSDK_FATAL_HALT', False); // don't halt on Fatal errors
require_once('base.inc');
/**
* Can't test Base directly, since it is an abstract class, so we instantiate it
*/
class MyBase extends OpenCloud\Base {
public
$foo; // to test SetProperty
public function GetHttpRequestObject($url, $method='GET') {
return parent::GetHttpRequestObject($url, $method);
}
}
class BaseTest extends PHPUnit_Framework_TestCase
{
private $my;
/**
* create our redirected Base class
*/
public function __construct() {
$this->my = new MyBase;
}
/**
* Tests
*/
public function test_gettext() {
$this->assertEquals(_('Hello'), 'Hello');
}
public function test_noslash() {
$this->assertEquals(noslash('String/'), 'String');
$this->assertEquals(noslash('String'), 'String');
}
public function testDebug() {
setDebug(TRUE);
$this->expectOutputRegex('/ELLO/');
$this->my->debug("HELLO, WORLD!");
setDebug(FALSE);
}
/**
* @expectedException OpenCloud\URLError
*/
public function testUrl() {
$this->my->Url();
}
public function testGetHttpRequestObject() {
$request = $this->my->GetHttpRequestObject('file:/dev/null');
$this->assertEquals(
'OpenCloud\CurlRequest',
get_class($request));
}
/**
* @expectedException OpenCloud\AttributeError
*/
public function test__set() {
$this->my->foobar = 'baz'; // should cause error
$this->expectOutputRegEx('/Unrecognized attribute/');
}
public function testMakeQueryString() {
$this->assertEquals(
'A=1',
$this->my->MakeQueryString(array('A'=>1)));
$this->assertEquals(
'A=1&B=2',
$this->my->MakeQueryString(array('A'=>1,'B'=>2)));
}
/**
* @expectedException OpenCloud\JsonError
*/
public function testCheckJsonError() {
$json = '{"one":"two"}';
$obj = json_decode($json);
$this->assertEquals(FALSE, $this->my->CheckJsonError());
$json = '{"one":"two"';
$obj = json_decode($json);
$this->assertEquals(TRUE, $this->my->CheckJsonError());
}
/**
* @expectedException OpenCloud\AttributeError
*/
public function testSetProperty() {
$this->my->foo = 'bar';
$this->assertEquals('bar', $this->my->foo);
$this->my->SetProperty('one', 'two');
$this->assertEquals('two', $this->my->one);
}
}