public function test() { $channel = new Channel(); $pubDate = new \DateTime('2001-01-01', new \DateTimeZone('UTC')); $lastBuildDate = new \DateTime('2001-01-01', new \DateTimeZone('UTC')); $item1 = new Item(); $item2 = new Item(); $ext1 = new \StdClass(); $ext2 = new \StdClass(); $cloud = new Cloud(); $image = new Image(); $channel->setTitle('My Title')->setLink('https://www.example.com')->setDescription('My Description')->setLanguage('en')->setCopyright('(c) 2016 Acme')->setManagingEditor('John Doe <*****@*****.**>')->setWebMaster('Jane Doe <*****@*****.**')->setPubDate($pubDate)->setLastBuildDate($lastBuildDate)->setDocs('http://example.com/rss2-spec')->setGenerator('Generator v1')->setCloud($cloud)->setTtl(60)->setImage($image)->setRating('R')->setItems([$item1])->addItem($item2)->setExtensions([$ext1])->addExtension($ext2)->setWebMaster('Jane Doe <*****@*****.**'); $this->assertSame('My Title', $channel->getTitle()); $this->assertSame('https://www.example.com', $channel->getLink()); $this->assertSame('My Description', $channel->getDescription()); $this->assertSame('en', $channel->getLanguage()); $this->assertSame('(c) 2016 Acme', $channel->getCopyright()); $this->assertSame('John Doe <*****@*****.**>', $channel->getManagingEditor()); $this->assertSame('Jane Doe <*****@*****.**', $channel->getWebMaster()); $this->assertSame($pubDate, $channel->getPubDate()); $this->assertSame($lastBuildDate, $channel->getLastBuildDate()); $this->assertSame('http://example.com/rss2-spec', $channel->getDocs()); $this->assertSame('Generator v1', $channel->getGenerator()); $this->assertSame($cloud, $channel->getCloud()); $this->assertSame(60, $channel->getTtl()); $this->assertSame($image, $channel->getImage()); $this->assertSame('R', $channel->getRating()); $this->assertSame([$item1, $item2], $channel->getItems()); $this->assertSame([$ext1, $ext2], $channel->getExtensions()); }
public function writeChannel(RssWriter $rssWriter, Channel $channel) { $writer = $rssWriter->getXmlWriter(); $writer->startElement('channel'); $writer->startElement('title'); $writer->writeCdata($channel->getTitle()); $writer->endElement(); $writer->writeElement('link', $channel->getLink()); $writer->startElement('description'); $writer->writeCdata($channel->getDescription()); $writer->endElement(); if ($channel->getLanguage()) { $writer->writeElement('language', $channel->getLanguage()); } if ($channel->getCopyright()) { $writer->startElement('copyright'); $writer->writeCdata($channel->getCopyright()); $writer->endElement(); } if ($channel->getManagingEditor()) { $writer->startElement('managingEditor'); $writer->writeCdata($channel->getManagingEditor()); $writer->endElement(); } if ($channel->getWebMaster()) { $writer->startElement('webMaster'); $writer->writeCdata($channel->getWebMaster()); $writer->endElement(); } if ($channel->getPubDate()) { $writer->writeElement('pubDate', $channel->getPubDate()->format('r')); } if ($channel->getLastBuildDate()) { $writer->writeElement('lastBuildDate', $channel->getLastBuildDate()->format('r')); } foreach ($channel->getCategories() as $category) { $this->writeCategory($writer, $category); } if ($channel->getGenerator()) { $writer->startElement('generator'); $writer->writeCdata($channel->getGenerator()); $writer->endElement(); } if ($channel->getDocs()) { $writer->writeElement('docs', $channel->getDocs()); } if ($channel->getCloud()) { $this->writeCloud($writer, $channel->getCloud()); } if ($channel->getTtl()) { $writer->writeElement('ttl', $channel->getTtl()); } if ($channel->getImage()) { $this->writeImage($writer, $channel->getImage()); } if ($channel->getRating()) { $writer->writeElement('rating', $channel->getRating()); } foreach ($channel->getExtensions() as $extension) { $rssWriter->writeObject($extension); } foreach ($channel->getItems() as $item) { $rssWriter->writeObject($item); } $writer->endElement(); }