Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Added Reader/Writer methods and tests for <itunes:title> on entry level #96

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Reader/Extension/Podcast/Entry.php
Expand Up @@ -129,6 +129,28 @@ public function getKeywords()
return $this->data['keywords'];
}

/**
* Get the entry title
*
* @return string
*/
public function getTitle()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmmh, a test class for the entire Zend\Feed\Reader\Extension\Podcast\Entry is missing.
I will create a separate issue report for this problem.

{
if (isset($this->data['title'])) {
return $this->data['title'];
}

$title = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:title)');

if (! $title) {
$title = null;
}

$this->data['title'] = $title;

return $this->data['title'];
}

/**
* Get the entry subtitle
*
Expand Down
17 changes: 17 additions & 0 deletions src/Writer/Extension/ITunes/Entry.php
Expand Up @@ -191,6 +191,23 @@ public function setItunesKeywords(array $value)
return $this;
}

/**
* Set title
*
* @param string $value
* @return Entry
* @throws Writer\Exception\InvalidArgumentException
*/
public function setItunesTitle($value)
{
if ($this->stringWrapper->strlen($value) > 255) {
throw new Writer\Exception\InvalidArgumentException('invalid parameter: "title" may only'
. ' contain a maximum of 255 characters');
}
$this->data['title'] = $value;
return $this;
}

/**
* Set subtitle
*
Expand Down
23 changes: 23 additions & 0 deletions src/Writer/Extension/ITunes/Renderer/Entry.php
Expand Up @@ -39,6 +39,7 @@ public function render()
$this->_setImage($this->dom, $this->base);
$this->_setExplicit($this->dom, $this->base);
$this->_setKeywords($this->dom, $this->base);
$this->_setTitle($this->dom, $this->base);
$this->_setSubtitle($this->dom, $this->base);
$this->_setSummary($this->dom, $this->base);
$this->_setEpisode($this->dom, $this->base);
Expand Down Expand Up @@ -198,6 +199,28 @@ protected function _setKeywords(DOMDocument $dom, DOMElement $root)
$this->called = true;
}

/**
* Set entry title
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
// @codingStandardsIgnoreStart
protected function _setTitle(DOMDocument $dom, DOMElement $root)
{
// @codingStandardsIgnoreEnd
$title = $this->getDataContainer()->getItunesTitle();
if (! $title) {
return;
}
$el = $dom->createElement('itunes:title');
$text = $dom->createTextNode($title);
$el->appendChild($text);
$root->appendChild($el);
$this->called = true;
}

/**
* Set entry subtitle
*
Expand Down
3 changes: 3 additions & 0 deletions test/Reader/Integration/_files/google-podcast-complete.xml
Expand Up @@ -40,6 +40,7 @@
<googleplay:explicit>no</googleplay:explicit>
<itunes:author>John Doe</itunes:author>
<googleplay:block>yes</googleplay:block>
<itunes:title>Shake Shake Shake Your Spices With A Shaker</itunes:title>
<itunes:subtitle>A short primer on table spices
</itunes:subtitle>
<googleplay:description>This week we talk about salt and pepper
Expand All @@ -59,6 +60,7 @@
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:title>Socket Wrench Shootout With A Tool</itunes:title>
<itunes:subtitle>Comparing socket wrenches is fun!
</itunes:subtitle>
<googleplay:description>This week we talk about metric vs. old
Expand All @@ -78,6 +80,7 @@
<item>
<title>Red, Whine, &amp; Blue</title>
<itunes:author>Various</itunes:author>
<itunes:title>Red, Whine &amp; Blue</itunes:title>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<googleplay:description>This week we talk about surviving in a Red
state if you are a Blue person. Or vice versa.
Expand Down
3 changes: 3 additions & 0 deletions test/Reader/Integration/_files/google-podcast.xml
Expand Up @@ -39,6 +39,7 @@
<googleplay:explicit>no</googleplay:explicit>
<itunes:author>John Doe</itunes:author>
<googleplay:block>yes</googleplay:block>
<itunes:title>Shake Shake Shake Your Spices With A Shaker</itunes:title>
<itunes:subtitle>A short primer on table spices
</itunes:subtitle>
<googleplay:description>This week we talk about salt and pepper
Expand All @@ -60,6 +61,7 @@
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:title>Socket Wrench Shootout With A Tool</itunes:title>
<itunes:subtitle>Comparing socket wrenches is fun!
</itunes:subtitle>
<googleplay:description>This week we talk about metric vs. old
Expand All @@ -81,6 +83,7 @@
<item>
<title>Red, Whine, &amp; Blue</title>
<itunes:author>Various</itunes:author>
<itunes:title>Red, Whine &amp; Blue</itunes:title>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<googleplay:description>This week we talk about surviving in a Red
state if you are a Blue person. Or vice versa.
Expand Down
3 changes: 3 additions & 0 deletions test/Reader/Integration/_files/podcast-complete.xml
Expand Up @@ -38,6 +38,7 @@
<itunes:explicit>no</itunes:explicit>
<itunes:author>John Doe</itunes:author>
<itunes:block>yes</itunes:block>
<itunes:title>Shake Shake Shake Your Spices With A Shaker</itunes:title>
<itunes:subtitle>A short primer on table spices
</itunes:subtitle>
<itunes:summary>This week we talk about salt and pepper
Expand All @@ -57,6 +58,7 @@
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:title>Socket Wrench Shootout With A Tool</itunes:title>
<itunes:subtitle>Comparing socket wrenches is fun!
</itunes:subtitle>
<itunes:summary>This week we talk about metric vs. old
Expand All @@ -76,6 +78,7 @@
<item>
<title>Red, Whine, &amp; Blue</title>
<itunes:author>Various</itunes:author>
<itunes:title>Red, Whine &amp; Blue</itunes:title>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<itunes:summary>This week we talk about surviving in a Red
state if you are a Blue person. Or vice versa.
Expand Down
3 changes: 3 additions & 0 deletions test/Reader/Integration/_files/podcast-episode.xml
Expand Up @@ -39,6 +39,7 @@
<itunes:explicit>no</itunes:explicit>
<itunes:author>John Doe</itunes:author>
<itunes:block>yes</itunes:block>
<itunes:title>Shake Shake Shake Your Spices With A Shaker</itunes:title>
<itunes:subtitle>A short primer on table spices
</itunes:subtitle>
<itunes:summary>This week we talk about salt and pepper
Expand All @@ -58,6 +59,7 @@
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:title>Socket Wrench Shootout With A Tool</itunes:title>
<itunes:subtitle>Comparing socket wrenches is fun!
</itunes:subtitle>
<itunes:summary>This week we talk about metric vs. old
Expand All @@ -77,6 +79,7 @@
<item>
<title>Red, Whine, &amp; Blue</title>
<itunes:author>Various</itunes:author>
<itunes:title>Red, Whine &amp; Blue</itunes:title>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<itunes:summary>This week we talk about surviving in a Red
state if you are a Blue person. Or vice versa.
Expand Down
3 changes: 3 additions & 0 deletions test/Reader/Integration/_files/podcast.xml
Expand Up @@ -37,6 +37,7 @@
<itunes:explicit>no</itunes:explicit>
<itunes:author>John Doe</itunes:author>
<itunes:block>yes</itunes:block>
<itunes:title>Shake Shake Shake Your Spices With A Shaker</itunes:title>
<itunes:subtitle>A short primer on table spices
</itunes:subtitle>
<itunes:summary>This week we talk about salt and pepper
Expand All @@ -58,6 +59,7 @@
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:title>Socket Wrench Shootout With A Tool</itunes:title>
<itunes:subtitle>Comparing socket wrenches is fun!
</itunes:subtitle>
<itunes:summary>This week we talk about metric vs. old
Expand All @@ -79,6 +81,7 @@
<item>
<title>Red, Whine, &amp; Blue</title>
<itunes:author>Various</itunes:author>
<itunes:title>Red, Whine &amp; Blue</itunes:title>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<itunes:summary>This week we talk about surviving in a Red
state if you are a Blue person. Or vice versa.
Expand Down
14 changes: 14 additions & 0 deletions test/Writer/Extension/ITunes/EntryTest.php
Expand Up @@ -185,6 +185,20 @@ public function testSetKeywordsThrowsExceptionIfFormattedKeywordsExceeds255CharL
}
}

public function testSetTitle()
{
$entry = new Writer\Entry;
$entry->setItunesTitle('abc');
$this->assertEquals('abc', $entry->getItunesTitle());
}

public function testSetTitleThrowsExceptionWhenValueExceeds255Chars()
{
$this->expectException(ExceptionInterface::class);
$entry = new Writer\Entry;
$entry->setItunesTitle(str_repeat('a', 256));
}

public function testSetSubtitle()
{
$entry = new Writer\Entry;
Expand Down