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.

43 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Tests\Unit;
use App\Models\CrawlSource;
use App\Services\Crawl\CrawlSourceResolver;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CrawlSourceResolverTest extends TestCase
{
use RefreshDatabase;
public function test_resolves_ai_sjtu_center_to_research_center_api(): void
{
CrawlSource::query()->create([
'name' => '师资列表页(通用 HTML',
'target_type' => 'teacher',
'adapter_code' => 'faculty_list_html',
'entry_url' => 'https://',
'match_domains' => ['*'],
'status' => 1,
'sort' => 30,
]);
CrawlSource::query()->create([
'name' => '交大人工智能研究院研究中心',
'target_type' => 'teacher',
'adapter_code' => 'ai_sjtu_research_center_api',
'entry_url' => 'https://ai.sjtu.edu.cn/center',
'match_domains' => ['ai.sjtu.edu.cn'],
'status' => 1,
'sort' => 25,
]);
$resolver = new CrawlSourceResolver;
$source = $resolver->resolve('https://ai.sjtu.edu.cn/center', 'teacher');
$this->assertNotNull($source);
$this->assertSame('ai_sjtu_research_center_api', $source->adapter_code);
}
}