Author: as
Date: Wed Oct 10 10:54:40 2007
New Revision: 6411

Log:
- In RSS2 the title, link and description nodes of item nodes are not all
  required, but at least one of title or description nodes is required.

Added:
    trunk/Feed/src/exceptions/one_item_data_missing.php   (with props)
    trunk/Feed/tests/rss2/data/rss2-02_no_link.xml
Modified:
    trunk/Feed/design/class_diagram.png
    trunk/Feed/src/feed_autoload.php
    trunk/Feed/src/processors/rss2.php
    trunk/Feed/tests/rss2/rss2_test.php

Modified: trunk/Feed/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Added: trunk/Feed/src/exceptions/one_item_data_missing.php
==============================================================================
--- trunk/Feed/src/exceptions/one_item_data_missing.php (added)
+++ trunk/Feed/src/exceptions/one_item_data_missing.php [iso-8859-1] Wed Oct 10 
10:54:40 2007
@@ -1,0 +1,32 @@
+<?php
+/**
+ * File containing the ezcFeedAtLeastOneItemDataRequiredException class.
+ *
+ * @package Feed
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ */
+
+/**
+ * Thrown when at least one of the required attributes is missing for a feed
+ * item.
+ *
+ * @package Feed
+ * @version //autogentag//
+ */
+class ezcFeedAtLeastOneItemDataRequiredException extends ezcFeedException
+{
+    /**
+     * Constructs a new ezcFeedAtLeastOneItemDataRequiredException.
+     *
+     * @param array(string) $attributes The attributes of which at least one 
is required
+     */
+    public function __construct( $attributes )
+    {
+        $attributes = implode( ', ', $attributes );
+        parent::__construct( "At least one of these attributes is required: 
{$attributes}." );
+    }
+}
+?>

Propchange: trunk/Feed/src/exceptions/one_item_data_missing.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Feed/src/feed_autoload.php
==============================================================================
--- trunk/Feed/src/feed_autoload.php [iso-8859-1] (original)
+++ trunk/Feed/src/feed_autoload.php [iso-8859-1] Wed Oct 10 10:54:40 2007
@@ -11,6 +11,7 @@
 
 return array(
     'ezcFeedException'                             => 
'Feed/exceptions/exception.php',
+    'ezcFeedAtLeastOneItemDataRequiredException'   => 
'Feed/exceptions/one_item_data_missing.php',
     'ezcFeedCanNotParseException'                  => 
'Feed/exceptions/can_not_parse.php',
     'ezcFeedOnlyOneValueAllowedException'          => 
'Feed/exceptions/only_one_value_allowed.php',
     'ezcFeedParseErrorException'                   => 
'Feed/exceptions/parse_error.php',

Modified: trunk/Feed/src/processors/rss2.php
==============================================================================
--- trunk/Feed/src/processors/rss2.php [iso-8859-1] (original)
+++ trunk/Feed/src/processors/rss2.php [iso-8859-1] Wed Oct 10 10:54:40 2007
@@ -62,15 +62,25 @@
      *
      * @var array(string)
      */
-    protected static $requiredFeedItemAttributes = array( 'title', 'link', 
'description' );
+    protected static $requiredFeedItemAttributes = array();
+
+    /**
+     * Holds a list of attributes for items definitions of which at least one
+     * is required.
+     *
+     * @var array(string)
+     */
+    protected static $atLeastOneRequiredFeedItemAttributes = array( 'title', 
'description' );
 
     /**
      * Holds a list of optional attributes for items definitions.
      *
      * @var array(string)
      */
-    protected static $optionalFeedItemAttributes = array( 'author', 'category',
-        'comments', 'enclosure', 'guid', 'published', 'source' );
+    protected static $optionalFeedItemAttributes = array(
+        'title', 'link', 'description',
+        'author', 'category', 'comments', 'enclosure', 'guid',
+        'published', 'source' );
 
     /**
      * Holds a mapping of the common names for items attributes to feed 
specific
@@ -206,17 +216,20 @@
         $itemTag = $this->xml->createElement( 'item' );
         $this->channel->appendChild( $itemTag );
 
-        foreach ( self::$requiredFeedItemAttributes as $attribute )
+        $atLeastOneRequiredFeedItemPresent = false;
+        foreach ( self::$atLeastOneRequiredFeedItemAttributes as $attribute )
         {
             $data = $item->getMetaData( $attribute );
-            if ( is_null( $data ) )
-            {
-                throw new ezcFeedRequiredItemDataMissingException( $attribute 
);
-            }
-            if ( $this->processModuleItemGenerateHook( $item, $attribute, 
$data ) !== false )
-            {
-                $this->generateItemData( $itemTag, $attribute, 
$item->getMetaData( $attribute ) );
-            }
+            if ( !is_null( $data ) )
+            {
+                $atLeastOneRequiredFeedItemPresent = true;
+                break;
+            }
+        }
+
+        if ( $atLeastOneRequiredFeedItemPresent === false )
+        {
+            throw new ezcFeedAtLeastOneItemDataRequiredException( 
self::$atLeastOneRequiredFeedItemAttributes );
         }
 
         foreach ( self::$optionalFeedItemAttributes as $attribute )
@@ -224,7 +237,7 @@
             $normalizedAttribute = $this->normalizeName( $attribute, 
self::$feedItemAttributesMap );
 
             $metaData = $item->getMetaData( $attribute );
-            if ( $this->processModuleItemGenerateHook( $item, $attribute, 
$data ) !== false )
+            if ( $this->processModuleItemGenerateHook( $item, $attribute, 
$metaData ) !== false )
             {
                 if ( !is_null( $metaData ) )
                 {

Added: trunk/Feed/tests/rss2/data/rss2-02_no_link.xml
==============================================================================
--- trunk/Feed/tests/rss2/data/rss2-02_no_link.xml (added)
+++ trunk/Feed/tests/rss2/data/rss2-02_no_link.xml [iso-8859-1] Wed Oct 10 
10:54:40 2007
@@ -1,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0">
+  <channel>
+    <title>eZ Components test</title>
+    <link>http://components.ez.no</link>
+    <description>This is a test for the eZ Components Feed 
Generator</description>
+    <managingEditor>[EMAIL PROTECTED] (Derick Rethans)</managingEditor>
+    <pubDate>Fri, 26 May 2006 10:46:31 +0200</pubDate>
+    <lastBuildDate>Fri, 26 May 2006 19:46:31 +0200</lastBuildDate>
+    <generator>eZ Components</generator>
+    <docs>http://www.rssboard.org/rss-specification</docs>
+    <item>
+      <title>First Item</title>
+      <description>This is the first item</description>
+    </item>
+    <item>
+      <title>Second Item</title>
+      <description>This is the second item</description>
+    </item>
+  </channel>
+</rss>

Modified: trunk/Feed/tests/rss2/rss2_test.php
==============================================================================
--- trunk/Feed/tests/rss2/rss2_test.php [iso-8859-1] (original)
+++ trunk/Feed/tests/rss2/rss2_test.php [iso-8859-1] Wed Oct 10 10:54:40 2007
@@ -123,6 +123,29 @@
         self::assertEquals( $expected, $feed->generate() );
     }
 
+    public function testSimpleWithItems3NoLink()
+    {
+        $feed = new ezcFeed( 'rss2' );
+        $feed->title = "eZ Components test";
+        $feed->link = "http://components.ez.no";;
+        $feed->description = "This is a test for the eZ Components Feed 
Generator";
+        $feed->author = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->author = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->published = 1148633191;
+        $feed->updated = "Fri May 26, 10:46:31 2006 PDT";
+
+        $item = $feed->newItem();
+        $item->title = "First Item";
+        $item->description = "This is the first item";
+
+        $item = $feed->newItem();
+        $item->title = "Second Item";
+        $item->description = "This is the second item";
+
+        $expected = file_get_contents( dirname( __FILE__ ) . 
"/data/rss2-02_no_link.xml" );
+        self::assertEquals( $expected, $feed->generate() );
+    }
+
     public function testSimpleWithItemsWithError1()
     {
         $feed = new ezcFeed( 'rss2' );
@@ -140,11 +163,11 @@
         try
         {
             $feed->generate();
-            self::assertEquals( 'Expected exception not thrown' );
-        }
-        catch ( ezcFeedRequiredItemDataMissingException $e )
-        {
-            self::assertEquals( "There was no data submitted for required 
attribute 'title'.", $e->getMessage() );
+            self::fail( 'Expected exception not thrown' );
+        }
+        catch ( ezcFeedAtLeastOneItemDataRequiredException $e )
+        {
+            self::assertEquals( "At least one of these attributes is required: 
title, description.", $e->getMessage() );
         }
     }
 


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to