Files
coruna-lab/tests/Unit/NoteContentTest.php
T
2026-09-08 04:53:35 +08:00

87 lines
3.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Unit;
use App\Support\NoteContent;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class NoteContentTest extends TestCase
{
#[Test]
public function splits_string_notes_and_strips_apple_notes_junk(): void
{
$items = NoteContent::fromList([
"扫描2\nhello body\n\n(\n(\n \n\$A8917AB7-F855-4E16-A794-B7B8DF44C783com.apple.notes.gallery",
['id' => 26, 'mod' => 0, 'title' => '新备忘录', 'snippet' => ''],
"密码285591",
]);
$this->assertCount(3, $items);
$this->assertSame('扫描2', $items[0]['title']);
$this->assertStringContainsString('hello body', $items[0]['body']);
$this->assertStringNotContainsString('com.apple.notes.gallery', $items[0]['body']);
$this->assertSame('新备忘录', $items[1]['title']);
$this->assertSame(26, $items[1]['native_id']);
$this->assertSame('密码285591', $items[2]['title']);
}
#[Test]
public function hash_is_stable_and_titles_preview(): void
{
$items = NoteContent::fromList(['alpha', 'beta', 'gamma']);
$this->assertSame(NoteContent::hash($items), NoteContent::hash($items));
$this->assertSame(['alpha', 'beta'], NoteContent::titles($items, 2));
}
#[Test]
public function drops_empty_junk_only_items(): void
{
$this->assertSame([], NoteContent::fromList(["\n(\n\t (\n"]));
}
#[Test]
public function keeps_title_as_body_when_rest_is_notes_junk(): void
{
$items = NoteContent::fromList(["spawn rabbit unusual favorite yard recipe\n(R(R"]);
$this->assertCount(1, $items);
$this->assertSame('spawn rabbit unusual favorite yard recipe', $items[0]['title']);
$this->assertSame('spawn rabbit unusual favorite yard recipe', $items[0]['body']);
}
#[Test]
public function cuts_attributed_string_suffix(): void
{
$raw = "8月行事曆\n8.11\n買冬季校服+领夏季校服\n中一适应课程(9:00-11:15)\n<(\n?(\n>(\n{(\nP(!\nR(\"\n[(#\na($\n|(%\n~ ('\nN\n(+\nhבĦ\ncom.apple.drawing.2";
$items = NoteContent::fromList([$raw]);
$this->assertCount(1, $items);
$this->assertSame('8月行事曆', $items[0]['title']);
$this->assertStringContainsString('中一适应课程(9:00-11:15)', $items[0]['body']);
$this->assertStringNotContainsString('<(', $items[0]['body']);
$this->assertStringNotContainsString('P(!', $items[0]['body']);
$this->assertStringNotContainsString('com.apple.drawing', $items[0]['body']);
$this->assertStringNotContainsString('Ħ', $items[0]['body']);
}
#[Test]
public function cuts_ascii_soup_line_after_real_text(): void
{
$items = NoteContent::fromList(["武汉\n帽子\n泡面\n(210/.-qponmlk+*)('&%\$#\"!"]);
$this->assertSame('武汉', $items[0]['title']);
$this->assertStringContainsString('泡面', $items[0]['body']);
$this->assertStringNotContainsString('qponmlk', $items[0]['body']);
}
#[Test]
public function cuts_long_protobuf_alphabet_dump(): void
{
$raw = "Face à lui...\nJe peux aussi respecter la crainte.\nLouis\n(\u{FFFD}%\u{FFFD}jKKKdcccbaa`]\\V^[QJIHQG>QQFFFQOOOOONNQMMMLLQQQL^DCBA@?~}||{zonlk77777762110/111115443,++8! .--&&\$#*&&&%&1GoB";
$items = NoteContent::fromList([$raw]);
$this->assertSame('Face à lui...', $items[0]['title']);
$this->assertStringContainsString('Je peux aussi respecter la crainte.', $items[0]['body']);
$this->assertStringContainsString('Louis', $items[0]['body']);
$this->assertStringNotContainsString('KKKdcccbaa', $items[0]['body']);
$this->assertStringNotContainsString('zonlk777', $items[0]['body']);
}
}