15b571377SAndreas Gohr<?php 25b571377SAndreas Gohr 35b571377SAndreas Gohrclass common_blank_test extends DokuWikiTest { 45b571377SAndreas Gohr 55b571377SAndreas Gohr private $nope; 65b571377SAndreas Gohr 75b571377SAndreas Gohr function test_blank() { 85b571377SAndreas Gohr $tests = array( 95b571377SAndreas Gohr // these are not blank 105b571377SAndreas Gohr array('string', false), 115b571377SAndreas Gohr array(1, false), 125b571377SAndreas Gohr array(1.0, false), 135b571377SAndreas Gohr array(0xff, false), 145b571377SAndreas Gohr array(array('something'), false), 155b571377SAndreas Gohr 165b571377SAndreas Gohr // these aren't either! 175b571377SAndreas Gohr array('0', false), 185b571377SAndreas Gohr array(' ', false), 195b571377SAndreas Gohr array('0.0', false), 205b571377SAndreas Gohr array(0, false), 215b571377SAndreas Gohr array(0.0, false), 225b571377SAndreas Gohr array(0x00, false), 235b571377SAndreas Gohr array(true, false), 245b571377SAndreas Gohr 255b571377SAndreas Gohr // but these are 265b571377SAndreas Gohr array('', true), 275b571377SAndreas Gohr array(array(), true), 285b571377SAndreas Gohr array(null, true), 295b571377SAndreas Gohr array(false, true), 305b571377SAndreas Gohr array("\0", true) 315b571377SAndreas Gohr ); 325b571377SAndreas Gohr 335b571377SAndreas Gohr foreach($tests as $test) { 345b571377SAndreas Gohr $this->assertEquals($test[1], blank($test[0]), "using " . var_export($test[0], true)); 355b571377SAndreas Gohr } 365b571377SAndreas Gohr } 375b571377SAndreas Gohr 385b571377SAndreas Gohr function test_trim() { 39*ddd88cddSChristopher Smith $whitespace = " \t\r\n"; 40*ddd88cddSChristopher Smith $this->assertFalse(blank($whitespace), "using default \$trim value"); 41*ddd88cddSChristopher Smith $this->assertFalse(blank($whitespace, false), "using \$trim = false"); 42*ddd88cddSChristopher Smith $this->assertTrue(blank($whitespace, true), "using \$trim = true"); 435b571377SAndreas Gohr } 445b571377SAndreas Gohr 45*ddd88cddSChristopher Smith function test_undefined() { 465b571377SAndreas Gohr $undef = array(); 47*ddd88cddSChristopher Smith $this->assertTrue(blank($var), "using undefined/unitialised variable"); 48*ddd88cddSChristopher Smith $this->assertTrue(blank($undef['nope']), "using undefined array index"); 49*ddd88cddSChristopher Smith $this->assertTrue(blank($this->nope), "using unset object property"); 505b571377SAndreas Gohr } 515b571377SAndreas Gohr 525b571377SAndreas Gohr} 53