master
parent
bd8527fc55
commit
780a7a24e2
@ -0,0 +1,38 @@
|
||||
<?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'])));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue