Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
221
Merge Requests
221
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
876d410c
Commit
876d410c
authored
May 30, 2012
by
jhodgdon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1598588
by Niklas Fiekas:
PSR-0
conversion of mail tests
parent
44a8b09d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
86 deletions
+97
-86
core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php
...odules/system/lib/Drupal/system/Tests/Common/MailTest.php
+92
-0
core/modules/system/system.info
core/modules/system/system.info
+0
-1
core/modules/system/tests/mail.test
core/modules/system/tests/mail.test
+5
-85
No files found.
core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php
0 → 100644
View file @
876d410c
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\MailTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\Core\Mail\MailInterface
;
use
Drupal\simpletest\WebTestBase
;
/**
* Defines a mail class used for testing.
*/
class
MailTest
extends
WebTestBase
implements
MailInterface
{
/**
* The most recent message that was sent through the test case.
*
* We take advantage here of the fact that static variables are shared among
* all instance of the same class.
*/
private
static
$sent_message
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Mail system'
,
'description'
=>
'Performs tests on the pluggable mailing framework.'
,
'group'
=>
'Mail'
,
);
}
function
setUp
()
{
parent
::
setUp
(
array
(
'simpletest'
));
// Set MailTestCase (i.e. this class) as the SMTP library
variable_set
(
'mail_system'
,
array
(
'default-system'
=>
'Drupal\system\Tests\Common\MailTest'
));
}
/**
* Assert that the pluggable mail system is functional.
*/
public
function
testPluggableFramework
()
{
global
$language_interface
;
// Use MailTestCase for sending a message.
$message
=
drupal_mail
(
'simpletest'
,
'mail_test'
,
'testing@example.com'
,
$language_interface
);
// Assert whether the message was sent through the send function.
$this
->
assertEqual
(
self
::
$sent_message
[
'to'
],
'testing@example.com'
,
t
(
'Pluggable mail system is extendable.'
));
}
/**
* Test that message sending may be canceled.
*
* @see simpletest_mail_alter()
*/
public
function
testCancelMessage
()
{
global
$language
;
// Reset the class variable holding a copy of the last sent message.
self
::
$sent_message
=
NULL
;
// Send a test message that simpletest_mail_alter should cancel.
$message
=
drupal_mail
(
'simpletest'
,
'cancel_test'
,
'cancel@example.com'
,
$language
);
// Assert that the message was not actually sent.
$this
->
assertNull
(
self
::
$sent_message
,
'Message was canceled.'
);
}
/**
* Concatenate and wrap the e-mail body for plain-text mails.
*
* @see Drupal\Core\Mail\PhpMail
*/
public
function
format
(
array
$message
)
{
// Join the body array into one string.
$message
[
'body'
]
=
implode
(
"
\n\n
"
,
$message
[
'body'
]);
// Convert any HTML to plain-text.
$message
[
'body'
]
=
drupal_html_to_text
(
$message
[
'body'
]);
// Wrap the mail body for sending.
$message
[
'body'
]
=
drupal_wrap_mail
(
$message
[
'body'
]);
return
$message
;
}
/**
* Send function that is called through the mail system.
*/
public
function
mail
(
array
$message
)
{
self
::
$sent_message
=
$message
;
}
}
core/modules/system/system.info
View file @
876d410c
...
...
@@ -22,7 +22,6 @@ files[] = tests/form.test
files
[]
=
tests
/
image
.
test
files
[]
=
tests
/
installer
.
test
files
[]
=
tests
/
lock
.
test
files
[]
=
tests
/
mail
.
test
files
[]
=
tests
/
menu
.
test
files
[]
=
tests
/
module
.
test
files
[]
=
tests
/
pager
.
test
...
...
core/modules/system/tests/mail.test
View file @
876d410c
...
...
@@ -2,97 +2,17 @@
/**
* @file
*
Test the Drupal mailing system
.
*
Definition of Drupal\system\Tests\Common\HtmlToTextTest
.
*/
use
Drupal\Core\Mail\MailInterface
;
use
Drupal\simpletest\WebTestBase
;
/**
* Defines a mail class used for testing.
*/
class
MailTestCase
extends
WebTestBase
implements
MailInterface
{
/**
* The most recent message that was sent through the test case.
*
* We take advantage here of the fact that static variables are shared among
* all instance of the same class.
*/
private
static
$sent_message
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Mail system'
,
'description'
=>
'Performs tests on the pluggable mailing framework.'
,
'group'
=>
'Mail'
,
);
}
function
setUp
()
{
parent
::
setUp
(
array
(
'simpletest'
));
// Set MailTestCase (i.e. this class) as the SMTP library
variable_set
(
'mail_system'
,
array
(
'default-system'
=>
'MailTestCase'
));
}
/**
* Assert that the pluggable mail system is functional.
*/
public
function
testPluggableFramework
()
{
global
$language_interface
;
// Use MailTestCase for sending a message.
$message
=
drupal_mail
(
'simpletest'
,
'mail_test'
,
'testing@example.com'
,
$language_interface
);
namespace
Drupal\system\Tests\Common
;
// Assert whether the message was sent through the send function.
$this
->
assertEqual
(
self
::
$sent_message
[
'to'
],
'testing@example.com'
,
t
(
'Pluggable mail system is extendable.'
));
}
/**
* Test that message sending may be canceled.
*
* @see simpletest_mail_alter()
*/
public
function
testCancelMessage
()
{
global
$language
;
// Reset the class variable holding a copy of the last sent message.
self
::
$sent_message
=
NULL
;
// Send a test message that simpletest_mail_alter should cancel.
$message
=
drupal_mail
(
'simpletest'
,
'cancel_test'
,
'cancel@example.com'
,
$language
);
// Assert that the message was not actually sent.
$this
->
assertNull
(
self
::
$sent_message
,
'Message was canceled.'
);
}
/**
* Concatenate and wrap the e-mail body for plain-text mails.
*
* @see Drupal\Core\Mail\PhpMail
*/
public
function
format
(
array
$message
)
{
// Join the body array into one string.
$message
[
'body'
]
=
implode
(
"
\n\n
"
,
$message
[
'body'
]);
// Convert any HTML to plain-text.
$message
[
'body'
]
=
drupal_html_to_text
(
$message
[
'body'
]);
// Wrap the mail body for sending.
$message
[
'body'
]
=
drupal_wrap_mail
(
$message
[
'body'
]);
return
$message
;
}
/**
* Send function that is called through the mail system.
*/
public
function
mail
(
array
$message
)
{
self
::
$sent_message
=
$message
;
}
}
use
Drupal\simpletest\WebTestBase
;
/**
*
Unit t
ests for drupal_html_to_text().
*
T
ests for drupal_html_to_text().
*/
class
DrupalHtmlToTextTestCase
extends
WebTestBase
{
class
HtmlToTextTest
extends
WebTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'HTML to text conversion'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment