mirror of
https://github.com/Chouchen/ShikiryuRSS.git
synced 2025-10-27 01:23:07 +01:00
40
tests/BasicBuilderTest.php
Normal file
40
tests/BasicBuilderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shikiryu\SRSS\Builder\SRSSBuilder;
|
||||
use Shikiryu\SRSS\Entity\Item;
|
||||
use Shikiryu\SRSS\SRSS;
|
||||
use Shikiryu\SRSS\SRSSTools;
|
||||
|
||||
class BasicBuilderTest extends TestCase
|
||||
{
|
||||
public function testCreateBasicRSS()
|
||||
{
|
||||
$srss = SRSS::create();
|
||||
$srss->title = 'My Blog';
|
||||
$srss->description = 'is the best';
|
||||
$srss->link = 'http://shikiryu.com/devblog/';
|
||||
$items = [
|
||||
['title' => 'title 1', 'link' => 'http://shikiryu.com/devblog/article-1', 'pubDate' => SRSSTools::getRSSDate('2012-03-05 12:02:01'), 'description' => 'description 1'],
|
||||
['title' => 'title 2', 'link' => 'http://shikiryu.com/devblog/article-2', 'pubDate' => SRSSTools::getRSSDate('2022-03-05 22:02:02'), 'description' => 'description 2'],
|
||||
['title' => 'title 3', 'link' => 'http://shikiryu.com/devblog/article-3', 'pubDate' => SRSSTools::getRSSDate('2032-03-05 32:02:03'), 'description' => 'description 3'],
|
||||
['title' => 'title 4', 'link' => 'http://shikiryu.com/devblog/article-4', 'pubDate' => SRSSTools::getRSSDate('2042-03-05 42:02:04'), 'description' => 'description 4'],
|
||||
];
|
||||
foreach ($items as $item) {
|
||||
$rssItem = new Item();
|
||||
$rssItem->title = $item['title'];
|
||||
$rssItem->link = $item['link'];
|
||||
$rssItem->pubDate = $item['pubDate'];
|
||||
$rssItem->description = $item['description'];
|
||||
$srss->addItem($rssItem);
|
||||
}
|
||||
|
||||
self::assertTrue($srss->isValid());
|
||||
|
||||
$filepath = __DIR__.'/resources/tmp/build/testCreateBasicRSS.rss';
|
||||
$builder = new SRSSBuilder();
|
||||
$builder->build($srss, $filepath);
|
||||
|
||||
self::assertFileExists($filepath);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shikiryu\SRSS\Exception\SRSSException;
|
||||
use Shikiryu\SRSS\SRSS;
|
||||
use Shikiryu\SRSS\SRSSException;
|
||||
|
||||
class BasicReader extends TestCase
|
||||
class BasicReaderTest extends TestCase
|
||||
{
|
||||
public function testReadBasicRSS()
|
||||
{
|
||||
@@ -14,7 +14,7 @@ class BasicReader extends TestCase
|
||||
self::assertNotNull($first_item);
|
||||
self::assertEquals('RSS Tutorial', $first_item->title);
|
||||
|
||||
self::assertTrue($rss->channel->isValid());
|
||||
self::assertTrue($rss->isValid());
|
||||
}
|
||||
|
||||
public function testRssNotFound()
|
||||
@@ -41,6 +41,6 @@ class BasicReader extends TestCase
|
||||
self::assertEquals('http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp', $rss->getLast()->link);
|
||||
self::assertEquals('Fri, 30 May 2003 11:06:42 GMT', $rss->getItem(2)->pubDate);
|
||||
|
||||
self::assertTrue($rss->channel->isValid());
|
||||
self::assertTrue($rss->isValid());
|
||||
}
|
||||
}
|
||||
@@ -7,25 +7,25 @@ class MediaTest extends TestCase
|
||||
{
|
||||
public function testImages()
|
||||
{
|
||||
$rss = SRSS::read('resources/media/cnn.xml');
|
||||
$rss = SRSS::read(__DIR__.'/resources/media/cnn.xml');
|
||||
self::assertEquals('CNN.com - RSS Channel - Entertainment', $rss->title);
|
||||
|
||||
$first_item = $rss->getFirst();
|
||||
self::assertEquals('Kirstie Alley, \'Cheers\' and \'Veronica\'s Closet\' star, dead at 71', $first_item->title);
|
||||
|
||||
self::assertEquals('https://cdn.cnn.com/cnnnext/dam/assets/221205172141-kirstie-alley-2005-super-169.jpg', $first_item->medias[0]->url);
|
||||
self::assertTrue($rss->channel->isValid(), var_export($rss->channel->validated, true));
|
||||
self::assertTrue($rss->isValid(), var_export($rss->channel->validated, true));
|
||||
}
|
||||
|
||||
public function testMusicVideo()
|
||||
{
|
||||
$rss = SRSS::read('resources/media/music-video.xml');
|
||||
$rss = SRSS::read(__DIR__.'/resources/media/music-video.xml');
|
||||
self::assertEquals('Music Videos 101', $rss->title);
|
||||
|
||||
self::assertCount(1, $rss->items);
|
||||
|
||||
$first_item = $rss->getFirst();
|
||||
self::assertEquals('http://www.foo.com/movie.mov', $first_item->medias[0]->url);
|
||||
self::assertTrue($rss->channel->isValid());
|
||||
self::assertTrue($rss->isValid());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user