68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Services\Autopodbor\Agent\Fetch\FetchedSite;
|
||
|
|
use App\Services\Autopodbor\Agent\Fetch\Fetcher;
|
||
|
|
use App\Services\Autopodbor\Agent\Study\SiteOpener;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class);
|
||
|
|
uses(SharesSupplierPdo::class);
|
||
|
|
|
||
|
|
function seedOpenerRange(): void
|
||
|
|
{
|
||
|
|
$importId = (int) DB::table('phone_ranges_imports')->insertGetId([
|
||
|
|
'source_url' => 'https://rossvyaz.gov.ru/test',
|
||
|
|
'checksum_sha256' => str_repeat('c', 64),
|
||
|
|
'status' => 'completed',
|
||
|
|
'imported_at' => now(),
|
||
|
|
]);
|
||
|
|
|
||
|
|
DB::table('phone_ranges')->insert([
|
||
|
|
'def_code' => 391,
|
||
|
|
'from_num' => 2000000,
|
||
|
|
'to_num' => 2999999,
|
||
|
|
'operator' => 'Ростелеком',
|
||
|
|
'region' => 'Красноярский край',
|
||
|
|
'subject_code' => 24,
|
||
|
|
'imported_at' => now(),
|
||
|
|
'import_id' => $importId,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Fetcher, отдающий фиксированный HTML. */
|
||
|
|
function openerFetcher(string $html): Fetcher
|
||
|
|
{
|
||
|
|
return new class($html) implements Fetcher
|
||
|
|
{
|
||
|
|
public function __construct(private string $html) {}
|
||
|
|
|
||
|
|
public function site(string $url): FetchedSite
|
||
|
|
{
|
||
|
|
return new FetchedSite($url, $this->html);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function directory(string $url): array
|
||
|
|
{
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
it('глубокий путь: мусорный номер (код вне реестра) не попадает в numbers', function (): void {
|
||
|
|
seedOpenerRange(); // есть только 391 2000000..2999999
|
||
|
|
|
||
|
|
// Настоящий 73912920000 (391) + мусор 76132306130 (код 613, вне реестра).
|
||
|
|
$html = '<a href="tel:+73912920000">звонок</a>'
|
||
|
|
.' <span>+7 613 230 61 30</span>';
|
||
|
|
|
||
|
|
$r = (new SiteOpener(openerFetcher($html)))->open('kraslombard24.ru', '391');
|
||
|
|
|
||
|
|
$numbers = collect($r->numbers)->pluck('number');
|
||
|
|
expect($numbers)->toContain('73912920000')
|
||
|
|
->and($numbers)->not->toContain('76132306130');
|
||
|
|
});
|