From c65980879a990e6d02a8ab262b014e670f314477 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 24 May 2021 18:04:18 +0200 Subject: Add function to generate selection boxes. --- tests/SelectFieldTest.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/SelectFieldTest.php (limited to 'tests/SelectFieldTest.php') 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 @@ + +// SPDX-FileCopyrightText: 2021 Harald Eilertsen +// +// 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('', $res); + } + + public function testSelectFieldWithOneOption() + { + $res = ViewHelpers\select_field("fooselect", [[42, 'An option']]); + $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); + } + + public function testSelectFieldWithMultipleOption() + { + $opts = [[42, 'An option'], [666, 'Another option'], ["foo", 'A foo option']]; + + $res = ViewHelpers\select_field("fooselect", $opts); + + $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + } + + public function testSelectFieldWithSelectedOption() + { + $opts = [[42, 'An option'], [666, 'Another option'], ["foo", 'A foo option']]; + + $res = ViewHelpers\select_field("fooselect", $opts, 666); + + $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + } +} -- cgit v1.2.3 From 9694c61f301989cdbbfd9e303e74b30812752cab Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 24 May 2021 19:33:07 +0200 Subject: Allow custom text for no selection in select_fields. --- tests/SelectFieldTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/SelectFieldTest.php') diff --git a/tests/SelectFieldTest.php b/tests/SelectFieldTest.php index 1c1a8c2..fb6c298 100644 --- a/tests/SelectFieldTest.php +++ b/tests/SelectFieldTest.php @@ -22,6 +22,7 @@ final class SelectFieldTest extends WP_UnitTestCase $res = ViewHelpers\select_field("fooselect", [[42, 'An option']]); $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); } @@ -33,6 +34,7 @@ final class SelectFieldTest extends WP_UnitTestCase $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); @@ -46,6 +48,21 @@ final class SelectFieldTest extends WP_UnitTestCase $this->assertStringStartsWith('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $res); + $this->assertStringContainsString('', $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('', $res); + $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); $this->assertStringContainsString('', $res); -- cgit v1.2.3