Skip to content

Commit 44d2061

Browse files
committed
Added optional author element to Item. According to spec, this should be an email address, but a full name could also be included.
Tests updated and passing.
1 parent 82812ff commit 44d2061

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Source/Suin/RSSWriter/Item.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Item implements \Suin\RSSWriter\ItemInterface
2222
protected $pubDate;
2323
/** @var array */
2424
protected $enclosure;
25+
/** @var string */
26+
protected $author;
2527

2628
/**
2729
* Set item title
@@ -105,7 +107,17 @@ public function enclosure($url, $length = 0, $type = 'audio/mpeg')
105107
return $this;
106108
}
107109

108-
/**
110+
/**
111+
* Set the author
112+
* @param string $author Email of item author
113+
* @return $this
114+
*/
115+
public function author($author) {
116+
$this->author = $author;
117+
return $this;
118+
}
119+
120+
/**
109121
* Append item to the channel
110122
* @param \Suin\RSSWriter\ChannelInterface $channel
111123
* @return $this
@@ -164,6 +176,11 @@ public function asXML()
164176
$element->addAttribute('length', $this->enclosure['length']);
165177
}
166178
}
179+
180+
if ( ! empty($this->author) ) {
181+
$xml->addChild('author', $this->author);
182+
}
183+
167184
return $xml;
168185
}
169186
}

Source/Suin/RSSWriter/ItemInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public function pubDate($pubDate);
6060
*/
6161
public function enclosure($url, $length = 0, $type = 'audio/mpeg');
6262

63+
/**
64+
* Set the author
65+
* @param string $author Email of item author
66+
* @return $this
67+
*/
68+
public function author($author);
69+
6370
/**
6471
* Append item to the channel
6572
* @param \Suin\RSSWriter\ChannelInterface $channel

Tests/Suin/RSSWriter/ItemTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function testEnclosure()
9797
$this->assertAttributeSame($enclosure, 'enclosure', $item);
9898
}
9999

100+
public function testAuthor()
101+
{
102+
$author = uniqid();
103+
$item = new Item();
104+
$this->assertSame($item, $item->author($author));
105+
$this->assertAttributeSame($author, 'author', $item);
106+
}
107+
100108
public function testAsXML()
101109
{
102110
$now = time();
@@ -116,7 +124,8 @@ public function testAsXML()
116124
'enclosure' => array(
117125
'url' => 'http://link-to-audio-file.com/test.mp3',
118126
'length' => 4992,
119-
'type' => 'audio/mpeg')
127+
'type' => 'audio/mpeg'),
128+
'author' => 'Hidehito Nozawa aka Suin'
120129
);
121130

122131
$item = new Item();
@@ -136,6 +145,7 @@ public function testAsXML()
136145
<guid isPermaLink=\"true\">{$data['guid']}</guid>
137146
<pubDate>{$nowString}</pubDate>
138147
<enclosure url=\"{$data['enclosure']['url']}\" length=\"{$data['enclosure']['length']}\" type=\"{$data['enclosure']['type']}\"/>
148+
<author>{$data['author']}</author>
139149
</item>
140150
";
141151
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML());

0 commit comments

Comments
 (0)