Skip to content

Commit

Permalink
Merge pull request #1345 from shikorism/fix/1323-narou-zap-nbsp
Browse files Browse the repository at this point in the history
NarouResolver: 作品に含まれる要素のキーワードに含まれるnbspを除去
  • Loading branch information
shibafu528 authored Nov 24, 2024
2 parents 84a83d4 + 5ba8ac1 commit 3d2a71d
Show file tree
Hide file tree
Showing 3 changed files with 452 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/MetadataResolver/NarouResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function resolve(string $url): Metadata
// タグ
$keywordNodeList = $xpath->query('//th[contains(text(), "キーワード")]/following-sibling::td[1]');
if ($keywordNodeList->length !== 0) {
$keyword = trim($keywordNodeList->item(0)->textContent);
$metadata->tags = explode(' ', $keyword);
$keyword = trim($keywordNodeList->item(0)->textContent);
$metadata->tags = preg_split('/\s+/u', $keyword);
}

// 作者名
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/MetadataResolver/NarouResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ public function testLongDescriptionNovel()
$this->assertSame('https://novel18.syosetu.com/novelview/infotop/ncode/n0477gn/', (string) $this->handler->getLastRequest()->getUri());
}
}

public function testFeaturesInKeyword()
{
$responseText = $this->fetchSnapshot(__DIR__ . '/../../fixture/Narou/testFeaturesInKeyword.html');

$this->createResolver(NarouResolver::class, $responseText);

$metadata = $this->resolver->resolve('https://novel18.syosetu.com/n6404hk/');
$this->assertEquals('王子繁殖促進計画「王子の性欲を刺激せよ」 ~よってたかって性欲を刺激される小国王子の異世界奮闘記~', $metadata->title);
$this->assertEquals("作者: ひもの\n小国だが王子に転生した俺。 \n意外に甘くない現実に戸惑いつつも、いつかはエロエロハーレムが作れたらいいな、と思っていたが…… \n\n幼馴染が、いとこのお姉ちゃんが、周りの美少女達が、恥じらいながらも一生懸命、俺の性欲を刺激してくる。 \n\nえ? 俺の性欲を刺激するために、国家プロジェクトが立ち上がった?……", $metadata->description);
$this->assertEquals(['残酷な描写あり', '異世界転生', '男主人公', 'ハーレム', '魔法', 'オリジナル戦記', '戦記', '淫語', '羞恥', '美少女', 'イチャラブ', '♡喘ぎ', '孕ませ', '巨乳'], $metadata->tags);
if ($this->shouldUseMock()) {
$this->assertSame('https://novel18.syosetu.com/novelview/infotop/ncode/n6404hk/', (string) $this->handler->getLastRequest()->getUri());
}
}
}
Loading

0 comments on commit 3d2a71d

Please sign in to comment.