Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Unit Tests for serializing arrays
4
 *
5
 * @package    XML_Serializer
6
 * @subpackage tests
7
 * @author     Stephan Schmidt <schst@php-tools.net>
8
 * @author     Chuck Burgess <ashnazg@php.net>
9
 */
10
 
11
/**
12
 * PHPUnit main() hack
13
 *
14
 * "Call class::main() if this source file is executed directly."
15
 */
16
if (!defined('PHPUnit_MAIN_METHOD')) {
17
    define('PHPUnit_MAIN_METHOD', 'XML_Unserializer_Option_Whitespace_TestCase::main');
18
}
19
require_once 'PHPUnit/Framework/TestCase.php';
20
require_once 'PHPUnit/Framework/TestSuite.php';
21
require_once 'PHPUnit/TextUI/TestRunner.php';
22
 
23
require_once 'XML/Unserializer.php';
24
 
25
/**
26
 * Unit Tests for serializing arrays
27
 *
28
 * @package    XML_Serializer
29
 * @subpackage tests
30
 * @author     Stephan Schmidt <schst@php-tools.net>
31
 * @author     Chuck Burgess <ashnazg@php.net>
32
 */
33
class XML_Unserializer_Option_Whitespace_TestCase extends PHPUnit_Framework_TestCase {
34
 
35
    private $xml = '<xml>
36
   <string>
37
 
38
    This XML
39
    document
40
    contains
41
    line breaks.
42
 
43
   </string>
44
 </xml>';
45
 
46
    public static function main() {
47
        $suite  = new PHPUnit_Framework_TestSuite('XML_Unserializer_Option_Whitespace_TestCase');
48
        $result = PHPUnit_TextUI_TestRunner::run($suite);
49
    }
50
 
51
    protected function setUp() {}
52
 
53
    protected function tearDown() {}
54
 
55
   /**
56
    * Test trim behaviour
57
    */
58
    public function testTrim()
59
    {
60
        $u = new XML_Unserializer();
61
        $u->setOption(XML_UNSERIALIZER_OPTION_WHITESPACE, XML_UNSERIALIZER_WHITESPACE_TRIM);
62
        $u->unserialize($this->xml);
63
        $expected = array('string' => 'This XML
64
    document
65
    contains
66
    line breaks.');
67
        $this->assertEquals($expected, $u->getUnserializedData());
68
    }
69
 
70
   /**
71
    * Test normalize behaviour
72
    */
73
    public function testNormalize()
74
    {
75
        $u = new XML_Unserializer();
76
        $u->setOption(XML_UNSERIALIZER_OPTION_WHITESPACE, XML_UNSERIALIZER_WHITESPACE_NORMALIZE);
77
        $u->unserialize($this->xml);
78
        $expected = array('string' => 'This XML document contains line breaks.');
79
        $this->assertEquals($expected, $u->getUnserializedData());
80
    }
81
 
82
   /**
83
    * Test keep behaviour
84
    */
85
    public function testKeep()
86
    {
87
        $u = new XML_Unserializer();
88
        $u->setOption(XML_UNSERIALIZER_OPTION_WHITESPACE, XML_UNSERIALIZER_WHITESPACE_KEEP);
89
        $u->unserialize($this->xml);
90
        $expected = array('string' => '
91
 
92
    This XML
93
    document
94
    contains
95
    line breaks.
96
 
97
   ');
98
        $this->assertEquals($expected, $u->getUnserializedData());
99
    }
100
 
101
}
102
 
103
/**
104
 * PHPUnit main() hack
105
 * "Call class::main() if this source file is executed directly."
106
 */
107
if (PHPUnit_MAIN_METHOD == 'XML_Unserializer_Option_Whitespace_TestCase::main') {
108
    XML_Unserializer_Option_Whitespace_TestCase::main();
109
}
110
?>