Skip to content

Commit e780773

Browse files
author
Zoe Slattery
committed
Miscellaneous tests for ext/imap
1 parent 3c1bcc2 commit e780773

24 files changed

+2270
-0
lines changed

ext/imap/tests/imap_8bit_basic.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Test imap_8bit() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
extension_loaded('imap') or die('skip imap extension not available in this build');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : string imap_8bit ( string $string )
10+
* Description: Convert an 8bit string to a quoted-printable string.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing imap_8bit() : basic functionality ***\n";
15+
16+
var_dump(imap_8bit("String with CRLF at end \r\n"));
17+
//NB this appears to be a bug in cclient; a space at end of string should be encoded as =20
18+
var_dump(imap_8bit("String with space at end "));
19+
var_dump(imap_8bit("String with tabs \t\t in middle"));
20+
var_dump(imap_8bit("String with tab at end \t"));
21+
var_dump(imap_8bit("\x00\x01\x02\x03\x04\xfe\xff\x0a\x0d"));
22+
23+
?>
24+
===Done===
25+
--EXPECT--
26+
*** Testing imap_8bit() : basic functionality ***
27+
string(28) "String with CRLF at end=20
28+
"
29+
string(25) "String with space at end "
30+
string(33) "String with tabs =09=09 in middle"
31+
string(26) "String with tab at end =09"
32+
string(27) "=00=01=02=03=04=FE=FF=0A=0D"
33+
===Done===

ext/imap/tests/imap_alerts_error.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test imap_alerts() function : error conditions
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__).'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : array imap_alerts(void)
10+
* Description: Returns an array of all IMAP alerts that have been generated since the last page load or since the last imap_alerts() call, whichever came last. The alert stack is cleared after imap_alerts() is called.
11+
* Source code: ext/imap/php_imap.c
12+
* Alias to functions:
13+
*/
14+
15+
echo "*** Testing imap_alerts() : error conditions ***\n";
16+
17+
// One argument
18+
echo "\n-- Testing imap_alerts() function with one argument --\n";
19+
$extra_arg = 10;;
20+
var_dump( imap_alerts($extra_arg) );
21+
22+
?>
23+
===DONE===
24+
--EXPECTF--
25+
*** Testing imap_alerts() : error conditions ***
26+
27+
-- Testing imap_alerts() function with one argument --
28+
29+
Warning: Wrong parameter count for imap_alerts() in %s on line %d
30+
NULL
31+
===DONE===

ext/imap/tests/imap_append_basic.phpt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
--TEST--
2+
Test imap_append() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__).'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options ] )
10+
* Description: Append a string message to a specified mailbox.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing imap_append() : basic functionality ***\n";
15+
16+
require_once(dirname(__FILE__).'/imap_include.inc');
17+
18+
echo "Create a new mailbox for test\n";
19+
$imap_stream = setup_test_mailbox("", 0);
20+
if (!is_resource($imap_stream)) {
21+
exit("TEST FAILED: Unable to create test mailbox\n");
22+
}
23+
24+
$mb_details = imap_mailboxmsginfo($imap_stream);
25+
echo "Add a couple of msgs to new mailbox " . $mb_details->Mailbox . "\n";
26+
var_dump(imap_append($imap_stream, $mb_details->Mailbox
27+
, "From: webmaster@something.com\r\n"
28+
. "To: info@something.com\r\n"
29+
. "Subject: Test message\r\n"
30+
. "\r\n"
31+
. "this is a test message, please ignore\r\n"
32+
));
33+
34+
var_dump(imap_append($imap_stream, $mb_details->Mailbox
35+
, "From: webmaster@something.com\r\n"
36+
. "To: info@something.com\r\n"
37+
. "Subject: Another test\r\n"
38+
. "\r\n"
39+
. "this is another test message, please ignore it too!!\r\n"
40+
));
41+
42+
$check = imap_check($imap_stream);
43+
echo "Msg Count after append : ". $check->Nmsgs . "\n";
44+
45+
echo "List the msg headers\n";
46+
var_dump(imap_headers($imap_stream));
47+
48+
imap_close($imap_stream);
49+
?>
50+
===Done===
51+
--CLEAN--
52+
<?php
53+
require_once('clean.inc');
54+
?>
55+
--EXPECTF--
56+
*** Testing imap_append() : basic functionality ***
57+
Create a new mailbox for test
58+
Create a temporary mailbox and add 0 msgs
59+
.. mailbox '%s' created
60+
Add a couple of msgs to new mailbox {%s}INBOX.%s
61+
bool(true)
62+
bool(true)
63+
Msg Count after append : 2
64+
List the msg headers
65+
array(2) {
66+
[0]=>
67+
string(%d) "%w%s 1)%s webmaster@something. Test message (%d chars)"
68+
[1]=>
69+
string(%d) "%w%s 2)%s webmaster@something. Another test (%d chars)"
70+
}
71+
===Done===
72+

ext/imap/tests/imap_base64_basic.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test imap_base64() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
extension_loaded('imap') or die('skip imap extension not available in this build');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : string imap_base64 ( string $text )
10+
* Description: Decode BASE64 encoded text.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing imap_base64() : basic functionality ***\n";
15+
16+
$str = b'This is an example string to be base 64 encoded';
17+
$base64 = base64_encode($str);
18+
if (imap_base64($base64) == $str) {
19+
echo "TEST PASSED\n";
20+
} else {
21+
echo "TEST FAILED";
22+
}
23+
24+
$str = b'!£$%^&*()_+-={][];;@~#?/>.<,';
25+
$base64 = base64_encode($str);
26+
if (imap_base64($base64) == $str) {
27+
echo "TEST PASSED\n";
28+
} else {
29+
echo "TEST FAILED";
30+
}
31+
32+
$hex = b'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
33+
$base64 = base64_encode($hex);
34+
if (imap_base64($base64) == $hex) {
35+
echo "TEST PASSED\n";
36+
} else {
37+
echo "TEST FAILED";
38+
}
39+
40+
?>
41+
===Done===
42+
--EXPECT--
43+
*** Testing imap_base64() : basic functionality ***
44+
TEST PASSED
45+
TEST PASSED
46+
TEST PASSED
47+
===Done===

ext/imap/tests/imap_binary_basic.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
Test imap_binary() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
extension_loaded('imap') or die('skip imap extension not available in this build');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : string imap_binary ( string $string )
10+
* Description: Convert an 8bit string to a base64 string.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing imap_binary() : basic functionality ***\n";
15+
16+
echo "Encode as short string\n";
17+
$str = b'This is an example string to be base 64 encoded';
18+
$base64 = imap_binary($str);
19+
var_dump(bin2hex($base64));
20+
21+
echo "Encode a string which results in more than 60 charters of output\n";
22+
$str = b'This is a long string with results in more than 60 characters of output';
23+
$base64 = imap_binary($str);
24+
var_dump(bin2hex($base64));
25+
26+
echo "Encode a string with special characters\n";
27+
$str = b'_+-={][];;@~#?/>.<,';
28+
$base64 = imap_binary($str);
29+
var_dump(bin2hex($base64));
30+
31+
echo "Encode some hexadecimal data\n";
32+
$hex = b'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
33+
$base64 = imap_binary($hex);
34+
var_dump(bin2hex($base64));
35+
36+
?>
37+
===Done===
38+
--EXPECTF--
39+
*** Testing imap_binary() : basic functionality ***
40+
Encode as short string
41+
%string|unicode%(136) "5647687063794270637942686269426c654746746347786c49484e30636d6c755a794230627942695a53426959584e6c49445930494756755932396b0d0a5a57513d0d0a"
42+
Encode a string which results in more than 60 charters of output
43+
%string|unicode%(200) "56476870637942706379426849477876626d6367633352796157356e4948647064476767636d567a64577830637942706269427462334a6c4948526f0d0a595734674e6a416759326868636d466a64475679637942765a694276645852776458513d0d0a"
44+
Encode a string with special characters
45+
%string|unicode%(60) "5879737450587464573130374f30422b497a3876506934384c413d3d0d0a"
46+
Encode some hexadecimal data
47+
%string|unicode%(144) "65444177584867774d5678344d444a636544417a584867774e4678344d445663654441325848684751567834526b4a6365455a4458486847524678340d0a526b566365455a470d0a"
48+
===Done===

ext/imap/tests/imap_body_basic.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Test imap_body() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__).'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : string imap_body ( resource $imap_stream , int $msg_number [, int $options ] )
10+
* Description: Read the message body.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing imap_body() : basic functionality ***\n";
15+
16+
require_once(dirname(__FILE__).'/imap_include.inc');
17+
18+
echo "Create a new mailbox for test\n";
19+
$imap_stream = setup_test_mailbox("", 1);
20+
if (!is_resource($imap_stream)) {
21+
exit("TEST FAILED: Unable to create test mailbox\n");
22+
}
23+
24+
$check = imap_check($imap_stream);
25+
echo "Msg Count in new mailbox: ". $check->Nmsgs . "\n";
26+
27+
// show body for msg 1
28+
var_dump(imap_body($imap_stream, 1));
29+
30+
imap_close($imap_stream);
31+
?>
32+
===Done===
33+
--CLEAN--
34+
<?php
35+
require_once('clean.inc');
36+
?>
37+
--EXPECTF--
38+
*** Testing imap_body() : basic functionality ***
39+
Create a new mailbox for test
40+
Create a temporary mailbox and add 1 msgs
41+
.. mailbox '%s' created
42+
Msg Count in new mailbox: 1
43+
string(%d) "1: this is a test message, please ignore%a"
44+
===Done===
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
--TEST--
2+
Test imap_bodystruct() function : basic functionality
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__).'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
/* Prototype : object imap_bodystruct ( resource $imap_stream , int $msg_number , string $section )
10+
* Description: Read the structure of a specified body section of a specific message.
11+
* Source code: ext/imap/php_imap.c
12+
*/
13+
14+
echo "*** Testing string imap_bodystruct : basic functionality ***\n";
15+
require_once(dirname(__FILE__).'/imap_include.inc');
16+
17+
echo "Create a new mailbox for test and add a multipart msgs\n";
18+
$imap_stream = setup_test_mailbox("", 1, $mailbox, "multipart");
19+
if (!is_resource($imap_stream)) {
20+
exit("TEST FAILED: Unable to create test mailbox\n");
21+
}
22+
23+
echo "\nGet and validate structure of body part 1\n";
24+
25+
$m = imap_bodystruct($imap_stream, 1, "1");
26+
27+
$mandatoryFields = array(
28+
'ifsubtype',
29+
'ifdescription',
30+
'ifid',
31+
'ifdisposition',
32+
'ifdparameters',
33+
'ifparameters',
34+
);
35+
36+
foreach($mandatoryFields as $mf)
37+
{
38+
if(isValid($m->$mf))
39+
{
40+
echo "$mf is 0 or 1\n";
41+
}
42+
else
43+
{
44+
echo "$mf FAIL\n";
45+
}
46+
}
47+
48+
if(is_array($m->parameters))
49+
{
50+
echo "parameters is an array\n";
51+
}
52+
53+
echo "\nTry to get part 4!\n";
54+
var_dump(imap_bodystruct($imap_stream, 1, "4"));
55+
56+
imap_close($imap_stream);
57+
58+
function isValid($param)
59+
{
60+
if(($param == 0) || ($param == 1))
61+
{
62+
$result=true;
63+
}
64+
else
65+
{
66+
$result=false;
67+
}
68+
return $result;
69+
}
70+
?>
71+
===Done===
72+
--CLEAN--
73+
<?php
74+
require_once('clean.inc');
75+
?>
76+
--EXPECTF--
77+
*** Testing string imap_bodystruct : basic functionality ***
78+
Create a new mailbox for test and add a multipart msgs
79+
Create a temporary mailbox and add 1 msgs
80+
.. mailbox '{localhost/norsh}INBOX.phpttest' created
81+
82+
Get and validate structure of body part 1
83+
ifsubtype is 0 or 1
84+
ifdescription is 0 or 1
85+
ifid is 0 or 1
86+
ifdisposition is 0 or 1
87+
ifdparameters is 0 or 1
88+
ifparameters is 0 or 1
89+
parameters is an array
90+
91+
Try to get part 4!
92+
bool(false)
93+
===Done===

0 commit comments

Comments
 (0)