ソースを参照

test special chars with RSS

euromark 11 年 前
コミット
00bad314bf
1 ファイル変更46 行追加2 行削除
  1. 46 2
      Test/Case/View/RssViewTest.php

+ 46 - 2
Test/Case/View/RssViewTest.php

@@ -513,7 +513,7 @@ RSS;
 		$Controller = new Controller($Request, $Response);
 		$data = array(
 			'channel' => array(
-				'title' => 'Channel title with äöü umlauts',
+				'title' => 'Channel title',
 				'link' => 'http://channel.example.org',
 			),
 			'items' => array(
@@ -529,7 +529,7 @@ RSS;
 <?xml version="1.0" encoding="UTF-8"?>
 <rss version="2.0">
   <channel>
-    <title>Channel title with äöü umlauts</title>
+    <title>Channel title</title>
     <link>http://channel.example.org</link>
     <description/>
     <item>
@@ -545,4 +545,48 @@ RSS;
 		$this->assertTextEquals($expected, $result);
 	}
 
+	/**
+	 * RssViewTest::testSerializeWithSpecialChars()
+	 *
+	 * @return void
+	 */
+	public function testSerializeWithSpecialChars() {
+		$Request = new CakeRequest();
+		$Response = new CakeResponse();
+		$Controller = new Controller($Request, $Response);
+		$data = array(
+			'channel' => array(
+				'title' => 'Channel title with äöü umlauts and <!> special chars',
+				'link' => 'http://channel.example.org',
+			),
+			'items' => array(
+				array(
+					'title' => 'A <unsafe title',
+					'link' => array('controller' => 'foo', 'action' => 'bar'),
+					'description' => 'My content "&" and <other> stuff here should also be escaped safely'),
+			)
+		);
+		$Controller->set(array('channel' => $data, '_serialize' => 'channel'));
+		$View = new RssView($Controller);
+		$result = $View->render(false);
+
+		$expected = <<<RSS
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0">
+  <channel>
+    <title>Channel title with äöü umlauts and &lt;!&gt; special chars</title>
+    <link>http://channel.example.org</link>
+    <description/>
+    <item>
+      <title>A &lt;unsafe title</title>
+      <link>$this->baseUrl/foo/bar</link>
+      <description>My content "&amp;" and &lt;other&gt; stuff here should also be escaped safely</description>
+    </item>
+  </channel>
+</rss>
+
+RSS;
+		$this->assertTextEquals($expected, $result);
+	}
+
 }