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.

50 lines
1.3 KiB

<?php
namespace Tests\Unit;
use App\Models\CrawlAddress;
use App\Services\Crawl\CrawlAddressSourceResolver;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CrawlAddressSourceResolverTest extends TestCase
{
use RefreshDatabase;
public function test_resolves_source_by_request_url(): void
{
CrawlAddress::query()->create([
'target_type' => 'industry_news',
'name' => '交大要闻',
'request_url' => 'https://news.sjtu.edu.cn/jdyw/index.html',
'sort' => 0,
'status' => 1,
]);
$resolver = new CrawlAddressSourceResolver;
$this->assertSame(
'交大要闻',
$resolver->resolveByRequestUrl('https://news.sjtu.edu.cn/jdyw/index.html'),
);
}
public function test_resolves_source_by_article_host(): void
{
CrawlAddress::query()->create([
'target_type' => 'industry_news',
'name' => '南大要闻',
'request_url' => 'https://www.nju.edu.cn/xww/zhxw.htm',
'sort' => 0,
'status' => 1,
]);
$resolver = new CrawlAddressSourceResolver;
$this->assertSame(
'南大要闻',
$resolver->resolveBySourceUrl('https://www.nju.edu.cn/xww/2026/0310/article.html'),
);
}
}