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_Serializer_Option_EncodeFunc_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/Serializer.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_Serializer_Option_EncodeFunc_TestCase extends PHPUnit_Framework_TestCase {
34
 
35
    private $options = array(
36
        XML_SERIALIZER_OPTION_INDENT               => '',
37
        XML_SERIALIZER_OPTION_LINEBREAKS           => '',
38
        XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES => true,
39
        XML_SERIALIZER_OPTION_ENCODE_FUNC          => 'strtoupper'
40
    );
41
 
42
    public static function main() {
43
        $suite  = new PHPUnit_Framework_TestSuite('XML_Serializer_Option_EncodeFunc_TestCase');
44
        $result = PHPUnit_TextUI_TestRunner::run($suite);
45
    }
46
 
47
    protected function setUp() {}
48
 
49
    protected function tearDown() {}
50
 
51
   /**
52
    * Test encode function with cdata
53
    */
54
    public function testCData()
55
    {
56
        $s = new XML_Serializer($this->options);
57
        $s->serialize('a string');
58
        $this->assertEquals('<string>A STRING</string>', $s->getSerializedData());
59
    }
60
 
61
   /**
62
    * Test encode function with attributes
63
    */
64
    public function testAttributes()
65
    {
66
        $s = new XML_Serializer($this->options);
67
        $s->serialize(array('foo' => 'bar'));
68
        $this->assertEquals('<array foo="BAR" />', $s->getSerializedData());
69
    }
70
 
71
   /**
72
    * Test encode function with cdata
73
    */
74
    public function testMixed()
75
    {
76
        $s = new XML_Serializer($this->options);
77
        $s->serialize(array('foo' => 'bar', 'tomato'));
78
        $this->assertEquals('<array foo="BAR"><XML_Serializer_Tag>TOMATO</XML_Serializer_Tag></array>', $s->getSerializedData());
79
    }
80
 
81
}
82
 
83
/**
84
 * PHPUnit main() hack
85
 * "Call class::main() if this source file is executed directly."
86
 */
87
if (PHPUnit_MAIN_METHOD == 'XML_Serializer_Option_EncodeFunc_TestCase::main') {
88
    XML_Serializer_Option_EncodeFunc_TestCase::main();
89
}
90
?>