2020-02-04 01:44:16 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Io;
|
|
|
|
|
|
|
|
use App\Exceptions\CsvImportException;
|
|
|
|
use App\Io\CheckinCsvImporter;
|
2020-02-13 01:03:54 +09:00
|
|
|
use App\User;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Illuminate\Support\Carbon;
|
2020-02-04 01:44:16 +09:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class CheckinCsvImporterTest extends TestCase
|
|
|
|
{
|
2020-02-13 01:03:54 +09:00
|
|
|
use RefreshDatabase;
|
|
|
|
|
2020-02-04 01:44:16 +09:00
|
|
|
public function testIncompatibleCharsetEUCJP()
|
|
|
|
{
|
2020-02-13 01:03:54 +09:00
|
|
|
$user = factory(User::class)->create();
|
2020-02-04 01:44:16 +09:00
|
|
|
$this->expectException(CsvImportException::class);
|
|
|
|
$this->expectExceptionMessage('文字コード判定に失敗しました。UTF-8 (BOM無し) または Shift_JIS をお使いください。');
|
|
|
|
|
2020-02-13 01:03:54 +09:00
|
|
|
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/incompatible-charset.eucjp.csv');
|
2020-02-04 01:44:16 +09:00
|
|
|
$importer->execute();
|
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
/**
|
|
|
|
* @dataProvider provideMissingTime
|
|
|
|
*/
|
|
|
|
public function testMissingTime($filename)
|
2020-02-04 01:44:16 +09:00
|
|
|
{
|
2020-02-13 01:03:54 +09:00
|
|
|
$user = factory(User::class)->create();
|
2020-02-04 01:44:16 +09:00
|
|
|
$this->expectException(CsvImportException::class);
|
|
|
|
$this->expectExceptionMessage('日時列は必須です。');
|
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
$importer = new CheckinCsvImporter($user, $filename);
|
2020-02-04 01:44:16 +09:00
|
|
|
$importer->execute();
|
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
public function provideMissingTime()
|
2020-02-04 01:44:16 +09:00
|
|
|
{
|
2020-02-15 22:53:10 +09:00
|
|
|
return [
|
|
|
|
'UTF8' => [__DIR__ . '/../../fixture/Csv/missing-time.utf8.csv'],
|
|
|
|
'SJIS' => [__DIR__ . '/../../fixture/Csv/missing-time.sjis.csv'],
|
|
|
|
];
|
2020-02-04 01:44:16 +09:00
|
|
|
}
|
2020-02-13 01:03:54 +09:00
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
/**
|
|
|
|
* @dataProvider provideDate
|
|
|
|
*/
|
|
|
|
public function testDate($expectedDate, $filename)
|
2020-02-13 01:03:54 +09:00
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
$importer = new CheckinCsvImporter($user, $filename);
|
2020-02-13 01:03:54 +09:00
|
|
|
$importer->execute();
|
|
|
|
$ejaculation = $user->ejaculations()->first();
|
|
|
|
|
|
|
|
$this->assertSame(1, $user->ejaculations()->count());
|
2020-02-15 22:53:10 +09:00
|
|
|
$this->assertEquals($expectedDate, $ejaculation->ejaculated_date);
|
2020-02-13 01:03:54 +09:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:10 +09:00
|
|
|
public function provideDate()
|
2020-02-13 01:03:54 +09:00
|
|
|
{
|
2020-02-15 22:53:10 +09:00
|
|
|
$date = Carbon::create(2020, 1, 23, 6, 1, 0, 'Asia/Tokyo');
|
|
|
|
|
|
|
|
return [
|
|
|
|
'Zero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date.utf8.csv'],
|
|
|
|
'NoZero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero.utf8.csv'],
|
|
|
|
'Zero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nosecond.utf8.csv'],
|
|
|
|
'NoZero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero-nosecond.utf8.csv'],
|
|
|
|
];
|
2020-02-13 01:03:54 +09:00
|
|
|
}
|
2020-02-04 01:44:16 +09:00
|
|
|
}
|