| 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_Arrays_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_Arrays_TestCase extends PHPUnit_Framework_TestCase {
|
|
|
34 |
|
|
|
35 |
private $options = array(
|
|
|
36 |
XML_SERIALIZER_OPTION_INDENT => '',
|
|
|
37 |
XML_SERIALIZER_OPTION_LINEBREAKS => '',
|
|
|
38 |
);
|
|
|
39 |
|
|
|
40 |
public static function main() {
|
|
|
41 |
$suite = new PHPUnit_Framework_TestSuite('XML_Serializer_Arrays_TestCase');
|
|
|
42 |
$result = PHPUnit_TextUI_TestRunner::run($suite);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
protected function setUp() {}
|
|
|
46 |
|
|
|
47 |
protected function tearDown() {}
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Test serializing a numbered array
|
|
|
52 |
*/
|
|
|
53 |
public function testNumberedArray()
|
|
|
54 |
{
|
|
|
55 |
$s = new XML_Serializer($this->options);
|
|
|
56 |
$s->serialize(array('one', 'two', 'three'));
|
|
|
57 |
$this->assertEquals(
|
|
|
58 |
'<array><XML_Serializer_Tag>one</XML_Serializer_Tag><XML_Serializer_Tag>two</XML_Serializer_Tag><XML_Serializer_Tag>three</XML_Serializer_Tag></array>'
|
|
|
59 |
, $s->getSerializedData()
|
|
|
60 |
);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Test serializing an assoc array
|
|
|
65 |
*/
|
|
|
66 |
public function testAssocArray()
|
|
|
67 |
{
|
|
|
68 |
$s = new XML_Serializer($this->options);
|
|
|
69 |
$s->serialize(array('one' => 'foo', 'two' => 'bar'));
|
|
|
70 |
$this->assertEquals(
|
|
|
71 |
'<array><one>foo</one><two>bar</two></array>'
|
|
|
72 |
, $s->getSerializedData()
|
|
|
73 |
);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Test serializing an mixed array
|
|
|
78 |
*/
|
|
|
79 |
public function testMixedArray()
|
|
|
80 |
{
|
|
|
81 |
$s = new XML_Serializer($this->options);
|
|
|
82 |
$s->serialize(array('one' => 'foo', 'two' => 'bar', 'three'));
|
|
|
83 |
$this->assertEquals(
|
|
|
84 |
'<array><one>foo</one><two>bar</two><XML_Serializer_Tag>three</XML_Serializer_Tag></array>'
|
|
|
85 |
, $s->getSerializedData()
|
|
|
86 |
);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* PHPUnit main() hack
|
|
|
93 |
* "Call class::main() if this source file is executed directly."
|
|
|
94 |
*/
|
|
|
95 |
if (PHPUnit_MAIN_METHOD == 'XML_Serializer_Arrays_TestCase::main') {
|
|
|
96 |
XML_Serializer_Arrays_TestCase::main();
|
|
|
97 |
}
|
|
|
98 |
?>
|