|
|
@@ -108,6 +108,78 @@ class XmlViewTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test that rendering with _serialize respects XML options.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testRenderSerializeWithOptions()
|
|
|
+ {
|
|
|
+ $Request = new Request();
|
|
|
+ $Response = new Response();
|
|
|
+ $Controller = new Controller($Request, $Response);
|
|
|
+ $data = [
|
|
|
+ '_serialize' => ['tags'],
|
|
|
+ '_xmlOptions' => ['format' => 'attributes'],
|
|
|
+ 'tags' => [
|
|
|
+ 'tag' => [
|
|
|
+ [
|
|
|
+ 'id' => '1',
|
|
|
+ 'name' => 'defect'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'id' => '2',
|
|
|
+ 'name' => 'enhancement'
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $Controller->set($data);
|
|
|
+ $Controller->viewClass = 'Xml';
|
|
|
+ $View = $Controller->createView();
|
|
|
+ $result = $View->render();
|
|
|
+
|
|
|
+ $expected = Xml::build(['response' => ['tags' => $data['tags']]], $data['_xmlOptions'])->asXML();
|
|
|
+ $this->assertSame($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test that rendering with _serialize can work with string setting.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testRenderSerializeWithString()
|
|
|
+ {
|
|
|
+ $Request = new Request();
|
|
|
+ $Response = new Response();
|
|
|
+ $Controller = new Controller($Request, $Response);
|
|
|
+ $data = [
|
|
|
+ '_serialize' => 'tags',
|
|
|
+ '_xmlOptions' => ['format' => 'attributes'],
|
|
|
+ 'tags' => [
|
|
|
+ 'tags' => [
|
|
|
+ 'tag' => [
|
|
|
+ [
|
|
|
+ 'id' => '1',
|
|
|
+ 'name' => 'defect'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'id' => '2',
|
|
|
+ 'name' => 'enhancement'
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $Controller->set($data);
|
|
|
+ $Controller->viewClass = 'Xml';
|
|
|
+ $View = $Controller->createView();
|
|
|
+ $result = $View->render();
|
|
|
+
|
|
|
+ $expected = Xml::build($data['tags'], $data['_xmlOptions'])->asXML();
|
|
|
+ $this->assertSame($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test render with an array in _serialize
|
|
|
*
|
|
|
* @return void
|