Skip to content

Commit

Permalink
Adding IMAP tests (PHP 5.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
odoucet committed Nov 23, 2009
1 parent eab96b6 commit db8c6d5
Show file tree
Hide file tree
Showing 19 changed files with 1,018 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/imap/tests/imap_body.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ imap_body();
echo "Checking with incorrect parameter type\n";
imap_body('');
imap_body(false);
require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
imap_body($stream_id);
imap_body($stream_id,-1);
imap_body($stream_id,1,-1);

//Access not existing
var_dump(imap_body($stream_id, 999, FT_UID));

imap_close($stream_id);

?>
--EXPECTF--
Checking with no parameters
Expand All @@ -25,3 +37,12 @@ Checking with incorrect parameter type
Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_body(): Bad message number in %s on line %d

Warning: imap_body(): invalid value for the options parameter in %s on line %d

Warning: imap_body(): Bad message number in %s on line %d
bool(false)
70 changes: 70 additions & 0 deletions ext/imap/tests/imap_fetchstructure_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
imap_fetchstructure() function : basic functionality
--CREDITS--
Olivier Doucet
--SKIPIF--
<?php
require_once(dirname(__FILE__).'/skipif.inc');
?>
--FILE--
<?php
echo "Checking with no parameters\n";
imap_fetchstructure();

echo "Checking with incorrect parameter type\n";
imap_fetchstructure('');
imap_fetchstructure(false);

require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);

imap_fetchstructure($stream_id);
imap_fetchstructure($stream_id,0);

$z = imap_fetchstructure($stream_id,1);


$fields = array('type','encoding','ifsubtype','subtype',
'ifdescription','lines','bytes','parameters');

foreach ($fields as $key) {
var_dump(isset($z->$key));
}
var_dump($z->type);
var_dump($z->encoding);
var_dump($z->bytes);
var_dump($z->lines);
var_dump(is_object($z->parameters));

imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
?>
--EXPECTF--
Checking with no parameters

Warning: imap_fetchstructure() expects at least 2 parameters, 0 given in %s on line %d
Checking with incorrect parameter type

Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created

Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
int(%d)
int(%d)
int(%d)
int(%d)
bool(true)
7 changes: 7 additions & 0 deletions ext/imap/tests/imap_gc_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ echo "Checking with incorrect parameter type\n";
imap_gc('', false);
imap_gc(false, false);

require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
imap_gc($stream_id, -1);

?>
--EXPECTF--
Checking with no parameters
Expand All @@ -26,3 +31,5 @@ Checking with incorrect parameter type
Warning: imap_gc() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d

Warning: imap_gc() expects parameter 1 to be resource, boolean given in %s on line %d

Warning: imap_gc(): invalid value for the flags parameter in %s on line %d
68 changes: 68 additions & 0 deletions ext/imap/tests/imap_getsubscribed_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--TEST--
imap_getsubscribed() function : basic functionality
--CREDITS--
Olivier Doucet
--SKIPIF--
<?php
require_once(dirname(__FILE__).'/skipif.inc');
?>
--FILE--
<?php
echo "Checking with no parameters\n";
imap_getsubscribed();

echo "Checking with incorrect parameter type\n";
imap_getsubscribed('');
imap_getsubscribed(false);

require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());

imap_getsubscribed($stream_id);
imap_getsubscribed($stream_id,$default_mailbox);
var_dump(imap_getsubscribed($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));


echo "Checking OK\n";

$newbox = $default_mailbox . "." . $mailbox_prefix;

imap_createmailbox($stream_id, $newbox);
imap_subscribe($stream_id, $newbox);

$z = imap_getsubscribed($stream_id,$default_mailbox,'*');

var_dump(is_array($z));
var_dump($z[0]);

imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
?>
--EXPECTF--
Checking with no parameters

Warning: imap_getsubscribed() expects exactly 3 parameters, 0 given in %s on line %d
Checking with incorrect parameter type

Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d

Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d

Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d

Warning: imap_getsubscribed() expects exactly 3 parameters, 2 given in %s on line %d
bool(false)
Checking OK
bool(true)
object(stdClass)#%d (%d) {
[%sname"]=>
string(%d) "{%s}%s"
[%sattributes"]=>
int(%d)
[%sdelimiter"]=>
string(%d) "%s"
}
129 changes: 129 additions & 0 deletions ext/imap/tests/imap_headerinfo_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
--TEST--
imap_headerinfo() function : basic functionality
--CREDITS--
Olivier Doucet
--SKIPIF--
<?php
require_once(dirname(__FILE__).'/skipif.inc');
?>
--FILE--
<?php

require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);

$z = imap_headerinfo($stream_id, 1);

$fields = array ('toaddress','to','fromaddress','from',
'reply_toaddress','reply_to',
'senderaddress', 'sender',
'subject','Subject',
'Recent','Unseen','Flagged','Answered','Deleted','Draft',
'Msgno','MailDate','Size','udate');

echo "Check general fields\n";
foreach ($fields as $key) {
var_dump(isset($z->$key));
}

echo "Check type\n";
var_dump($z->toaddress);
var_dump($z->fromaddress);
var_dump($z->reply_toaddress);
var_dump($z->senderaddress);
var_dump($z->subject);
var_dump($z->Subject);

if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
echo "Recent: OK";
} else {
echo "Recent: error: ".$z->Recent;
}
echo "\n";

if ($z->Unseen == 'U' || $z->Unseen == ' ') {
echo "Unseen: OK";
} else {
echo "Unseen: error: ".$z->Unseen;
}
echo "\n";

if ($z->Flagged == 'F' || $z->Flagged == ' ') {
echo "Flagged: OK";
} else {
echo "Flagged: error: ".$z->Flagged;
}
echo "\n";

if ($z->Answered == 'A' || $z->Answered == ' ') {
echo "Answered: OK";
} else {
echo "Answered: error";
}
echo "\n";

if ($z->Deleted == 'D' || $z->Deleted == ' ') {
echo "Deleted: OK";
} else {
echo "Deleted: error";
}
echo "\n";

if ($z->Draft == 'X' || $z->Draft == ' ') {
echo "Draft: OK";
} else {
echo "Draft: error";
}
echo "\n";

var_dump($z->Msgno);
var_dump($z->Size);
var_dump($z->udate);

imap_close($stream_id);

?>
--CLEAN--
<?php
require_once('clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
Check general fields
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Check type
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
Recent: OK
Unseen: OK
Flagged: OK
Answered: OK
Deleted: OK
Draft: OK
string(%d) "%s"
string(%d) "%d"
int(%d)
36 changes: 36 additions & 0 deletions ext/imap/tests/imap_headerinfo_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
imap_headerinfo() incorrect parameter count
--CREDITS--
Olivier Doucet
--SKIPIF--
<?php
require_once(dirname(__FILE__).'/skipif.inc');
?>
--FILE--
<?php
echo "Checking with no parameters\n";
imap_headerinfo();

echo "Checking with incorrect parameter type\n";
imap_headerinfo('');
imap_headerinfo(false);

require_once(dirname(__FILE__).'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());

imap_headerinfo($stream_id);

imap_close($stream_id);
?>
--EXPECTF--
Checking with no parameters

Warning: imap_headerinfo() expects at least 2 parameters, 0 given in %s on line %d
Checking with incorrect parameter type

Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d

Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d
Loading

0 comments on commit db8c6d5

Please sign in to comment.