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

49 lines
1.9 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);
}
}
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());
$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());
}
}