1<?php
2
3namespace dokuwiki\plugin\bureaucracy\test;
4
5use \Doku_Form;
6
7/**
8 * @group plugin_bureaucracyau
9 * @group plugins
10 */
11class bureaucracyau_field_email_test extends BureaucracyTest
12{
13
14    public function dataProvider()
15    {
16        return [
17            [
18                'Mail: @@emailLabel@@',
19                'valid@example.com',
20                'Mail: valid@example.com',
21                [],
22                'valid email',
23            ],
24            [
25                'Mail: @@emailLabel@@',
26                '@MAIL@',
27                'Mail: @MAIL@',
28                [],
29                '@MAIL@ placeholder for user\'s email adress',
30            ],
31            [
32                'Mail: @@emailLabel@@',
33                'invalid@example',
34                'Mail: invalid@example',
35                [],
36                'local email addresses are allowed',
37            ],
38            [
39                'Mail: @@emailLabel@@',
40                'invalid[at]example.com',
41                null,
42                ['emailLabel'],
43                'invalid email',
44            ],
45        ];
46    }
47
48    /**
49     * @dataProvider dataProvider
50     *
51     * @param string $templateSyntax
52     * @param        $postedValue
53     * @param string $expectedWikiText
54     * @param string $expectedValidationErrors
55     * @param string $msg
56     *
57     */
58    public function test_field_email_submit(
59        $templateSyntax,
60        $postedValue,
61        $expectedWikiText,
62        $expectedValidationErrors,
63        $msg
64    ) {
65        $actualValidationErrors = [];
66
67        $label = 'emailLabel';
68        $actualWikiText = parent::send_form_action_template(
69            "email \"$label\"",
70            $templateSyntax,
71            $actualValidationErrors,
72            $postedValue
73        );
74
75        if (empty($expectedValidationErrors)) {
76            $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
77        }
78        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
79    }
80
81    public function test_field_email_render()
82    {
83        $formSyntax = 'email emailLabel';
84        $instr = p_get_instructions("<form>\n$formSyntax\n</form>");
85
86        $actualHTML = p_render('xhtml', $instr, $info);
87
88        $expectedFieldHTML = '<label><span>emailLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="edit required" required="required" /></label>';
89        $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML;
90        $this->assertEquals(trim($expectedHTML), trim($actualHTML));
91    }
92}
93