Introduce FrontController as the replacement for RootController.
[hoplite.git] / testing / tests / http / output_filter_test.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2011 Blue Static
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
16
17 namespace hoplite\test;
18 use hoplite\http as http;
19
20 require_once HOPLITE_ROOT . '/http/output_filter.php';
21
22 class TestOutputFilter extends http\OutputFilter
23 {
24 public function T_EncodeXML($d)
25 {
26 return $this->_EncodeXML($d);
27 }
28 }
29
30 class OutputFilterTest extends \PHPUnit_Framework_TestCase
31 {
32 public function setUp()
33 {
34 $this->fixture = new TestOutputFilter(new http\FrontController(array()));
35 }
36
37 public function testEncodeXML()
38 {
39 $array = array(
40 'test' => 1,
41 'foo' => 'bar',
42 'bar' => '<strong>baz</strong>',
43 'baz' => array(
44 'poo' => 'moo',
45 'moo' => 'baa'
46 )
47 );
48 $expected = <<<XML
49 <?xml version="1.0"?>
50 <response><test>1</test><foo>bar</foo><bar>&lt;strong&gt;baz&lt;/strong&gt;</bar><baz><poo>moo</poo><moo>baa</moo></baz></response>
51
52 XML;
53
54 $this->assertEquals($expected, $this->fixture->T_EncodeXML($array));
55
56 $obj = new \stdClass();
57 $obj->int = 2;
58 $obj->obj = new \stdClass();
59 $obj->obj->string = 'Foo';
60 $expected = <<<XML
61 <?xml version="1.0"?>
62 <response><int>2</int><obj><string>Foo</string></obj></response>
63
64 XML;
65 $this->assertEquals($expected, $this->fixture->T_EncodeXML($obj));
66 }
67 }