Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
cc92aca7
Commit
cc92aca7
authored
12 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
some first tests for the Mailer class
parent
3891d3ec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
_test/tests/inc/mailer.test.php
+94
-0
94 additions, 0 deletions
_test/tests/inc/mailer.test.php
with
94 additions
and
0 deletions
_test/tests/inc/mailer.test.php
0 → 100644
+
94
−
0
View file @
cc92aca7
<?php
/**
* Extends the mailer class to expose internal variables for testing
*/
class
TestMailer
extends
Mailer
{
public
function
prop
(
$name
){
return
$this
->
$name
;
}
}
class
mailer_test
extends
DokuWikiTest
{
function
test_userheader
(){
$mail
=
new
TestMailer
();
$headers
=
$mail
->
prop
(
'headers'
);
$this
->
assertArrayNotHasKey
(
'X-Dokuwiki-User'
,
$headers
);
$_SERVER
[
'REMOTE_USER'
]
=
'andi'
;
$mail
=
new
TestMailer
();
$headers
=
$mail
->
prop
(
'headers'
);
$this
->
assertArrayHasKey
(
'X-Dokuwiki-User'
,
$headers
);
}
function
test_setHeader
(){
$mail
=
new
TestMailer
();
// check existance of default headers
$headers
=
$mail
->
prop
(
'headers'
);
$this
->
assertArrayHasKey
(
'X-Mailer'
,
$headers
);
$this
->
assertArrayHasKey
(
'X-Dokuwiki-Title'
,
$headers
);
$this
->
assertArrayHasKey
(
'X-Dokuwiki-Server'
,
$headers
);
$this
->
assertArrayHasKey
(
'X-Auto-Response-Suppress'
,
$headers
);
$this
->
assertArrayHasKey
(
'List-Id'
,
$headers
);
// set a bunch of test headers
$mail
->
setHeader
(
'test-header'
,
'bla'
);
$mail
->
setHeader
(
'to'
,
'A valid ASCII name <test@example.com>'
);
$mail
->
setHeader
(
'from'
,
"Thös ne
\n
eeds
\x00
serious cleaning$§%."
);
$mail
->
setHeader
(
'bad'
,
"Thös ne
\n
eeds
\x00
serious cleaning$§%."
,
false
);
$mail
->
setHeader
(
"weird
\n
*+
\x00
foo.-_@bar?"
,
'now clean'
);
// are they set?
$headers
=
$mail
->
prop
(
'headers'
);
$this
->
assertArrayHasKey
(
'Test-Header'
,
$headers
);
$this
->
assertEquals
(
'bla'
,
$headers
[
'Test-Header'
]);
$this
->
assertArrayHasKey
(
'To'
,
$headers
);
$this
->
assertEquals
(
'A valid ASCII name <test@example.com>'
,
$headers
[
'To'
]);
$this
->
assertArrayHasKey
(
'From'
,
$headers
);
$this
->
assertEquals
(
'Ths neeedsserious cleaning.'
,
$headers
[
'From'
]);
$this
->
assertArrayHasKey
(
'Bad'
,
$headers
);
$this
->
assertEquals
(
"Thös ne
\n
eeds
\x00
serious cleaning$§%."
,
$headers
[
'Bad'
]);
$this
->
assertArrayHasKey
(
'Weird+foo.-_@bar'
,
$headers
);
// unset a header again
$mail
->
setHeader
(
'test-header'
,
''
);
$headers
=
$mail
->
prop
(
'headers'
);
$this
->
assertArrayNotHasKey
(
'Test-Header'
,
$headers
);
}
function
test_simplemail
(){
global
$conf
;
$conf
[
'htmlmail'
]
=
0
;
$mail
=
new
TestMailer
();
$mail
->
to
(
'test@example.com'
);
$mail
->
setBody
(
'A test mail in ASCII'
);
$dump
=
$mail
->
dump
();
$this
->
assertNotRegexp
(
'/Content-Type: multipart/'
,
$dump
);
$this
->
assertRegexp
(
'#Content-Type: text/plain; charset=UTF-8#'
,
$dump
);
$this
->
assertRegexp
(
'/'
.
base64_encode
(
'A test mail in ASCII'
)
.
'/'
,
$dump
);
$conf
[
'htmlmail'
]
=
1
;
}
function
test_replacements
(){
$mail
=
new
TestMailer
();
$replacements
=
array
(
'@DATE@'
,
'@BROWSER@'
,
'@IPADDRESS@'
,
'@HOSTNAME@'
,
'@TITLE@'
,
'@DOKUWIKIURL@'
,
'@USER@'
,
'@NAME@'
,
'@MAIL@'
);
$mail
->
setBody
(
'A test mail in with replacements '
.
join
(
' '
,
$replacements
));
$text
=
$mail
->
prop
(
'text'
);
$html
=
$mail
->
prop
(
'html'
);
foreach
(
$replacements
as
$repl
){
$this
->
assertNotRegexp
(
"/
$repl
/"
,
$text
,
"
$repl
replacement still in text"
);
$this
->
assertNotRegexp
(
"/
$repl
/"
,
$html
,
"
$repl
replacement still in html"
);
}
}
}
//Setup VIM: ex: et ts=4 :
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment