Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1365 from splitbrain/blank
add convenience function for empty check without 0
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
class common_blank_test extends DokuWikiTest { | ||
|
||
private $nope; | ||
|
||
function test_blank() { | ||
$tests = array( | ||
// these are not blank | ||
array('string', false), | ||
array(1, false), | ||
array(1.0, false), | ||
array(0xff, false), | ||
array(array('something'), false), | ||
|
||
// these aren't either! | ||
array('0', false), | ||
array(' ', false), | ||
array('0.0', false), | ||
array(0, false), | ||
array(0.0, false), | ||
array(0x00, false), | ||
array(true, false), | ||
|
||
// but these are | ||
array('', true), | ||
array(array(), true), | ||
array(null, true), | ||
array(false, true), | ||
array("\0", true) | ||
); | ||
|
||
foreach($tests as $test) { | ||
$this->assertEquals($test[1], blank($test[0]), "using " . var_export($test[0], true)); | ||
} | ||
} | ||
|
||
function test_trim() { | ||
$whitespace = " \t\r\n"; | ||
$this->assertFalse(blank($whitespace), "using default \$trim value"); | ||
$this->assertFalse(blank($whitespace, false), "using \$trim = false"); | ||
$this->assertTrue(blank($whitespace, true), "using \$trim = true"); | ||
} | ||
|
||
function test_undefined() { | ||
$undef = array(); | ||
$this->assertTrue(blank($var), "using undefined/unitialised variable"); | ||
$this->assertTrue(blank($undef['nope']), "using undefined array index"); | ||
$this->assertTrue(blank($this->nope), "using unset object property"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters