summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/_test/field_time.test.php
blob: b027d8c4f3fa614f02e23b050af26ffd79d08d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

namespace dokuwiki\plugin\bureaucracy\test;

/**
 * @group plugin_bureaucracy
 * @group plugins
 */
class bureaucracy_field_time_test extends BureaucracyTest
{

    public function dataProvider()
    {
        return [
            [
                'time:@@timeLabel@@',
                'time timeLabel',
                '10:32',
                'time:10:32',
                [],
                'valid time without seconds',
            ],
            [
                'time:@@timeLabel@@',
                'time timeLabel',
                '10:32:44',
                'time:10:32:44',
                [],
                'valid time with seconds',
            ],
            [
                'time:@@timeLabel@@',
                'time timeLabel',
                '1032',
                null,
                ['timeLabel'],
                'invalid time',
            ],
        ];
    }

    /**
     * @dataProvider dataProvider
     *
     * @param string   $templateSyntax
     * @param string   $formSyntax
     * @param string   $postedValue
     * @param string   $expectedWikiText
     * @param string[] $expectedValidationErrors
     * @param string   $msg
     */
    public function test_field_time_submit(
        $templateSyntax,
        $formSyntax,
        $postedValue,
        $expectedWikiText,
        $expectedValidationErrors,
        $msg
    ) {
        $actualValidationErrors = [];

        $actualWikiText = parent::send_form_action_template(
            $formSyntax,
            $templateSyntax,
            $actualValidationErrors,
            $postedValue
        );

        if (empty($expectedValidationErrors)) {
            $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
        }
        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
    }

    public function test_field_time_render()
    {
        $formSyntax = 'time "timeLabel"';
        $instr = p_get_instructions("<form>\n$formSyntax\n</form>");

        $actualHTML = p_render('xhtml', $instr, $info);

        $expectedFieldHTML = '<label><span>timeLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="timefield edit required" maxlength="8" required="required" /></label>';
        $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML;
        $this->assertEquals(trim($expectedHTML), trim($actualHTML));
    }
}