Skip to content

Commit fa1c14b

Browse files
committed
Merge pull request #4 from kenobi883/master
Add optional author element to Item
2 parents 82812ff + 849a49b commit fa1c14b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Source/Suin/RSSWriter/Item.php

Lines changed: 19 additions & 0 deletions
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
@@ -106,6 +108,17 @@ public function enclosure($url, $length = 0, $type = 'audio/mpeg')
106108
}
107109

108110
/**
111+
* Set the author
112+
* @param string $author Email of item author
113+
* @return $this
114+
*/
115+
public function author($author)
116+
{
117+
$this->author = $author;
118+
return $this;
119+
}
120+
121+
/**
109122
* Append item to the channel
110123
* @param \Suin\RSSWriter\ChannelInterface $channel
111124
* @return $this
@@ -164,6 +177,12 @@ public function asXML()
164177
$element->addAttribute('length', $this->enclosure['length']);
165178
}
166179
}
180+
181+
if ( ! empty($this->author) )
182+
{
183+
$xml->addChild('author', $this->author);
184+
}
185+
167186
return $xml;
168187
}
169188
}

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)