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.
33 lines
1.0 KiB
33 lines
1.0 KiB
|
6 days ago
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Unit;
|
||
|
|
|
||
|
|
use App\Services\Crawl\HtmlPagination;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
class HtmlPaginationTest extends TestCase
|
||
|
|
{
|
||
|
|
public function test_builds_sjtu_style_page_urls(): void
|
||
|
|
{
|
||
|
|
$base = 'https://news.sjtu.edu.cn/jdyw/index.html';
|
||
|
|
|
||
|
|
$this->assertSame($base, HtmlPagination::buildPageUrl($base, 1, ''));
|
||
|
|
$this->assertSame(
|
||
|
|
'https://news.sjtu.edu.cn/jdyw/index_2.html',
|
||
|
|
HtmlPagination::buildPageUrl($base, 2, '<a href="index_2.html">2</a>')
|
||
|
|
);
|
||
|
|
$this->assertSame(
|
||
|
|
'https://news.sjtu.edu.cn/jdyw/index_5.html',
|
||
|
|
HtmlPagination::buildPageUrl($base, 5, '<a href="index_5.html">末页</a>')
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_detects_max_page_from_index_underscore_links(): void
|
||
|
|
{
|
||
|
|
$html = '<a href="index.html">1</a><a href="index_2.html">2</a><a href="index_8.html">8</a>';
|
||
|
|
$base = 'https://news.sjtu.edu.cn/jdyw/index.html';
|
||
|
|
|
||
|
|
$this->assertSame(8, HtmlPagination::detectTotalPages($html, $base));
|
||
|
|
}
|
||
|
|
}
|