Skip to content

Commit

Permalink
小説情報ページに対応 長い説明文のテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
eai04191 committed Feb 13, 2021
1 parent a124059 commit 360e107
Show file tree
Hide file tree
Showing 4 changed files with 426 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/MetadataResolver/MetadataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MetadataResolver implements Resolver
'~dmm\.co\.jp/~' => FanzaResolver::class,
'~www\.patreon\.com/~' => PatreonResolver::class,
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
'~\.syosetu\.com/n\d+[a-z]+~' => NarouResolver::class,
'~\.syosetu\.com/(novelview/infotop/ncode/)?n\d+[a-z]+~' => NarouResolver::class,
'~ci-en\.(jp|net|dlsite\.com)/creator/\d+/article/\d+~' => CienResolver::class,
'~www\.plurk\.com\/p\/.*~' => PlurkResolver::class,
'~store\.steampowered\.com/app/\d+~' => SteamResolver::class,
Expand Down
2 changes: 1 addition & 1 deletion app/MetadataResolver/NarouResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function resolve(string $url): Metadata
$cookieJar = CookieJar::fromArray(['over18' => 'yes'], '.syosetu.com');


preg_match('~\.syosetu\.com/(?P<ncode>n\d+[a-z]+)~', $url, $matches);
preg_match('~\.syosetu\.com/(novelview/infotop/ncode/)?(?P<ncode>n\d+[a-z]+)~', $url, $matches);
$ncode = $matches['ncode'];

$res = $this->client->get("https://novel18.syosetu.com/novelview/infotop/ncode/$ncode/", ['cookies' => $cookieJar]);
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/MetadataResolver/NarouResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,34 @@ public function testNovel()
$this->assertSame('https://novel18.syosetu.com/novelview/infotop/ncode/n2978fx/', (string) $this->handler->getLastRequest()->getUri());
}
}

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

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

$metadata = $this->resolver->resolve('https://novel18.syosetu.com/novelview/infotop/ncode/n2978fx/');
$this->assertEquals('ぱんつ売りの少女', $metadata->title);
$this->assertEquals("作者: 飴宮 地下\n冴えない男「ハルノ・ヒトキ」が仕事からの帰宅途中で美少女に声を掛けられる。\n驚いた事に少女の目的は自分の下着を売る事だった。\nお金に困っていた少女は徐々にヒトキに下着を売っていたが段々とその内容がエスカレートして行き……。", $metadata->description);
$this->assertEquals(['ギャグ', '男主人公', '現代', '下着', '匂いフェチ', 'ブルセラ'], $metadata->tags);
if ($this->shouldUseMock()) {
$this->assertSame('https://novel18.syosetu.com/novelview/infotop/ncode/n2978fx/', (string) $this->handler->getLastRequest()->getUri());
}
}

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

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

$metadata = $this->resolver->resolve('https://novel18.syosetu.com/n0477gn/');
$this->assertEquals('俺のことが好き過ぎる双子の天才妹が、「妹と結婚して子作りすること」を合法化して二人がかりで精液を搾りとってくる話', $metadata->title);
$this->assertEquals("作者: 伍式\n巨大財閥の跡取りである高校生「菊川笙(きくかわしょう)」。その双子の妹、貧乳美尻丁寧語の「菊川琴(こと)」と巨乳巨尻甘えん坊の「菊川鈴(すず)」。\n巨大財閥を実質的に動かしている天才双子妹は、しかし兄を盲愛して兄の精液で孕みたいと固く決意しているダブルブラコン妹だった。\nある時妹たち二人と一緒に高級……", $metadata->description);
$this->assertEquals(['ほのぼの', '男主人公', '', 'いちゃらぶ', '近親相姦', 'オナニー', '見せつけ', '尻合わせ', '孕ませっくす', '自慰', '尻ズリ', '兄妹', '双子', 'だいしゅきホールド', '膝立ちバック'], $metadata->tags);
if ($this->shouldUseMock()) {
$this->assertSame('https://novel18.syosetu.com/novelview/infotop/ncode/n0477gn/', (string) $this->handler->getLastRequest()->getUri());
}
}
}
Loading

0 comments on commit 360e107

Please sign in to comment.