| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Unit test for Net_IMAP IMAP.php
|
|
|
6 |
*
|
|
|
7 |
* PHP version 5
|
|
|
8 |
*
|
|
|
9 |
* LICENSE: GPL.
|
|
|
10 |
*
|
|
|
11 |
* @category Net
|
|
|
12 |
* @package Net_IMAP
|
|
|
13 |
* @author Sebastian Ebling <hudeldudel@php.net>
|
|
|
14 |
* @copyright 2006 Sebastian Ebling
|
|
|
15 |
* @license http://www.gnu.org/copyleft/gpl.html
|
|
|
16 |
* @version CVS: $Id: testIMAP.php,v 1.10 2007/02/21 02:39:58 hudeldudel Exp $
|
|
|
17 |
* @link http://pear.php.net/package/Net_IMAP/
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* We are testing IMAP.php
|
|
|
22 |
*/
|
|
|
23 |
require_once 'Net/IMAP.php';
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Use PHPUnit3 for testing
|
|
|
27 |
*/
|
|
|
28 |
require_once 'PHPUnit/Framework/TestCase.php';
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Connection settings
|
|
|
32 |
*/
|
|
|
33 |
require_once 'settings.php';
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* The test class
|
|
|
37 |
*/
|
|
|
38 |
class testIMAP extends PHPUnit_Framework_TestCase
|
|
|
39 |
{
|
|
|
40 |
// contains the object handle of the Net_IMAP class
|
|
|
41 |
protected $fixture;
|
|
|
42 |
|
|
|
43 |
private $delimiter;
|
|
|
44 |
|
|
|
45 |
private $reservedFolders;
|
|
|
46 |
|
|
|
47 |
private $mailboxNames;
|
|
|
48 |
|
|
|
49 |
function testIMAP() {
|
|
|
50 |
$conn = new Net_IMAP(HOST, PORT);
|
|
|
51 |
// we need to login for getting the delimiter
|
|
|
52 |
$conn->login(USER, PASS);
|
|
|
53 |
if (PEAR::isError($this->delimiter = $conn->getHierarchyDelimiter())) {
|
|
|
54 |
echo 'Can not get hierarchy delimiter';
|
|
|
55 |
exit;
|
|
|
56 |
}
|
|
|
57 |
$conn->disconnect();
|
|
|
58 |
|
|
|
59 |
$this->reservedFolders = array( 'INBOX',
|
|
|
60 |
'INBOX'.$this->delimiter.'Trash');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
protected function setUp()
|
|
|
64 |
{
|
|
|
65 |
$this->fixture = new Net_IMAP();
|
|
|
66 |
|
|
|
67 |
// some mailboxnames to test with
|
|
|
68 |
$this->mailboxNames = array();
|
|
|
69 |
$this->mailboxNames[] = 'INBOX'.$this->delimiter.'testcase';
|
|
|
70 |
$this->mailboxNames[] = 'INBOX'.$this->delimiter.'umlautsöäüßÖÄÜ';
|
|
|
71 |
|
|
|
72 |
// ToDo: insert some mails
|
|
|
73 |
// $this->messages['test_mail1'] = file_get_contents('mails1.mbox');
|
|
|
74 |
// $this->messages['test_mail2'] = file_get_contents('mails2.mbox');
|
|
|
75 |
// $this->messages['test_mail3'] = file_get_contents('mails3.mbox');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
protected function tearDown()
|
|
|
79 |
{
|
|
|
80 |
// delete all mailboxes except INBOX
|
|
|
81 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
82 |
foreach ($mailboxes as $mailbox) {
|
|
|
83 |
if (in_array($mailbox, $this->reservedFolders)) {
|
|
|
84 |
continue;
|
|
|
85 |
}
|
|
|
86 |
$this->fixture->deleteMailbox($mailbox);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// delete instance
|
|
|
90 |
unset($this->fixture);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
protected function login()
|
|
|
94 |
{
|
|
|
95 |
$result = $this->fixture->connect(HOST, PORT);
|
|
|
96 |
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
|
|
|
97 |
$result = $this->fixture->login(USER, PASS);
|
|
|
98 |
$this->assertTrue(!PEAR::isError($result), 'Can not log in');
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
protected function logout()
|
|
|
102 |
{
|
|
|
103 |
$result = $this->fixture->disconnect();
|
|
|
104 |
$this->assertTrue(!PEAR::isError($result), 'Error on disconnect');
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
///
|
|
|
110 |
/// connection tests
|
|
|
111 |
///
|
|
|
112 |
|
|
|
113 |
public function testConnect()
|
|
|
114 |
{
|
|
|
115 |
$result = $this->fixture->connect(HOST, PORT);
|
|
|
116 |
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public function testLogin()
|
|
|
120 |
{
|
|
|
121 |
$result = $this->fixture->connect(HOST, PORT);
|
|
|
122 |
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
|
|
|
123 |
$result = $this->fixture->login(USER, PASS);
|
|
|
124 |
$this->assertTrue(!PEAR::isError($result), 'Can not login');
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public function testDisconnect()
|
|
|
128 |
{
|
|
|
129 |
$result = $this->fixture->connect(HOST, PORT);
|
|
|
130 |
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
|
|
|
131 |
$result = $this->fixture->login(USER, PASS);
|
|
|
132 |
$this->assertTrue($result, 'Can not login');
|
|
|
133 |
$result = $this->fixture->disconnect();
|
|
|
134 |
$this->assertTrue(!PEAR::isError($result), 'Error on disconnect');
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
///
|
|
|
140 |
/// mailbox tests
|
|
|
141 |
///
|
|
|
142 |
|
|
|
143 |
public function testCreateMailbox()
|
|
|
144 |
{
|
|
|
145 |
$this->login();
|
|
|
146 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
147 |
foreach ($this->mailboxNames as $mailbox) {
|
|
|
148 |
if (in_array($mailbox, $this->reservedFolders)) {
|
|
|
149 |
continue;
|
|
|
150 |
}
|
|
|
151 |
$this->fixture->deleteMailbox($mailbox);
|
|
|
152 |
}
|
|
|
153 |
foreach ($this->mailboxNames as $mailbox) {
|
|
|
154 |
if ($mailbox == 'INBOX') {
|
|
|
155 |
continue;
|
|
|
156 |
}
|
|
|
157 |
$result = $this->fixture->createMailbox($mailbox);
|
|
|
158 |
$this->assertTrue($result, 'Can not create mailbox '.$mailbox);
|
|
|
159 |
}
|
|
|
160 |
// print_r($this->fixture->getMailboxes());
|
|
|
161 |
$this->logout();
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public function testGetMailboxes()
|
|
|
165 |
{
|
|
|
166 |
$this->login();
|
|
|
167 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
168 |
// print_r($mailboxes);
|
|
|
169 |
$this->logout();
|
|
|
170 |
|
|
|
171 |
$this->assertTrue(!PEAR::isError($mailboxes), 'Can not list mailboxes');
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public function testSelectMailbox()
|
|
|
175 |
{
|
|
|
176 |
$this->login();
|
|
|
177 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
178 |
foreach ($mailboxes as $mailbox) {
|
|
|
179 |
$result = $this->fixture->selectMailbox($mailbox);
|
|
|
180 |
$this->assertTrue(!PEAR::isError($result), 'Can not select mailbox '.$mailbox);
|
|
|
181 |
}
|
|
|
182 |
$this->logout();
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// examineMailbox needs some messages for testing
|
|
|
186 |
|
|
|
187 |
public function testRenameMailbox()
|
|
|
188 |
{
|
|
|
189 |
$this->login();
|
|
|
190 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
191 |
// print_r($mailboxes);
|
|
|
192 |
foreach ($mailboxes as $mailbox) {
|
|
|
193 |
if (in_array($mailbox, $this->reservedFolders)) {
|
|
|
194 |
continue;
|
|
|
195 |
}
|
|
|
196 |
$result = $this->fixture->renameMailbox($mailbox, $mailbox.'renamed');
|
|
|
197 |
$this->assertTrue(!PEAR::isError($result), 'Can not rename mailbox '.$mailbox);
|
|
|
198 |
}
|
|
|
199 |
$mailboxes_new = $this->fixture->getMailboxes();
|
|
|
200 |
for ($i=0; $i < sizeof($mailboxes_new); $i++) {
|
|
|
201 |
if (in_array($mailboxes[$i], $this->reservedFolders)) {
|
|
|
202 |
continue;
|
|
|
203 |
}
|
|
|
204 |
$this->assertTrue(($mailboxes[$i].'renamed' == $mailboxes_new[$i]), 'Mailbox '.$mailboxes[$i].' not renamed');
|
|
|
205 |
}
|
|
|
206 |
// print_r($mailboxes_new);
|
|
|
207 |
|
|
|
208 |
$this->logout();
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public function testMailboxExist()
|
|
|
212 |
{
|
|
|
213 |
$this->login();
|
|
|
214 |
// this mailbox name must not exist before
|
|
|
215 |
$mailboxname = 'INBOX'.$this->delimiter.'testMailboxExistöäüß';
|
|
|
216 |
$this->fixture->deleteMailbox($mailboxname);
|
|
|
217 |
$result = $this->fixture->mailboxExist($mailboxname);
|
|
|
218 |
$this->assertFalse($result, 'Mailbox should NOT exist');
|
|
|
219 |
|
|
|
220 |
$result = $this->fixture->createMailbox($mailboxname);
|
|
|
221 |
$this->assertTrue(!PEAR::isError($result), 'Can not create mailbox');
|
|
|
222 |
|
|
|
223 |
$result = $this->fixture->mailboxExist($mailboxname);
|
|
|
224 |
$this->assertTrue($result, 'Mailbox should exist');
|
|
|
225 |
|
|
|
226 |
$result = $this->fixture->deleteMailbox($mailboxname);
|
|
|
227 |
$this->assertTrue($result, 'Can not delete Mailbox');
|
|
|
228 |
|
|
|
229 |
$this->logout();
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public function testDeleteMailbox()
|
|
|
233 |
{
|
|
|
234 |
$this->login();
|
|
|
235 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
236 |
// print_r($mailboxes);
|
|
|
237 |
foreach ($mailboxes as $mailbox) {
|
|
|
238 |
if (in_array($mailbox, $this->reservedFolders)) {
|
|
|
239 |
continue;
|
|
|
240 |
}
|
|
|
241 |
$result = $this->fixture->deleteMailbox($mailbox);
|
|
|
242 |
$this->assertTrue(!PEAR::isError($result), 'Can not delete mailbox '.$mailbox);
|
|
|
243 |
}
|
|
|
244 |
// print_r($this->fixture->getMailboxes());
|
|
|
245 |
|
|
|
246 |
$this->logout();
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public function testGetMailboxSize()
|
|
|
250 |
{
|
|
|
251 |
$this->login();
|
|
|
252 |
$mailboxes = $this->fixture->getMailboxes();
|
|
|
253 |
foreach ($mailboxes as $mailbox) {
|
|
|
254 |
$result = $this->fixture->getMailboxSize($mailbox);
|
|
|
255 |
// print_r($result);
|
|
|
256 |
$this->assertTrue(!PEAR::isError($result), 'Can not get size for mailbox '.$mailbox);
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
$this->logout();
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
///
|
|
|
265 |
/// suscribing tests
|
|
|
266 |
///
|
|
|
267 |
|
|
|
268 |
public function testSubscribeMailbox()
|
|
|
269 |
{
|
|
|
270 |
$this->login();
|
|
|
271 |
$this->fixture->createMailbox('INBOX'.$this->delimiter.'testSubscribe');
|
|
|
272 |
$result = $this->fixture->subscribeMailbox('INBOX'.$this->delimiter.'testSubscribe');
|
|
|
273 |
$this->assertTrue(!PEAR::isError($result), 'Can not subscribe Mailbox');
|
|
|
274 |
|
|
|
275 |
$this->logout();
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
public function testListsubscribedMailboxes()
|
|
|
279 |
{
|
|
|
280 |
$this->login();
|
|
|
281 |
$this->fixture->createMailbox('INBOX'.$this->delimimter.'testSubscribe');
|
|
|
282 |
$this->fixture->subscribeMailbox('INBOX');
|
|
|
283 |
$this->fixture->subscribeMailbox('INBOX'.$this->delimiter.'testSubscribe');
|
|
|
284 |
$subscribed = $this->fixture->listsubscribedMailboxes();
|
|
|
285 |
//print_r($subscribed);
|
|
|
286 |
$this->logout();
|
|
|
287 |
|
|
|
288 |
$this->assertTrue(!PEAR::isError($subscribed), 'Can not list subscribed mailboxes');
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
public function testUnsubscribeMailbox()
|
|
|
292 |
{
|
|
|
293 |
$this->login();
|
|
|
294 |
$subscribed = $this->fixture->listsubscribedMailboxes();
|
|
|
295 |
// print_r($subscribed);
|
|
|
296 |
foreach ($subscribed as $mailbox) {
|
|
|
297 |
if ($mailbox == 'INBOX') {
|
|
|
298 |
continue;
|
|
|
299 |
}
|
|
|
300 |
$result = $this->fixture->unsubscribeMailbox($mailbox);
|
|
|
301 |
$this->assertTrue(!PEAR::isError($result), 'Can not unsubscribe mailbox '.$mailbox);
|
|
|
302 |
}
|
|
|
303 |
// print_r($this->fixture->listsubscribedMailboxes());
|
|
|
304 |
|
|
|
305 |
$this->logout();
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
public function testGetStorageQuotaRoot()
|
|
|
309 |
{
|
|
|
310 |
$this->login();
|
|
|
311 |
if (!$this->fixture->hasCapability('QUOTA')) {
|
|
|
312 |
return;
|
|
|
313 |
}
|
|
|
314 |
$this->fixture->selectMailbox('INBOX');
|
|
|
315 |
$result = $this->fixture->getStorageQuotaRoot();
|
|
|
316 |
$this->assertTrue(!PEAR::isError($result), 'Can not get StorageQuotaRoot');
|
|
|
317 |
$this->logout();
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
public function testGetACL()
|
|
|
321 |
{
|
|
|
322 |
$this->login();
|
|
|
323 |
if (!$this->fixture->hasCapability('ACL')) {
|
|
|
324 |
return;
|
|
|
325 |
}
|
|
|
326 |
$result = $this->fixture->getACL();
|
|
|
327 |
$this->assertTrue(!PEAR::isError($result), 'Can not get ACL');
|
|
|
328 |
$this->logout();
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
public function testGetHierarchyDelimiter()
|
|
|
332 |
{
|
|
|
333 |
$this->login();
|
|
|
334 |
$result = $this->fixture->getHierarchyDelimiter();
|
|
|
335 |
$this->assertTrue(!PEAR::isError($result), 'Can not get Hierarchy Delimiter');
|
|
|
336 |
$this->logout();
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
?>
|