1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/XMLRPC/Newsletter/Server.php'; |
3
|
|
|
|
4
|
|
|
class NewsletterXMLRPCTest extends PHPUnit_Framework_TestCase |
5
|
|
|
{ |
6
|
|
|
protected $server; |
7
|
|
|
protected $db; |
8
|
|
|
|
9
|
|
|
function setUp() |
10
|
|
|
{ |
11
|
|
|
$this->server = new Intraface_XMLRPC_Newsletter_Server; |
12
|
|
|
$this->db = MDB2::singleton(DB_DSN); |
13
|
|
|
$this->kernel = new Stub_Kernel; |
|
|
|
|
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function tearDown() |
17
|
|
|
{ |
18
|
|
|
$this->db->exec('TRUNCATE contact'); |
19
|
|
|
$this->db->exec('TRUNCATE newsletter_subscriber'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function testConstruction() |
23
|
|
|
{ |
24
|
|
|
$this->markTestIncomplete( |
25
|
|
|
'This test has not been implemented yet.' |
26
|
|
|
); |
27
|
|
|
$this->assertTrue(is_object($this->server)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function testEmptyCredentialsThrowsException() |
31
|
|
|
{ |
32
|
|
|
$this->markTestIncomplete( |
33
|
|
|
'This test has not been implemented yet.' |
34
|
|
|
); |
35
|
|
|
$credentials = array(); |
36
|
|
|
$list = 1; |
37
|
|
|
$email = 'test'; |
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
$this->server->subscribe($credentials, $list, $email); |
|
|
|
|
41
|
|
|
$this->assertFalse(true, 'Should have thrown an exception'); |
42
|
|
|
} catch (XML_RPC2_FaultException $e) { |
|
|
|
|
43
|
|
|
$this->assertTrue(true); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @group xmlrpc |
49
|
|
|
*/ |
50
|
|
|
function testIfANonExistingListIsUsedWithSubscribeAnExceptionIsThrown() |
51
|
|
|
{ |
52
|
|
|
$this->markTestIncomplete( |
53
|
|
|
'This test has not been implemented yet.' |
54
|
|
|
); |
55
|
|
|
$client = $this->getClient(); |
56
|
|
|
|
57
|
|
|
$credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something'); |
58
|
|
|
$list = 1; // non existing list |
59
|
|
|
$email = 'test'; |
60
|
|
|
|
61
|
|
|
try { |
62
|
|
|
$client->subscribe($credentials, $list, $email); |
63
|
|
|
$this->assertFalse(true, 'Should have thrown an exception'); |
64
|
|
|
} catch (XML_RPC2_FaultException $e) { |
|
|
|
|
65
|
|
|
$this->assertTrue(true); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @group xmlrpc |
71
|
|
|
*/ |
72
|
|
|
function testSubscribeHandlesStuff() |
73
|
|
|
{ |
74
|
|
|
$this->markTestIncomplete( |
75
|
|
|
'This test has not been implemented yet.' |
76
|
|
|
); |
77
|
|
|
$client = $this->getClient(); |
78
|
|
|
$credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something'); |
79
|
|
|
$email = 'test'; |
80
|
|
|
|
81
|
|
|
// create the list |
82
|
|
|
$newsletter = new NewsletterList($this->kernel); |
83
|
|
|
$data = array( |
84
|
|
|
'title' => 'title', |
85
|
|
|
'sender_name' => 'sender name', |
86
|
|
|
'reply_email' => '[email protected]', |
87
|
|
|
'description' => 'description', |
88
|
|
|
'subscribe_message' => 'subscribe message', |
89
|
|
|
'subscribe_subject' => 'subscribe subject', |
90
|
|
|
'optin_link' => 'http://example.dk/' |
91
|
|
|
); |
92
|
|
|
$list = $newsletter->save($data); |
93
|
|
|
|
94
|
|
|
try { |
95
|
|
|
$client->subscribe($credentials, $list, $email); |
96
|
|
|
$this->assertFalse(true, 'Should have thrown an exception'); |
97
|
|
|
} catch (XML_RPC2_FaultException $e) { |
|
|
|
|
98
|
|
|
$this->assertTrue(true); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function getClient() |
103
|
|
|
{ |
104
|
|
|
require_once dirname(__FILE__) . '/../../../install/Install.php'; |
105
|
|
|
|
106
|
|
|
if (!defined('SERVER_STATUS')) { |
107
|
|
|
define('SERVER_STATUS', 'TEST'); |
108
|
|
|
} |
109
|
|
|
$install = new Intraface_Install; |
110
|
|
|
$install->resetServer(); |
111
|
|
|
$install->grantModuleAccess('administration', 'contact', 'newsletter'); |
|
|
|
|
112
|
|
|
|
113
|
|
|
require_once 'XML/RPC2/Client.php'; |
114
|
|
|
$options = array('prefix' => 'newsletter.', 'debug' => false); |
115
|
|
|
return XML_RPC2_Client::create(XMLRPC_SERVER_URL.'newsletter?version=0.2.0', $options); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: