1<?php
2
3namespace dokuwiki\plugin\bureaucracyau\test;
4
5use \Doku_Form;
6
7/**
8 * @group plugin_bureaucracyau
9 * @group plugins
10 */
11class bureaucracyau_field_hidden_test extends BureaucracyauTest
12{
13
14    public function dataProvider()
15    {
16        return [
17            [
18                'hidden:@@hiddenLabel@@',
19                'default value of the hidden field',
20                'default value of the hidden field',
21                'hidden:default value of the hidden field',
22                [],
23                'valid hidden',
24            ],
25        ];
26    }
27
28    /**
29     * @dataProvider dataProvider
30     *
31     * @param string $templateSyntax
32     * @param        $postedValue
33     * @param string $expectedWikiText
34     * @param string $expectedValidationErrors
35     * @param string $msg
36     *
37     */
38    public function test_field_hidden_submit(
39        $templateSyntax,
40        $defaultValue,
41        $postedValue,
42        $expectedWikiText,
43        $expectedValidationErrors,
44        $msg
45    ) {
46        $actualValidationErrors = [];
47
48        $label = 'hiddenLabel';
49        $actualWikiText = parent::send_form_action_template(
50            "hidden \"$label\" \"=$defaultValue\"",
51            $templateSyntax,
52            $actualValidationErrors,
53            $postedValue
54        );
55
56        if (empty($expectedValidationErrors)) {
57            $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
58        }
59        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
60    }
61
62    public function test_field_time_render()
63    {
64        $formSyntax = 'hidden hiddenLabel "=default value of the hidden field"';
65        $instr = p_get_instructions("<form>\n$formSyntax\n</form>");
66
67        $actualHTML = p_render('xhtml', $instr, $info);
68
69        $hiddenFormPrefix = '<form class="bureaucracyau__plugin" id="bureaucracyau__plugin1" enctype="multipart/form-data" method="post" action="" accept-charset="utf-8"><div class="no">
70<input type="hidden" name="sectok" value="" /><input type="hidden" name="bureaucracyau[$$id]" value="1" />';
71        $expectedFieldHTML = '<input type="hidden" name="bureaucracyau[0]" value="default value of the hidden field" />';
72        $hiddenFormSuffix = '</div></form>';
73        $expectedHTML = "$hiddenFormPrefix$expectedFieldHTML$hiddenFormSuffix";
74
75        $this->assertEquals(trim($expectedHTML), trim($actualHTML));
76    }
77}
78