diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-05-24 18:04:18 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-05-24 18:04:18 +0200 |
commit | c65980879a990e6d02a8ab262b014e670f314477 (patch) | |
tree | 976065c2fe52760bc69977b9c9d668af0e30c78d /tests/SelectFieldTest.php | |
parent | ae72f1b2f0c73ded5277300f0d15914e6e10ecae (diff) | |
download | gigologadmin-c65980879a990e6d02a8ab262b014e670f314477.tar.gz gigologadmin-c65980879a990e6d02a8ab262b014e670f314477.tar.bz2 gigologadmin-c65980879a990e6d02a8ab262b014e670f314477.zip |
Add function to generate selection boxes.
Diffstat (limited to 'tests/SelectFieldTest.php')
-rw-r--r-- | tests/SelectFieldTest.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/SelectFieldTest.php b/tests/SelectFieldTest.php new file mode 100644 index 0000000..1c1a8c2 --- /dev/null +++ b/tests/SelectFieldTest.php @@ -0,0 +1,53 @@ +<?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="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="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="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); + } +} |