1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-12-23 05:01:36 +01:00
ShikiryuRSS/tests/OriginalReaderSRSSTest.php

42 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;
2023-04-17 14:28:01 +02:00
use Shikiryu\SRSS\Validator\Formator;
2023-04-11 14:07:13 +02:00
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);
2023-04-17 14:28:01 +02:00
self::assertEquals('<![CDATA[ Liftoff News ]]>', $rss->title);
2023-04-11 14:07:13 +02:00
$article1 = $rss->getItem(1);
$articleFirst = $rss->getFirst();
self::assertEquals($article1, $articleFirst);
$links = [];
foreach($rss as $article) {
2023-04-17 14:28:01 +02:00
$links[] = sprintf('<a href="%s">%s %s</a>', $article->link, SRSSTools::getRSSDate('d/m/y', $article->pubDate), $article->title);
2023-04-11 14:07:13 +02:00
}
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);
}
}