1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-11-22 19:58:51 +01:00
ShikiryuRSS/tests/BasicReaderTest.php

99 lines
4.5 KiB
PHP
Raw Normal View History

<?php
use PHPUnit\Framework\TestCase;
2023-04-12 14:41:45 +02:00
use Shikiryu\SRSS\Entity\Channel\Category;
use Shikiryu\SRSS\Entity\Channel\Cloud;
use Shikiryu\SRSS\Entity\Channel\Image;
use Shikiryu\SRSS\Entity\Item;
use Shikiryu\SRSS\SRSS;
class BasicReaderTest extends TestCase
{
2023-04-12 15:28:38 +02:00
public function testReadBasicRSS(): void
{
$rss = SRSS::read(__DIR__.'/resources/basic.xml');
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ test Home Page ]]>', $rss->title);
$first_item = $rss->getFirst();
self::assertNotNull($first_item);
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ RSS Tutorial ]]>', $first_item->title);
2023-04-07 00:35:20 +02:00
self::assertTrue($rss->isValid());
}
2023-04-12 15:28:38 +02:00
public function testSpecificationExampleRSS(): void
2023-04-06 11:07:06 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/harvard.xml');
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ Liftoff News ]]>', $rss->title);
2023-04-06 11:07:06 +02:00
self::assertEquals('http://liftoff.msfc.nasa.gov/', $rss->link);
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ Liftoff to Space Exploration. ]]>', $rss->description);
2023-04-06 11:07:06 +02:00
self::assertEquals('en-us', $rss->language);
2023-04-17 14:28:01 +02:00
self::assertEquals('Tue, 10 Jun 2003 04:00:00 UTC', $rss->pubDate);
self::assertEquals('Tue, 10 Jun 2003 09:41:01 UTC', $rss->lastBuildDate);
2023-04-06 11:07:06 +02:00
self::assertEquals('http://blogs.law.harvard.edu/tech/rss', $rss->docs);
self::assertEquals('Weblog Editor 2.0', $rss->generator);
self::assertEquals('editor@example.com', $rss->managingEditor);
self::assertEquals('webmaster@example.com', $rss->webMaster);
self::assertCount(4, $rss->items);
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ Star City ]]>', $rss->getFirst()->title);
2023-04-06 11:07:06 +02:00
self::assertEquals('http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp', $rss->getLast()->link);
2023-04-17 14:28:01 +02:00
self::assertEquals('Fri, 30 May 2003 11:06:42 UTC', $rss->getItem(2)->pubDate);
2023-04-07 00:35:20 +02:00
self::assertTrue($rss->isValid());
2023-04-06 11:07:06 +02:00
}
2023-04-12 14:41:45 +02:00
2023-04-12 15:28:38 +02:00
public function testChannelImage(): void
2023-04-12 14:41:45 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/media/cnn.xml');
$image = $rss->image;
self::assertInstanceOf(Image::class, $image);
self::assertEquals('http://i2.cdn.turner.com/cnn/2015/images/09/24/cnn.digital.png', $image->url, var_export($image, true));
self::assertEquals('CNN.com - RSS Channel - Entertainment', $image->title, var_export($image, true));
self::assertEquals('https://www.cnn.com/entertainment/index.html', $image->link, var_export($image, true));
}
2023-04-12 15:28:38 +02:00
public function testChannelCategory(): void
2023-04-12 14:41:45 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/cloud.xml');
$categories = $rss->category;
self::assertCount(1, $categories);
$category = $categories[0];
self::assertInstanceOf(Category::class, $category);
self::assertEquals('http://www.weblogs.com/rssUpdates/changes.xml', $category->domain, var_export($category, true));
self::assertEquals('rssUpdates', $category->value, var_export($category, true));
}
2023-04-12 15:28:38 +02:00
public function testCloud(): void
2023-04-12 14:41:45 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/cloud.xml');
$cloud = $rss->cloud;
self::assertInstanceOf(Cloud::class, $cloud);
self::assertEquals('radio.xmlstoragesystem.com', $cloud->domain, var_export($cloud, true));
self::assertEquals('80', $cloud->port, var_export($cloud, true));
self::assertEquals('/RPC2', $cloud->path, var_export($cloud, true));
self::assertEquals('xmlStorageSystem.rssPleaseNotify', $cloud->registerProcedure, var_export($cloud, true));
self::assertEquals('xml-rpc', $cloud->protocol, var_export($cloud, true));
}
2023-04-12 15:28:38 +02:00
public function testSource(): void
2023-04-12 14:41:45 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/basic.xml');
$firstItem = $rss->getFirst();
self::assertInstanceOf(Item::class, $firstItem);
$source = $firstItem->source;
self::assertInstanceOf(Item\Source::class, $source);
self::assertEquals('http://www.tomalak.org/links2.xml', $source->url);
self::assertEquals('Tomalak\'s Realm', $source->value);
}
2023-04-12 15:28:38 +02:00
public function testEnclosure(): void
2023-04-12 14:41:45 +02:00
{
$rss = SRSS::read(__DIR__.'/resources/basic.xml');
$item = $rss->getItem(2);
self::assertInstanceOf(Item::class, $item);
$enclosure = $item->enclosure;
self::assertInstanceOf(Item\Enclosure::class, $enclosure);
self::assertEquals('http://www.scripting.com/mp3s/touchOfGrey.mp3', $enclosure->url);
self::assertEquals('5588242', $enclosure->length);
self::assertEquals('audio/mpeg', $enclosure->type);
}
}