summaryrefslogtreecommitdiffstats
path: root/tests/SelectFieldTest.php
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-06-15 18:34:29 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-06-15 18:34:29 +0200
commit1a8155ea64352b0eaf088675d51547361f6f17a7 (patch)
tree7da669474e0896cefbec89a16b65413a7ed25cb1 /tests/SelectFieldTest.php
parentbfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8 (diff)
parent82c4a8f2c4e5acd80b813829cecc40f621da3b21 (diff)
downloadgigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.gz
gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.bz2
gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.zip
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
Diffstat (limited to 'tests/SelectFieldTest.php')
-rw-r--r--tests/SelectFieldTest.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/SelectFieldTest.php b/tests/SelectFieldTest.php
new file mode 100644
index 0000000..fb6c298
--- /dev/null
+++ b/tests/SelectFieldTest.php
@@ -0,0 +1,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);
+ }
+}