1<?php
2
3class common_blank_test extends DokuWikiTest {
4
5    private $nope;
6
7    function test_blank() {
8        $tests = array(
9            // these are not blank
10            array('string', false),
11            array(1, false),
12            array(1.0, false),
13            array(0xff, false),
14            array(array('something'), false),
15
16            // these aren't either!
17            array('0', false),
18            array(' ', false),
19            array('0.0', false),
20            array(0, false),
21            array(0.0, false),
22            array(0x00, false),
23            array(true, false),
24
25            // but these are
26            array('', true),
27            array(array(), true),
28            array(null, true),
29            array(false, true),
30            array("\0", true)
31        );
32
33        foreach($tests as $test) {
34            $this->assertEquals($test[1], blank($test[0]), "using " . var_export($test[0], true));
35        }
36    }
37
38    function test_trim() {
39        $whitespace = " \t\r\n";
40        $this->assertFalse(blank($whitespace), "using default \$trim value");
41        $this->assertFalse(blank($whitespace, false), "using \$trim = false");
42        $this->assertTrue(blank($whitespace, true), "using \$trim = true");
43    }
44
45    function test_undefined() {
46        $undef = array();
47        $this->assertTrue(blank($var), "using undefined/unitialised variable");
48        $this->assertTrue(blank($undef['nope']), "using undefined array index");
49        $this->assertTrue(blank($this->nope), "using unset object property");
50    }
51
52}
53