1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Webform module unit tests.
|
5
|
*/
|
6
|
class WebformUnitTestCase extends DrupalUnitTestCase {
|
7
|
|
8
|
/**
|
9
|
* {@inheritdoc}
|
10
|
*/
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => t('Webform unit tests'),
|
14
|
'description' => t('Unit tests for Webform functions.'),
|
15
|
'group' => t('Webform'),
|
16
|
);
|
17
|
}
|
18
|
|
19
|
/**
|
20
|
* The tests.
|
21
|
*/
|
22
|
public function test() {
|
23
|
require_once __DIR__ . '/../webform.module';
|
24
|
|
25
|
$test = webform_format_email_address('test@example.com', 'John Smith');
|
26
|
$sample = '"John Smith" <test@example.com>';
|
27
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() returns string for single name and email address.');
|
28
|
|
29
|
$test = webform_format_email_address('default', 'default');
|
30
|
$sample = '"' . webform_variable_get('webform_default_from_name') . '" <' . webform_variable_get('webform_default_from_address') . '>';
|
31
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() handles defaults.');
|
32
|
|
33
|
$test = webform_format_email_address('test@example.com', NULL);
|
34
|
$sample = 'test@example.com';
|
35
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() handles NULL name.');
|
36
|
|
37
|
$test = webform_format_email_address('test@example.com', 'John Smith', NULL, NULL, TRUE, FALSE);
|
38
|
$sample = ['"John Smith" <test@example.com>'];
|
39
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() returns array for single name and email address.');
|
40
|
|
41
|
$test = webform_format_email_address(['test1@example.com', 'test2@example.com'], 'John Smith');
|
42
|
$sample = '"John Smith" <test1@example.com>';
|
43
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() returns single string for multiple email addresses by default.');
|
44
|
|
45
|
$test = webform_format_email_address(['test1@example.com', 'test2@example.com'], ['John One', 'John Two'], NULL, NULL, TRUE, FALSE);
|
46
|
$sample = ['"John One" <test1@example.com>', '"John Two" <test2@example.com>'];
|
47
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() returns array for multiple email addresses when $single is FALSE.');
|
48
|
|
49
|
$test = webform_format_email_address(['test1@example.com', 'test2@example.com'], 'John One', NULL, NULL, TRUE, FALSE);
|
50
|
$sample = ['"John One" <test1@example.com>', '"John One" <test2@example.com>'];
|
51
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() repeats first name when more emails than names provided.');
|
52
|
|
53
|
$test = webform_format_email_address('test1@example.com, test2@example.com', 'John One', NULL, NULL, TRUE, FALSE);
|
54
|
$sample = ['"John One" <test1@example.com>', '"John One" <test2@example.com>'];
|
55
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() accepts multiple emails as comma-separated string.');
|
56
|
|
57
|
$node = (object) [
|
58
|
'webform' => [
|
59
|
'components' => [
|
60
|
1 => ['name' => 'Email component', 'type' => 'textfield'],
|
61
|
2 => ['name' => 'Name component', 'type' => 'textfield'],
|
62
|
],
|
63
|
],
|
64
|
];
|
65
|
$test = webform_format_email_address(1, 2, $node);
|
66
|
$sample = '"Value of Name component" <Value of "Email component">';
|
67
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() takes name and email from component names.');
|
68
|
|
69
|
$submission = (object) [
|
70
|
'data' => [
|
71
|
1 => ['test@example.com'],
|
72
|
2 => ['John Smith'],
|
73
|
],
|
74
|
];
|
75
|
$test = webform_format_email_address(1, 2, $node, $submission);
|
76
|
$sample = '"John Smith" <test@example.com>';
|
77
|
$this->assertIdentical($test, $sample, 'webform_format_email_address() takes name and email from submission values.');
|
78
|
}
|
79
|
|
80
|
}
|