That mostly enables testing global functions Bug: T87781 Change-Id: Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
51 lines
948 B
PHP
51 lines
948 B
PHP
<?php
|
|
|
|
/**
|
|
* @group GlobalFunctions
|
|
* @covers ::wfStringToBool
|
|
*/
|
|
class WfStringToBoolTest extends MediaWikiUnitTestCase {
|
|
|
|
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 ) );
|
|
}
|
|
}
|
|
|
|
}
|