summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php')
-rw-r--r--www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php b/www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php
new file mode 100644
index 00000000..7f56b605
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * @group GlobalFunctions
+ * @covers ::wfStringToBool
+ */
+class WfStringToBoolTest extends MediaWikiTestCase {
+
+ public function getTestCases() {
+ return [
+ [ 'true', true ],
+ [ 'on', true ],
+ [ 'yes', true ],
+ [ 'TRUE', true ],
+ [ 'YeS', true ],
+ [ 'On', true ],
+ [ '1', true ],
+ [ '+1', true ],
+ [ '01', true ],
+ [ '-001', true ],
+ [ ' 1', true ],
+ [ '-1 ', true ],
+ [ '', false ],
+ [ '0', false ],
+ [ 'false', false ],
+ [ 'NO', false ],
+ [ 'NOT', false ],
+ [ 'never', false ],
+ [ '!&', false ],
+ [ '-0', false ],
+ [ '+0', false ],
+ [ 'forget about it', false ],
+ [ ' on', false ],
+ [ 'true ', false ],
+ ];
+ }
+
+ /**
+ * @dataProvider getTestCases
+ * @param string $str
+ * @param bool $bool
+ */
+ public function testStr2Bool( $str, $bool ) {
+ if ( $bool ) {
+ $this->assertTrue( wfStringToBool( $str ) );
+ } else {
+ $this->assertFalse( wfStringToBool( $str ) );
+ }
+ }
+
+}