1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-12-22 04:41:37 +01:00
ShikiryuRSS/tests/OriginalReaderSRSSTest.php

41 lines
1.2 KiB
PHP
Raw Normal View History

2023-04-11 14:07:13 +02:00
<?php
use PHPUnit\Framework\TestCase;
use Shikiryu\SRSS\SRSS;
use Shikiryu\SRSS\SRSSTools;
class OriginalReaderSRSSTest extends TestCase
{
private string $original = __DIR__.'/resources/harvard.xml';
private string $saved = __DIR__.'/resources/tmp/build/rss.xml';
protected function tearDown(): void
{
parent::tearDown();
if (file_exists($this->saved)) {
unlink($this->saved);
}
}
2023-04-12 15:28:38 +02:00
public function testOriginalReader(): void
2023-04-11 14:07:13 +02:00
{
$rss = SRSS::read($this->original);
self::assertEquals('Liftoff News', $rss->title);
$article1 = $rss->getItem(1);
$articleFirst = $rss->getFirst();
self::assertEquals($article1, $articleFirst);
$links = [];
foreach($rss as $article) {
$links[] = sprintf('<a href="%s">%s %s</a>', $article->link, SRSSTools::formatDate('d/m/y', $article->pubDate), $article->title);
}
self::assertCount(4, $links, var_export($links, true));
$rssArray = $rss->toArray();
self::assertCount(11, $rssArray, var_export($rssArray, true)); // 11 elements in RSS
$rss->save($this->saved);
self::assertFileExists($this->saved);
}
}