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_multiselect_test extends BureaucracyauTest
12{
13
14    public function dataProvider()
15    {
16        return [
17            [
18                'fruits: @@multiSelectLabel@@',
19                'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges',
20                ['Peaches','Apples'],
21                'fruits: Peaches, Apples',
22                [],
23                'default separator',
24            ],
25            [
26                'fruits: @@multiSelectLabel(;)@@',
27                'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges',
28                ['Peaches','Apples'],
29                'fruits: Peaches;Apples',
30                [],
31                'custom separator',
32            ],
33        ];
34    }
35
36    /**
37     * @dataProvider dataProvider
38     *
39     * @param string $templateSyntax
40     * @param string $formSyntax
41     * @param        $postedValue
42     * @param string $expectedWikiText
43     * @param string $expectedValidationErrors
44     * @param string $msg
45     *
46     */
47    public function test_field_multiselect_submit(
48        $templateSyntax,
49        $formSyntax,
50        $postedValue,
51        $expectedWikiText,
52        $expectedValidationErrors,
53        $msg
54    ) {
55        $actualValidationErrors = [];
56
57        $actualWikiText = parent::send_form_action_template(
58            $formSyntax,
59            $templateSyntax,
60            $actualValidationErrors,
61            $postedValue
62        );
63
64        $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
65        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
66    }
67
68    public function test_field_multiselect_render()
69    {
70        $formSyntax = 'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges';
71        $instr = p_get_instructions("<form>\n$formSyntax\n</form>");
72
73        $actualHTML = p_render('xhtml', $instr, $info);
74
75        $expectedFieldHTML = '<label><span>multiSelectLabel <sup>*</sup></span> <select name="bureaucracyau[0][]" multiple="multiple">
76<option value="Peaches" selected="selected">Peaches</option><option value="Apples">Apples</option><option value="Oranges" selected="selected">Oranges</option>
77</select></label>';
78        $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML;
79        $this->assertEquals(trim($expectedHTML), trim($actualHTML));
80    }
81}
82