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

56 lines
2.2 KiB
PHP
Raw Normal View History

<?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
{
2023-04-11 14:07:13 +02:00
private string $saved = __DIR__.'/resources/tmp/build/testCreateBasicRSS.rss';
protected function tearDown(): void
{
parent::tearDown();
if (file_exists($this->saved)) {
unlink($this->saved);
}
}
2023-04-12 15:28:38 +02:00
public function testCreateBasicRSS(): void
{
$title = 'My Blog';
$description = 'is the best';
$link = 'http://shikiryu.com/devblog/';
$srss = SRSS::create();
$srss->title = $title;
$srss->description = $description;
$srss->link = $link;
$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());
self::assertEquals($title, $srss->title);
self::assertEquals($description, $srss->description);
self::assertEquals($link, $srss->link);
$builder = new SRSSBuilder();
2023-04-11 14:07:13 +02:00
$builder->build($srss, $this->saved);
self::assertFileExists($this->saved);
2023-04-11 14:07:13 +02:00
self::assertIsString($srss->show());
}
}