タグ列の番号飛びを許容
This commit is contained in:
parent
41ce5229c7
commit
0ca7b8b7e1
@ -147,15 +147,14 @@ class CheckinCsvImporter
|
|||||||
private function parseTags(int $line, array $record): array
|
private function parseTags(int $line, array $record): array
|
||||||
{
|
{
|
||||||
$tags = [];
|
$tags = [];
|
||||||
for ($i = 1; $i <= 32; $i++) {
|
foreach (array_keys($record) as $column) {
|
||||||
$column = 'タグ' . $i;
|
if (preg_match('/\Aタグ\d{1,2}\z/u', $column) !== 1) {
|
||||||
if (empty($record[$column])) {
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = trim($record[$column]);
|
$tag = trim($record[$column]);
|
||||||
if (empty($tag)) {
|
if (empty($tag)) {
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
if (mb_strlen($tag) > 255) {
|
if (mb_strlen($tag) > 255) {
|
||||||
throw new CsvImportException("{$line} 行 : {$column}は255文字以内にしてください。");
|
throw new CsvImportException("{$line} 行 : {$column}は255文字以内にしてください。");
|
||||||
@ -165,6 +164,9 @@ class CheckinCsvImporter
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tags[] = Tag::firstOrCreate(['name' => $tag]);
|
$tags[] = Tag::firstOrCreate(['name' => $tag]);
|
||||||
|
if (count($tags) >= 32) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tags;
|
return $tags;
|
||||||
|
@ -215,7 +215,7 @@ class CheckinCsvImporterTest extends TestCase
|
|||||||
$importer->execute();
|
$importer->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagCantAcceptJumpedColumnUTF8()
|
public function testTagCanAcceptJumpedColumnUTF8()
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
@ -225,8 +225,9 @@ class CheckinCsvImporterTest extends TestCase
|
|||||||
$tags = $ejaculation->tags()->get();
|
$tags = $ejaculation->tags()->get();
|
||||||
|
|
||||||
$this->assertSame(1, $user->ejaculations()->count());
|
$this->assertSame(1, $user->ejaculations()->count());
|
||||||
$this->assertCount(1, $tags);
|
$this->assertCount(2, $tags);
|
||||||
$this->assertEquals('貧乳', $tags[0]->name);
|
$this->assertEquals('貧乳', $tags[0]->name);
|
||||||
|
$this->assertEquals('巨乳', $tags[1]->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagCantAcceptMultilineUTF8()
|
public function testTagCantAcceptMultilineUTF8()
|
||||||
@ -239,6 +240,20 @@ class CheckinCsvImporterTest extends TestCase
|
|||||||
$importer->execute();
|
$importer->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTagCanAccept32ColumnsUTF8()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/tag-33-column.utf8.csv');
|
||||||
|
$importer->execute();
|
||||||
|
$ejaculation = $user->ejaculations()->first();
|
||||||
|
$tags = $ejaculation->tags()->get();
|
||||||
|
|
||||||
|
$this->assertSame(1, $user->ejaculations()->count());
|
||||||
|
$this->assertCount(32, $tags);
|
||||||
|
$this->assertEquals('み', $tags[31]->name);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSourceIsCsv()
|
public function testSourceIsCsv()
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
|
2
tests/fixture/Csv/tag-33-column.utf8.csv
vendored
Normal file
2
tests/fixture/Csv/tag-33-column.utf8.csv
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
日時,タグ1,タグ2,タグ3,タグ4,タグ5,タグ6,タグ7,タグ8,タグ9,タグ10,タグ11,タグ12,タグ13,タグ14,タグ15,タグ16,タグ17,タグ18,タグ19,タグ20,タグ21,タグ22,タグ23,タグ24,タグ25,タグ26,タグ27,タグ28,タグ29,タグ30,タグ31,タグ32,タグ33
|
||||||
|
2020/01/23 06:01,あ,い,う,え,お,か,き,く,け,こ,さ,し,す,せ,そ,た,ち,つ,て,と,な,に,ぬ,ね,の,は,ひ,ふ,へ,ほ,ま,み,む
|
|
Loading…
Reference in New Issue
Block a user