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
|
<?php
// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
use \EternalTerror\ViewHelpers;
final class SelectFieldTest extends WP_UnitTestCase
{
public function testEmptySelectField()
{
$res = ViewHelpers\select_field("fooselect");
$this->assertStringStartsWith('<select name="fooselect">', $res);
$this->assertStringEndsWith('</select>', $res);
}
public function testSelectFieldWithOneOption()
{
$res = ViewHelpers\select_field("fooselect", [[42, 'An option']]);
$this->assertStringStartsWith('<select name="fooselect">', $res);
$this->assertStringEndsWith('</select>', $res);
$this->assertStringContainsString('<option value="">Please select...</option>', $res);
$this->assertStringContainsString('<option value="42">An option</option>', $res);
}
public function testSelectFieldWithMultipleOption()
{
$opts = [[42, 'An option'], [666, 'Another option'], ["foo", 'A foo option']];
$res = ViewHelpers\select_field("fooselect", $opts);
$this->assertStringStartsWith('<select name="fooselect">', $res);
$this->assertStringEndsWith('</select>', $res);
$this->assertStringContainsString('<option value="">Please select...</option>', $res);
$this->assertStringContainsString('<option value="42">An option</option>', $res);
$this->assertStringContainsString('<option value="666">Another option</option>', $res);
$this->assertStringContainsString('<option value="foo">A foo option</option>', $res);
}
public function testSelectFieldWithSelectedOption()
{
$opts = [[42, 'An option'], [666, 'Another option'], ["foo", 'A foo option']];
$res = ViewHelpers\select_field("fooselect", $opts, 666);
$this->assertStringStartsWith('<select name="fooselect">', $res);
$this->assertStringEndsWith('</select>', $res);
$this->assertStringContainsString('<option value="">Please select...</option>', $res);
$this->assertStringContainsString('<option value="42">An option</option>', $res);
$this->assertStringContainsString('<option value="666" selected=\'selected\'>Another option</option>', $res);
$this->assertStringContainsString('<option value="foo">A foo option</option>', $res);
}
public function testSelectFieldWithCustomBlankSelectionText()
{
$opts = [[42, 'An option'], [666, 'Another option'], ["foo", 'A foo option']];
$res = ViewHelpers\select_field("fooselect", $opts, 666, "None");
$this->assertStringStartsWith('<select name="fooselect">', $res);
$this->assertStringEndsWith('</select>', $res);
$this->assertStringContainsString('<option value="">None</option>', $res);
$this->assertStringContainsString('<option value="42">An option</option>', $res);
$this->assertStringContainsString('<option value="666" selected=\'selected\'>Another option</option>', $res);
$this->assertStringContainsString('<option value="foo">A foo option</option>', $res);
}
}
|