summaryrefslogtreecommitdiff
path: root/tests/UnitTests/simpletest/test/dumper_test.php
blob: f01692472e0ceb92e642003b04da25bed7679264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
    // $Id: dumper_test.php,v 1.4 2004/09/24 22:55:10 lastcraft Exp $

    class DumperDummy {
    }

    class TestOfTextFormatting extends UnitTestCase {
        
        function testClipping() {
            $dumper = new SimpleDumper();
            $this->assertEqual(
                    $dumper->clipString("Hello", 6),
                    "Hello",
                    "Hello, 6->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello", 5),
                    "Hello",
                    "Hello, 5->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello world", 3),
                    "Hel...",
                    "Hello world, 3->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello world", 6, 3),
                    "Hello ...",
                    "Hello world, 6, 3->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello world", 3, 6),
                    "...o w...",
                    "Hello world, 3, 6->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello world", 4, 11),
                    "...orld",
                    "Hello world, 4, 11->%s");
            $this->assertEqual(
                    $dumper->clipString("Hello world", 4, 12),
                    "...orld",
                    "Hello world, 4, 12->%s");
        }
        
        function testDescribeNull() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/null/i', $dumper->describeValue(null));
        }
        
        function testDescribeBoolean() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/boolean/i', $dumper->describeValue(true));
            $this->assertWantedPattern('/true/i', $dumper->describeValue(true));
            $this->assertWantedPattern('/false/i', $dumper->describeValue(false));
        }
        
        function testDescribeString() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/string/i', $dumper->describeValue('Hello'));
            $this->assertWantedPattern('/Hello/', $dumper->describeValue('Hello'));
        }
        
        function testDescribeInteger() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/integer/i', $dumper->describeValue(35));
            $this->assertWantedPattern('/35/', $dumper->describeValue(35));
        }
        
        function testDescribeFloat() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/float/i', $dumper->describeValue(0.99));
            $this->assertWantedPattern('/0\.99/', $dumper->describeValue(0.99));
        }
        
        function testDescribeArray() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern('/array/i', $dumper->describeValue(array(1, 4)));
            $this->assertWantedPattern('/2/i', $dumper->describeValue(array(1, 4)));
        }
        
        function testDescribeObject() {
            $dumper = new SimpleDumper();
            $this->assertWantedPattern(
                    '/object/i',
                    $dumper->describeValue(new DumperDummy()));
            $this->assertWantedPattern(
                    '/DumperDummy/i',
                    $dumper->describeValue(new DumperDummy()));
        }
    }
?>