1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/XMLRPC/Contact/Server.php'; |
3
|
|
|
|
4
|
|
|
class ContactXMLRPCTest extends PHPUnit_Framework_TestCase |
5
|
|
|
{ |
6
|
|
|
protected $server; |
7
|
|
|
protected $db; |
8
|
|
|
|
9
|
|
|
function setUp() |
10
|
|
|
{ |
11
|
|
|
$this->server = new Intraface_XMLRPC_Contact_Server; |
12
|
|
|
$this->db = MDB2::singleton(DB_DSN); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
function tearDown() |
16
|
|
|
{ |
17
|
|
|
$this->db->exec('TRUNCATE contact'); |
18
|
|
|
$this->db->exec('TRUNCATE address'); |
19
|
|
|
unset($this->server); |
20
|
|
|
unset($this->db); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function getClient() |
24
|
|
|
{ |
25
|
|
|
require_once dirname(__FILE__) . '/../../../install/Install.php'; |
26
|
|
|
|
27
|
|
|
if (!defined('SERVER_STATUS')) { |
28
|
|
|
define('SERVER_STATUS', 'TEST'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$install = new Intraface_Install; |
32
|
|
|
$install->resetServer(); |
33
|
|
|
$install->grantModuleAccess('administration', 'contact'); |
|
|
|
|
34
|
|
|
|
35
|
|
|
require_once 'XML/RPC2/Client.php'; |
36
|
|
|
$debug = false; |
37
|
|
|
$options = array('prefix' => 'contact.', 'debug' => $debug, 'encoding' => 'utf-8'); |
38
|
|
|
$client = XML_RPC2_Client::create(XMLRPC_SERVER_URL.'contact', $options); |
39
|
|
|
|
40
|
|
|
return $client; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
//////////////////////////////////////////////// |
44
|
|
|
|
45
|
|
|
function testConstruction() |
46
|
|
|
{ |
47
|
|
|
$this->markTestIncomplete( |
48
|
|
|
'This test has not been implemented yet.' |
49
|
|
|
); |
50
|
|
|
$this->assertTrue(is_object($this->server)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function testEmptyCredentialsThrowsException() |
54
|
|
|
{ |
55
|
|
|
$this->markTestIncomplete( |
56
|
|
|
'This test has not been implemented yet.' |
57
|
|
|
); |
58
|
|
|
$credentials = array(); |
59
|
|
|
$data = array(); |
60
|
|
|
|
61
|
|
|
try { |
62
|
|
|
$this->server->saveContact($credentials, $data); |
|
|
|
|
63
|
|
|
$this->assertFalse(true, 'Should have thrown an exception'); |
64
|
|
|
} catch (XML_RPC2_FaultException $e) { |
|
|
|
|
65
|
|
|
$this->assertTrue(true); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function testInvalidKeyThrowsException() |
70
|
|
|
{ |
71
|
|
|
$this->markTestIncomplete( |
72
|
|
|
'This test has not been implemented yet.' |
73
|
|
|
); |
74
|
|
|
$credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something'); |
75
|
|
|
$data = array(); |
76
|
|
|
try { |
77
|
|
|
$this->server->saveContact($credentials, $data); |
|
|
|
|
78
|
|
|
$this->assertFalse(true, 'Should have thrown an exception'); |
79
|
|
|
} catch (XML_RPC2_FaultException $e) { |
|
|
|
|
80
|
|
|
$this->assertTrue(true); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @group xmlrpc |
86
|
|
|
*/ |
87
|
|
|
function testGetContactWithDanishCharactersIsReturnedInUTF8FromTheClient() |
88
|
|
|
{ |
89
|
|
|
$this->markTestIncomplete( |
90
|
|
|
'This test has not been implemented yet.' |
91
|
|
|
); |
92
|
|
|
$client = $this->getClient(); |
93
|
|
|
$credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something'); |
94
|
|
|
|
95
|
|
|
$contact = new Contact(new Stub_Kernel); |
96
|
|
|
$data = array('name' => 'Tester æøå'); |
97
|
|
|
$res = $contact->save($data); |
|
|
|
|
98
|
|
|
$this->assertEquals(1, $res); |
99
|
|
|
$this->assertEquals('Tester æøå', $contact->get('name')); |
100
|
|
|
|
101
|
|
|
$retrieved = $client->getContact($credentials, $contact->getId()); |
102
|
|
|
|
103
|
|
|
$this->assertEquals('Tester æøå', $retrieved['name']); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @group xmlrpc |
108
|
|
|
*/ |
109
|
|
|
function testSaveContactWorksWithDanishCharacters() |
110
|
|
|
{ |
111
|
|
|
$this->markTestIncomplete( |
112
|
|
|
'This test has not been implemented yet.' |
113
|
|
|
); |
114
|
|
|
$client = $this->getClient(); |
115
|
|
|
$credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something'); |
116
|
|
|
|
117
|
|
|
$contact = new Contact(new Stub_Kernel); |
118
|
|
|
$data = array('name' => 'Tester'); |
119
|
|
|
$contact->save($data); |
120
|
|
|
|
121
|
|
|
$new_name = 'Tester æøå'; |
122
|
|
|
$data = array('id' => $contact->getId(), 'name' => $new_name); |
123
|
|
|
$this->assertTrue($client->saveContact($credentials, $data)); |
124
|
|
|
|
125
|
|
|
$saved_contact = new Contact(new Stub_Kernel, $contact->getId()); |
126
|
|
|
$this->assertEquals($new_name, $saved_contact->get('name')); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.