-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve tests on
message_compose
hook.
- Loading branch information
Showing
2 changed files
with
99 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,48 +12,37 @@ | |
|
||
final class CustomFromTest extends TestCase | ||
{ | ||
const CONTAINS = 'custom_from_compose_contains'; | ||
const DISABLE = 'custom_from_preference_disable'; | ||
const RULES = 'custom_from_header_rules'; | ||
const SUBJECT = 'custom_from_compose_subject'; | ||
|
||
public static function storage_init_should_fetch_headers_provider(): array | ||
{ | ||
return array( | ||
array( | ||
array( | ||
'custom_from_compose_auto' => false | ||
), | ||
array('custom_from_compose_auto' => false), | ||
array(), | ||
'' | ||
), | ||
array( | ||
array( | ||
'custom_from_compose_auto' => true | ||
), | ||
array('custom_from_compose_auto' => true), | ||
array(), | ||
'bcc cc from to x-original-to' | ||
), | ||
array( | ||
array( | ||
'custom_from_header_rules' => 'header1=a;header2=b' | ||
), | ||
array(self::RULES => 'header1=a;header2=b'), | ||
array(), | ||
'header1 header2' | ||
), | ||
array( | ||
array( | ||
'custom_from_header_rules' => 'header=a', | ||
'custom_from_preference_disable' => true | ||
), | ||
array( | ||
'custom_from_compose_subject' => 'always' | ||
), | ||
array(self::RULES => 'header=a', self::DISABLE => true), | ||
array(self::SUBJECT => 'always'), | ||
'header' | ||
), | ||
array( | ||
array( | ||
'custom_from_header_rules' => 'header=a', | ||
'custom_from_preference_disable' => false | ||
), | ||
array( | ||
'custom_from_compose_subject' => 'always' | ||
), | ||
array(self::RULES => 'header=a', self::DISABLE => false), | ||
array(self::SUBJECT => 'always'), | ||
'header bcc cc from to x-original-to' | ||
) | ||
); | ||
|
@@ -75,29 +64,106 @@ public function test_storage_init_should_fetch_headers($config_values, $user_pre | |
public static function message_compose_should_set_state_provider(): array | ||
{ | ||
return array( | ||
// Subject rule "exact" should match address exactly | ||
array( | ||
array('to' => '[email protected]'), | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(), | ||
null, // TODO: assert [email protected] was matched | ||
), | ||
// Subject rule "exact" shouldn't match suffix | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(), | ||
null, | ||
), | ||
// Subject rule "prefix" should match address exactly | ||
array( | ||
array('to' => '[email protected]'), | ||
'[email protected]', | ||
) | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
null, // TODO: assert [email protected] was matched | ||
), | ||
// Subject rule "prefix" should match address by prefix | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
'[email protected]', | ||
), | ||
// Subject rule "prefix" should not match different user | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
null, | ||
), | ||
// Subject rule "domain" on custom header should match address by domain | ||
array( | ||
array('to' => '[email protected]', 'x-custom' => '[email protected]'), | ||
array(self::RULES => 'x-custom=d'), | ||
array(), | ||
'[email protected]' // TODO: assert [email protected] was matched | ||
), | ||
// Subject rule "domain" should not match different domain | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=d'), | ||
array(), | ||
null, | ||
), | ||
// Subject rule "other" should match anything | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=o'), | ||
array(), | ||
'[email protected]' // TODO: assert [email protected] was matched | ||
), | ||
// Subject rule is overridden by user prefrences | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(self::SUBJECT => 'domain'), | ||
'[email protected]' | ||
), | ||
// Contains constraint in configuration options matches address | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'match'), | ||
array(self::SUBJECT => 'domain'), | ||
'[email protected]' | ||
), | ||
// Contains constraint in configuration options rejects no match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'match'), | ||
array(self::SUBJECT => 'domain'), | ||
null | ||
), | ||
// Contains constraint in user preferences rejects no match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'other'), | ||
array(self::CONTAINS => 'match', self::SUBJECT => 'always'), | ||
null | ||
), | ||
); | ||
} | ||
|
||
#[DataProvider('message_compose_should_set_state_provider')] | ||
public function test_message_compose_should_set_state($message, $expected): void | ||
public function test_message_compose_should_set_state($message, $config_values, $user_prefs, $expected): void | ||
{ | ||
$identity1 = array('email' => '[email protected]', 'name' => 'Primary', 'standard' => '1'); | ||
$identity2 = array('email' => '[email protected]', 'name' => 'Secondary', 'standard' => '0'); | ||
$identity1 = array('email' => '[email protected]', 'name' => 'Alice', 'standard' => '0'); | ||
$identity2 = array('email' => '[email protected]', 'name' => 'Bob', 'standard' => '1'); | ||
$identity3 = array('email' => '[email protected]', 'name' => 'Carl', 'standard' => '0'); | ||
|
||
$id = 17; | ||
$uid = '42'; | ||
$rcmail = rcmail::mock(); | ||
$rcmail->mock_config(array()); | ||
$rcmail->mock_config($config_values); | ||
$rcmail->mock_message($uid, $message); | ||
$rcmail->mock_user(array($identity1, $identity2), array()); | ||
$rcmail->mock_user(array($identity1, $identity2, $identity3), $user_prefs); | ||
|
||
$plugin = self::create_plugin(); | ||
$plugin->message_compose(array('id' => $id, 'param' => array('uid' => $uid))); | ||
|