fedi-feed-router/tests/Unit/Services/Parsers/GuardianArticleParserTest.php
myrmidex 6784af2ff6
Some checks failed
CI / ci (push) Failing after 4m31s
25 - Fix all PHPStan errors and add mockery extension
2026-03-08 14:18:28 +01:00

63 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit\Services\Parsers;
use App\Contracts\ArticleParserInterface;
use App\Services\Parsers\GuardianArticleParser;
use Tests\TestCase;
class GuardianArticleParserTest extends TestCase
{
private GuardianArticleParser $parser;
protected function setUp(): void
{
parent::setUp();
$this->parser = new GuardianArticleParser;
}
public function test_implements_article_parser_interface(): void
{
$this->assertInstanceOf(ArticleParserInterface::class, $this->parser);
}
public function test_can_parse_guardian_url(): void
{
$this->assertTrue($this->parser->canParse('https://www.theguardian.com/world/2026/mar/08/some-article'));
}
public function test_can_parse_guardian_url_without_www(): void
{
$this->assertTrue($this->parser->canParse('https://theguardian.com/world/2026/mar/08/some-article'));
}
public function test_cannot_parse_non_guardian_url(): void
{
$this->assertFalse($this->parser->canParse('https://www.vrt.be/vrtnws/en/article'));
$this->assertFalse($this->parser->canParse('https://www.belganewsagency.eu/article'));
}
public function test_get_source_name(): void
{
$this->assertEquals('The Guardian', $this->parser->getSourceName());
}
public function test_extract_data_delegates_to_page_parser(): void
{
$html = '
<html>
<head>
<meta property="og:title" content="Test Title"/>
<meta property="og:description" content="Test Description"/>
</head>
<body><p>Content</p></body>
</html>
';
$data = $this->parser->extractData($html);
$this->assertIsArray($data);
$this->assertArrayHasKey('title', $data);
$this->assertEquals('Test Title', $data['title']);
}
}