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

Commit

Permalink
Added Reader/Writer methods and tests for <itunes:title> on episode (…
Browse files Browse the repository at this point in the history
…entry) level
  • Loading branch information
OpenHaus authored and weierophinney committed Mar 5, 2019
1 parent a71a16f commit 8c53672
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
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()
{
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

0 comments on commit 8c53672

Please sign in to comment.