You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

<?php
namespace Tests\Unit;
use App\Services\Crawl\Adapters\HuxiuHtmlAdapter;
use Tests\TestCase;
class HuxiuHtmlAdapterTest extends TestCase
{
public function test_resolves_channel_id_from_url(): void
{
$adapter = new HuxiuHtmlAdapter(
app(\App\Services\Crawl\NewsCategoryMatcher::class),
app(\App\Services\Crawl\NewsHtmlImageLocalizer::class),
);
$method = new \ReflectionMethod($adapter, 'resolveChannelId');
$method->setAccessible(true);
$this->assertSame(115, $method->invoke($adapter, 'https://www.huxiu.com/channel/115.html'));
$this->assertNull($method->invoke($adapter, 'https://www.huxiu.com/article/123.html'));
}
public function test_fetches_article_detail_via_api(): void
{
$adapter = new HuxiuHtmlAdapter(
app(\App\Services\Crawl\NewsCategoryMatcher::class),
app(\App\Services\Crawl\NewsHtmlImageLocalizer::class),
);
$method = new \ReflectionMethod($adapter, 'fetchArticleDetail');
$method->setAccessible(true);
$detail = $method->invoke($adapter, 'https://www.huxiu.com/article/4869203.html');
$this->assertNotEmpty($detail['title']);
$this->assertNotEmpty($detail['content_html']);
$this->assertGreaterThan(200, mb_strlen(strip_tags((string) $detail['content_html'])));
}
}