From 3015f8261180b2f6aea0d3eb101b8c15418fec0b Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 19 Aug 2020 09:46:18 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E9=9D=9E=E5=85=AC=E9=96=8B=E3=83=95?= =?UTF-8?q?=E3=83=A9=E3=82=B0=E3=80=81=E3=82=BB=E3=83=B3=E3=82=B7=E3=83=86?= =?UTF-8?q?=E3=82=A3=E3=83=96=E3=83=95=E3=83=A9=E3=82=B0=E3=81=AECSV?= =?UTF-8?q?=E5=87=BA=E5=8A=9B=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/CheckinCsvExporter.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Services/CheckinCsvExporter.php b/app/Services/CheckinCsvExporter.php index a94ec32..22607a0 100644 --- a/app/Services/CheckinCsvExporter.php +++ b/app/Services/CheckinCsvExporter.php @@ -30,7 +30,7 @@ class CheckinCsvExporter $csv->addStreamFilter('convert.mbstring.encoding.UTF-8:SJIS-win'); } - $header = ['日時', 'ノート', 'オカズリンク']; + $header = ['日時', 'ノート', 'オカズリンク', '非公開', 'センシティブ']; for ($i = 1; $i <= 32; $i++) { $header[] = "タグ{$i}"; } @@ -45,6 +45,8 @@ class CheckinCsvExporter $ejaculation->ejaculated_date->format('Y/m/d H:i'), $ejaculation->note, $ejaculation->link, + self::formatBoolean($ejaculation->is_private), + self::formatBoolean($ejaculation->is_too_sensitive), ]; foreach ($ejaculation->tags->take(32) as $tag) { $record[] = $tag->name; @@ -54,4 +56,9 @@ class CheckinCsvExporter }); }); } + + private static function formatBoolean($value): string + { + return $value ? 'true' : 'false'; + } } From 27e9a86be8ee74bc2f0b62b65d488c81663b1740 Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 19 Aug 2020 21:00:34 +0900 Subject: [PATCH 2/3] add test --- .../Unit/Services/CheckinCsvImporterTest.php | 42 +++++++++++++++++++ tests/fixture/Csv/private.utf8.csv | 10 +++++ tests/fixture/Csv/too-sensitive.utf8.csv | 10 +++++ 3 files changed, 62 insertions(+) create mode 100644 tests/fixture/Csv/private.utf8.csv create mode 100644 tests/fixture/Csv/too-sensitive.utf8.csv diff --git a/tests/Unit/Services/CheckinCsvImporterTest.php b/tests/Unit/Services/CheckinCsvImporterTest.php index 8d208bf..f58ae7e 100644 --- a/tests/Unit/Services/CheckinCsvImporterTest.php +++ b/tests/Unit/Services/CheckinCsvImporterTest.php @@ -277,6 +277,48 @@ class CheckinCsvImporterTest extends TestCase $this->assertEquals(Ejaculation::SOURCE_CSV, $ejaculation->source); } + public function testIsPrivateUTF8() + { + $user = factory(User::class)->create(); + + $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/private.utf8.csv'); + $importer->execute(); + + $ejaculations = $user->ejaculations()->orderBy('ejaculated_date')->get(); + + $this->assertSame(9, $ejaculations->count()); + $this->assertTrue($ejaculations[0]->is_private); + $this->assertTrue($ejaculations[1]->is_private); + $this->assertTrue($ejaculations[2]->is_private); + $this->assertTrue($ejaculations[3]->is_private); + $this->assertFalse($ejaculations[4]->is_private); + $this->assertFalse($ejaculations[5]->is_private); + $this->assertFalse($ejaculations[6]->is_private); + $this->assertFalse($ejaculations[7]->is_private); + $this->assertFalse($ejaculations[8]->is_private); + } + + public function testIsTooSensitiveUTF8() + { + $user = factory(User::class)->create(); + + $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/too-sensitive.utf8.csv'); + $importer->execute(); + + $ejaculations = $user->ejaculations()->orderBy('ejaculated_date')->get(); + + $this->assertSame(9, $ejaculations->count()); + $this->assertTrue($ejaculations[0]->is_too_sensitive); + $this->assertTrue($ejaculations[1]->is_too_sensitive); + $this->assertTrue($ejaculations[2]->is_too_sensitive); + $this->assertTrue($ejaculations[3]->is_too_sensitive); + $this->assertFalse($ejaculations[4]->is_too_sensitive); + $this->assertFalse($ejaculations[5]->is_too_sensitive); + $this->assertFalse($ejaculations[6]->is_too_sensitive); + $this->assertFalse($ejaculations[7]->is_too_sensitive); + $this->assertFalse($ejaculations[8]->is_too_sensitive); + } + public function testDontThrowUniqueKeyViolation() { $user = factory(User::class)->create(); diff --git a/tests/fixture/Csv/private.utf8.csv b/tests/fixture/Csv/private.utf8.csv new file mode 100644 index 0000000..259b893 --- /dev/null +++ b/tests/fixture/Csv/private.utf8.csv @@ -0,0 +1,10 @@ +日時,非公開 +2020/01/23 06:01:00,true +2020/01/23 06:02:00,TRUE +2020/01/23 06:03:00,True +2020/01/23 06:04:00,1 +2020/01/23 07:01:00,false +2020/01/23 07:02:00,FALSE +2020/01/23 07:03:00,False +2020/01/23 07:04:00,0 +2020/01/23 07:05:00, diff --git a/tests/fixture/Csv/too-sensitive.utf8.csv b/tests/fixture/Csv/too-sensitive.utf8.csv new file mode 100644 index 0000000..24cd1ef --- /dev/null +++ b/tests/fixture/Csv/too-sensitive.utf8.csv @@ -0,0 +1,10 @@ +日時,センシティブ +2020/01/23 06:01:00,true +2020/01/23 06:02:00,TRUE +2020/01/23 06:03:00,True +2020/01/23 06:04:00,1 +2020/01/23 07:01:00,false +2020/01/23 07:02:00,FALSE +2020/01/23 07:03:00,False +2020/01/23 07:04:00,0 +2020/01/23 07:05:00, From 915b575e6eb7157cc97c5d1a641bc266d1e681fd Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 19 Aug 2020 21:25:07 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E9=9D=9E=E5=85=AC=E9=96=8B=E3=83=95?= =?UTF-8?q?=E3=83=A9=E3=82=B0=E3=80=81=E3=82=BB=E3=83=B3=E3=82=B7=E3=83=86?= =?UTF-8?q?=E3=82=A3=E3=83=96=E3=83=95=E3=83=A9=E3=82=B0=E3=81=AECSV?= =?UTF-8?q?=E5=85=A5=E5=8A=9B=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Rules/FuzzyBoolean.php | 62 +++++++++++++++++++++++++++++ app/Services/CheckinCsvImporter.php | 9 +++++ 2 files changed, 71 insertions(+) create mode 100644 app/Rules/FuzzyBoolean.php diff --git a/app/Rules/FuzzyBoolean.php b/app/Rules/FuzzyBoolean.php new file mode 100644 index 0000000..ec40d71 --- /dev/null +++ b/app/Rules/FuzzyBoolean.php @@ -0,0 +1,62 @@ + ['required', new CsvDateTime()], 'ノート' => 'nullable|string|max:500', 'オカズリンク' => 'nullable|url|max:2000', + '非公開' => ['nullable', new FuzzyBoolean()], + 'センシティブ' => ['nullable', new FuzzyBoolean()], ]); if ($validator->fails()) { @@ -88,6 +91,12 @@ class CheckinCsvImporter $ejaculation->note = str_replace(["\r\n", "\r"], "\n", $record['ノート'] ?? ''); $ejaculation->link = $record['オカズリンク'] ?? ''; $ejaculation->source = Ejaculation::SOURCE_CSV; + if (isset($record['非公開'])) { + $ejaculation->is_private = FuzzyBoolean::isTruthy($record['非公開']); + } + if (isset($record['センシティブ'])) { + $ejaculation->is_too_sensitive = FuzzyBoolean::isTruthy($record['センシティブ']); + } try { $tags = $this->parseTags($line, $record);