wiki.techinc.nl/tests/phpunit/includes/GlobalFunctions/wfStringToBoolTest.php
Stanislav Malyshev 194acaa0e0 Expose string->bool conversion as function
There is code in several places in extensions which converts
setting or parameter string (such as "true", "yes", "false", "no")
to boolean. Since we already have the code that does in global
functions in wfStringToBool(), it makes sense to expose this code
and reuse it.

Change-Id: I88d98b012ff4bf14fd64a05a9135a6e75cf2d4e7
2017-11-15 06:57:40 +00:00

51 lines
944 B
PHP

<?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 ) );
}
}
}