MDL-52818 core: Added CFG->divertallemailsexcept config option

When $CFG->divertallemailsto is specified, this allows a list of email
or domain exceptions to be whitelisted enabling easier testing by groups
of testers who don't share a single email address.
This commit is contained in:
Brendan Heywood
2016-02-09 09:59:20 +00:00
committed by Dan Poltawski
parent 37f77a1b37
commit eca8cf67dc
3 changed files with 99 additions and 1 deletions
+67
View File
@@ -2644,6 +2644,73 @@ class core_moodlelib_testcase extends advanced_testcase {
$this->assertEventContextNotUsed($event);
}
public function diverted_emails_provider() {
return array(
'nodiverts' => array(
'divertallemailsto' => null,
'divertallemailsexcept' => null,
array(
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
),
false,
),
'alldiverts' => array(
'divertallemailsto' => '[email protected]',
'divertallemailsexcept' => null,
array(
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
),
true,
),
'alsodiverts' => array(
'divertallemailsto' => '[email protected]',
'divertallemailsexcept' => '@dev.com, fred(\+.*)[email protected]',
array(
'[email protected]',
'[email protected]',
'[email protected]',
),
true,
),
'divertsexceptions' => array(
'divertallemailsto' => '[email protected]',
'divertallemailsexcept' => '@dev.com, fred(\+.*)[email protected]',
array(
'[email protected]',
'[email protected]',
'[email protected]',
),
false,
),
);
}
/**
* @dataProvider diverted_emails_provider
*/
public function test_email_should_be_diverted($divertallemailsto, $divertallemailsexcept, $addresses, $expected) {
global $CFG;
$this->resetAfterTest();
$CFG->divertallemailsto = $divertallemailsto;
$CFG->divertallemailsexcept = $divertallemailsexcept;
foreach ($addresses as $address) {
$this->assertEquals($expected, email_should_be_diverted($address));
}
}
public function test_email_to_user() {
global $CFG;