diff --git a/src/Reader/Extension/Podcast/Entry.php b/src/Reader/Extension/Podcast/Entry.php index 7060fa3c..2a8c2aa6 100644 --- a/src/Reader/Extension/Podcast/Entry.php +++ b/src/Reader/Extension/Podcast/Entry.php @@ -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 * diff --git a/src/Writer/Extension/ITunes/Entry.php b/src/Writer/Extension/ITunes/Entry.php index cb49c0c7..eb219b54 100644 --- a/src/Writer/Extension/ITunes/Entry.php +++ b/src/Writer/Extension/ITunes/Entry.php @@ -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 * diff --git a/src/Writer/Extension/ITunes/Renderer/Entry.php b/src/Writer/Extension/ITunes/Renderer/Entry.php index 81840846..699e6a52 100644 --- a/src/Writer/Extension/ITunes/Renderer/Entry.php +++ b/src/Writer/Extension/ITunes/Renderer/Entry.php @@ -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); @@ -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 * diff --git a/test/Reader/Integration/_files/google-podcast-complete.xml b/test/Reader/Integration/_files/google-podcast-complete.xml index afccb390..cecf74ec 100644 --- a/test/Reader/Integration/_files/google-podcast-complete.xml +++ b/test/Reader/Integration/_files/google-podcast-complete.xml @@ -40,6 +40,7 @@ no John Doe yes + Shake Shake Shake Your Spices With A Shaker A short primer on table spices This week we talk about salt and pepper @@ -59,6 +60,7 @@ Socket Wrench Shootout Jane Doe + Socket Wrench Shootout With A Tool Comparing socket wrenches is fun! This week we talk about metric vs. old @@ -78,6 +80,7 @@ Red, Whine, & Blue Various + Red, Whine & Blue Red + Blue != Purple This week we talk about surviving in a Red state if you are a Blue person. Or vice versa. diff --git a/test/Reader/Integration/_files/google-podcast.xml b/test/Reader/Integration/_files/google-podcast.xml index 77f11299..d0573574 100644 --- a/test/Reader/Integration/_files/google-podcast.xml +++ b/test/Reader/Integration/_files/google-podcast.xml @@ -39,6 +39,7 @@ no John Doe yes + Shake Shake Shake Your Spices With A Shaker A short primer on table spices This week we talk about salt and pepper @@ -60,6 +61,7 @@ Socket Wrench Shootout Jane Doe + Socket Wrench Shootout With A Tool Comparing socket wrenches is fun! This week we talk about metric vs. old @@ -81,6 +83,7 @@ Red, Whine, & Blue Various + Red, Whine & Blue Red + Blue != Purple This week we talk about surviving in a Red state if you are a Blue person. Or vice versa. diff --git a/test/Reader/Integration/_files/podcast-complete.xml b/test/Reader/Integration/_files/podcast-complete.xml index d5de5c52..106a1500 100644 --- a/test/Reader/Integration/_files/podcast-complete.xml +++ b/test/Reader/Integration/_files/podcast-complete.xml @@ -38,6 +38,7 @@ no John Doe yes + Shake Shake Shake Your Spices With A Shaker A short primer on table spices This week we talk about salt and pepper @@ -57,6 +58,7 @@ Socket Wrench Shootout Jane Doe + Socket Wrench Shootout With A Tool Comparing socket wrenches is fun! This week we talk about metric vs. old @@ -76,6 +78,7 @@ Red, Whine, & Blue Various + Red, Whine & Blue Red + Blue != Purple This week we talk about surviving in a Red state if you are a Blue person. Or vice versa. diff --git a/test/Reader/Integration/_files/podcast-episode.xml b/test/Reader/Integration/_files/podcast-episode.xml index 2ef027ac..d442f510 100644 --- a/test/Reader/Integration/_files/podcast-episode.xml +++ b/test/Reader/Integration/_files/podcast-episode.xml @@ -39,6 +39,7 @@ no John Doe yes + Shake Shake Shake Your Spices With A Shaker A short primer on table spices This week we talk about salt and pepper @@ -58,6 +59,7 @@ Socket Wrench Shootout Jane Doe + Socket Wrench Shootout With A Tool Comparing socket wrenches is fun! This week we talk about metric vs. old @@ -77,6 +79,7 @@ Red, Whine, & Blue Various + Red, Whine & Blue Red + Blue != Purple This week we talk about surviving in a Red state if you are a Blue person. Or vice versa. diff --git a/test/Reader/Integration/_files/podcast.xml b/test/Reader/Integration/_files/podcast.xml index 9a81962b..a9656e47 100644 --- a/test/Reader/Integration/_files/podcast.xml +++ b/test/Reader/Integration/_files/podcast.xml @@ -37,6 +37,7 @@ no John Doe yes + Shake Shake Shake Your Spices With A Shaker A short primer on table spices This week we talk about salt and pepper @@ -58,6 +59,7 @@ Socket Wrench Shootout Jane Doe + Socket Wrench Shootout With A Tool Comparing socket wrenches is fun! This week we talk about metric vs. old @@ -79,6 +81,7 @@ Red, Whine, & Blue Various + Red, Whine & Blue Red + Blue != Purple This week we talk about surviving in a Red state if you are a Blue person. Or vice versa. diff --git a/test/Writer/Extension/ITunes/EntryTest.php b/test/Writer/Extension/ITunes/EntryTest.php index fcebcb48..9dafda46 100644 --- a/test/Writer/Extension/ITunes/EntryTest.php +++ b/test/Writer/Extension/ITunes/EntryTest.php @@ -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;