Browse Source

Correct order and sane default values

euromark 12 years ago
parent
commit
7a8058f24a
2 changed files with 59 additions and 3 deletions
  1. 51 0
      Test/Case/View/RssViewTest.php
  2. 8 3
      View/RssView.php

+ 51 - 0
Test/Case/View/RssViewTest.php

@@ -342,4 +342,55 @@ RSS;
 		$this->assertTextEquals($expected, $result);
 	}
 
+	/**
+	 * RssViewTest::testSerializeWithImage()
+	 *
+	 * @return void
+	 */
+	public function testSerializeWithImage() {
+		$Request = new CakeRequest();
+		$Response = new CakeResponse();
+		$Controller = new Controller($Request, $Response);
+		$url = array('controller' => 'topics', 'action' => 'feed', 'ext' => 'rss');
+		$data = array(
+			'channel' => array(
+				'title' => 'Channel title',
+				'guid' => array('url' => $url, '@isPermaLink' => 'true'),
+				'image' => array(
+					'url' => '/img/logo_rss.png',
+					'link' => '/'
+				)
+			),
+			'items' => array(
+				array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar')),
+			)
+		);
+		$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</title>
+    <guid isPermaLink="true">$this->baseUrl/topics/feed.rss</guid>
+    <image>
+      <url>$this->baseUrl/img/logo_rss.png</url>
+      <link>$this->baseUrl/</link>
+      <title>Channel title</title>
+    </image>
+    <link>$this->baseUrl/</link>
+    <description/>
+    <item>
+      <title>Title One</title>
+      <link>$this->baseUrl/foo/bar</link>
+    </item>
+  </channel>
+</rss>
+
+RSS;
+		//debug($result); ob_flush();
+		$this->assertTextEquals($expected, $result);
+	}
 }

+ 8 - 3
View/RssView.php

@@ -200,6 +200,9 @@ class RssView extends View {
 		}
 
 		$channel = $this->channel($data['channel']);
+		if (!empty($channel['image']) && empty($channel['image']['title'])) {
+			$channel['image']['title'] = $channel['title'];
+		}
 
 		foreach ($data['items'] as $item) {
 			$channel['item'][] = $this->_prepareOutput($item);
@@ -251,9 +254,6 @@ class RssView extends View {
 					$this->_usedNamespaces[] = $prefix;
 				}
 			}
-			if (is_array($val)) {
-				$val = $this->_prepareOutput($val);
-			}
 
 			$attrib = null;
 			switch ($bareKey) {
@@ -283,6 +283,7 @@ class RssView extends View {
 					break;
 				*/
 				case 'link':
+				case 'url':
 				case 'guid':
 				case 'comments':
 					if (is_array($val) && isset($val['@href'])) {
@@ -330,6 +331,10 @@ class RssView extends View {
 					//$attrib = $att;
 			}
 
+			if (is_array($val)) {
+				$val = $this->_prepareOutput($val);
+			}
+
 			$item[$key] = $val;
 		}