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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
* Unit test for Net_IMAP IMAP.php
*
* PHP version 5
*
* LICENSE: GPL.
*
* @category Net
* @package Net_IMAP
* @author Sebastian Ebling <hudeldudel@php.net>
* @copyright 2006 Sebastian Ebling
* @license http://www.gnu.org/copyleft/gpl.html
* @version CVS: $Id$
* @link http://pear.php.net/package/Net_IMAP/
*/
/**
* We are testing IMAP.php
*/
require_once 'Net/IMAP.php';
/**
* Use PHPUnit3 for testing
*/
require_once 'PHPUnit/Framework/TestCase.php';
/**
* The test class
*/
class testIMAP extends PHPUnit_Framework_TestCase
{
// contains the object handle of the Net_IMAP class
protected $fixture;
private $delimiter;
private $reservedFolders;
private $mailboxNames;
function testIMAP() {
$conn = new Net_IMAP(HOST, PORT);
// we need to login for getting the delimiter
$conn->login(USER, PASS);
if (PEAR::isError($this->delimiter = $conn->getHierarchyDelimiter())) {
$this->fail('Can not get hierarchy delimiter');
}
$conn->disconnect();
$this->reservedFolders = array( 'INBOX',
'INBOX'.$this->delimiter.'Trash');
}
protected function setUp()
{
if (file_exists(dirname(__FILE__) . '/settings.php')) {
include_once dirname(__FILE__) . '/settings.php';
} else {
$this->markTestSkipped("No settings.php available?");
}
$this->fixture = new Net_IMAP();
// some mailboxnames to test with
$this->mailboxNames = array();
$this->mailboxNames[] = 'INBOX'.$this->delimiter.'testcase';
$this->mailboxNames[] = 'INBOX'.$this->delimiter.'umlautsöäüßÖÄÜ';
// ToDo: insert some mails
// $this->messages['test_mail1'] = file_get_contents('mails1.mbox');
// $this->messages['test_mail2'] = file_get_contents('mails2.mbox');
// $this->messages['test_mail3'] = file_get_contents('mails3.mbox');
}
protected function tearDown()
{
// delete all mailboxes except INBOX
$mailboxes = $this->fixture->getMailboxes();
foreach ($mailboxes as $mailbox) {
if (in_array($mailbox, $this->reservedFolders)) {
continue;
}
$this->fixture->deleteMailbox($mailbox);
}
// delete instance
unset($this->fixture);
}
protected function login()
{
$result = $this->fixture->connect(HOST, PORT);
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
$result = $this->fixture->login(USER, PASS);
$this->assertTrue(!PEAR::isError($result), 'Can not log in');
}
protected function logout()
{
$result = $this->fixture->disconnect();
$this->assertTrue(!PEAR::isError($result), 'Error on disconnect');
}
///
/// connection tests
///
public function testConnect()
{
$result = $this->fixture->connect(HOST, PORT);
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
}
public function testLogin()
{
$result = $this->fixture->connect(HOST, PORT);
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
$result = $this->fixture->login(USER, PASS);
$this->assertTrue(!PEAR::isError($result), 'Can not login');
}
public function testDisconnect()
{
$result = $this->fixture->connect(HOST, PORT);
$this->assertTrue(!PEAR::isError($result), 'Can not connect');
$result = $this->fixture->login(USER, PASS);
$this->assertTrue($result, 'Can not login');
$result = $this->fixture->disconnect();
$this->assertTrue(!PEAR::isError($result), 'Error on disconnect');
}
///
/// mailbox tests
///
public function testCreateMailbox()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
foreach ($this->mailboxNames as $mailbox) {
if (in_array($mailbox, $this->reservedFolders)) {
continue;
}
$this->fixture->deleteMailbox($mailbox);
}
foreach ($this->mailboxNames as $mailbox) {
if ($mailbox == 'INBOX') {
continue;
}
$result = $this->fixture->createMailbox($mailbox);
$this->assertTrue($result, 'Can not create mailbox '.$mailbox);
}
// print_r($this->fixture->getMailboxes());
$this->logout();
}
public function testGetMailboxes()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
// print_r($mailboxes);
$this->logout();
$this->assertTrue(!PEAR::isError($mailboxes), 'Can not list mailboxes');
}
public function testSelectMailbox()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
foreach ($mailboxes as $mailbox) {
$result = $this->fixture->selectMailbox($mailbox);
$this->assertTrue(!PEAR::isError($result), 'Can not select mailbox '.$mailbox);
}
$this->logout();
}
// examineMailbox needs some messages for testing
public function testRenameMailbox()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
// print_r($mailboxes);
foreach ($mailboxes as $mailbox) {
if (in_array($mailbox, $this->reservedFolders)) {
continue;
}
$result = $this->fixture->renameMailbox($mailbox, $mailbox.'renamed');
$this->assertTrue(!PEAR::isError($result), 'Can not rename mailbox '.$mailbox);
}
$mailboxes_new = $this->fixture->getMailboxes();
for ($i=0; $i < sizeof($mailboxes_new); $i++) {
if (in_array($mailboxes[$i], $this->reservedFolders)) {
continue;
}
$this->assertTrue(($mailboxes[$i].'renamed' == $mailboxes_new[$i]), 'Mailbox '.$mailboxes[$i].' not renamed');
}
// print_r($mailboxes_new);
$this->logout();
}
public function testMailboxExist()
{
$this->login();
// this mailbox name must not exist before
$mailboxname = 'INBOX'.$this->delimiter.'testMailboxExistöäüß';
$this->fixture->deleteMailbox($mailboxname);
$result = $this->fixture->mailboxExist($mailboxname);
$this->assertFalse($result, 'Mailbox should NOT exist');
$result = $this->fixture->createMailbox($mailboxname);
$this->assertTrue(!PEAR::isError($result), 'Can not create mailbox');
$result = $this->fixture->mailboxExist($mailboxname);
$this->assertTrue($result, 'Mailbox should exist');
$result = $this->fixture->deleteMailbox($mailboxname);
$this->assertTrue($result, 'Can not delete Mailbox');
$this->logout();
}
public function testDeleteMailbox()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
// print_r($mailboxes);
foreach ($mailboxes as $mailbox) {
if (in_array($mailbox, $this->reservedFolders)) {
continue;
}
$result = $this->fixture->deleteMailbox($mailbox);
$this->assertTrue(!PEAR::isError($result), 'Can not delete mailbox '.$mailbox);
}
// print_r($this->fixture->getMailboxes());
$this->logout();
}
public function testGetMailboxSize()
{
$this->login();
$mailboxes = $this->fixture->getMailboxes();
foreach ($mailboxes as $mailbox) {
$result = $this->fixture->getMailboxSize($mailbox);
// print_r($result);
$this->assertTrue(!PEAR::isError($result), 'Can not get size for mailbox '.$mailbox);
}
$this->logout();
}
///
/// suscribing tests
///
public function testSubscribeMailbox()
{
$this->login();
$this->fixture->createMailbox('INBOX'.$this->delimiter.'testSubscribe');
$result = $this->fixture->subscribeMailbox('INBOX'.$this->delimiter.'testSubscribe');
$this->assertTrue(!PEAR::isError($result), 'Can not subscribe Mailbox');
$this->logout();
}
public function testListsubscribedMailboxes()
{
$this->login();
$this->fixture->createMailbox('INBOX'.$this->delimimter.'testSubscribe');
$this->fixture->subscribeMailbox('INBOX');
$this->fixture->subscribeMailbox('INBOX'.$this->delimiter.'testSubscribe');
$subscribed = $this->fixture->listsubscribedMailboxes();
//print_r($subscribed);
$this->logout();
$this->assertTrue(!PEAR::isError($subscribed), 'Can not list subscribed mailboxes');
}
public function testUnsubscribeMailbox()
{
$this->login();
$subscribed = $this->fixture->listsubscribedMailboxes();
// print_r($subscribed);
foreach ($subscribed as $mailbox) {
if ($mailbox == 'INBOX') {
continue;
}
$result = $this->fixture->unsubscribeMailbox($mailbox);
$this->assertTrue(!PEAR::isError($result), 'Can not unsubscribe mailbox '.$mailbox);
}
// print_r($this->fixture->listsubscribedMailboxes());
$this->logout();
}
public function testGetStorageQuotaRoot()
{
$this->login();
if (!$this->fixture->hasCapability('QUOTA')) {
return;
}
$this->fixture->selectMailbox('INBOX');
$result = $this->fixture->getStorageQuotaRoot();
$this->assertTrue(!PEAR::isError($result), 'Can not get StorageQuotaRoot');
$this->logout();
}
public function testGetACL()
{
$this->login();
if (!$this->fixture->hasCapability('ACL')) {
return;
}
$result = $this->fixture->getACL();
$this->assertTrue(!PEAR::isError($result), 'Can not get ACL');
$this->logout();
}
public function testGetHierarchyDelimiter()
{
$this->login();
$result = $this->fixture->getHierarchyDelimiter();
$this->assertTrue(!PEAR::isError($result), 'Can not get Hierarchy Delimiter');
$this->logout();
}
}
?>
|