1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Orchestra\Testbench\TestCase; |
6
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
7
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware; |
8
|
|
|
use Ladybirdweb\ImportExport\Facades\ImportExportLog; |
9
|
|
|
use Ladybirdweb\ImportExport\Models\ImportExportLog as ModelImportExportLog; |
10
|
|
|
use Ladybirdweb\ImportExport\Models\Import; |
11
|
|
|
|
12
|
|
|
class ImportExportLogTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
use RefreshDatabase; |
|
|
|
|
15
|
|
|
|
16
|
|
|
protected $import; |
17
|
|
|
|
18
|
|
|
protected function getPackageProviders($app) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
return ['Ladybirdweb\ImportExport\ImportExportServiceProvider']; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function getEnvironmentSetUp($app) |
24
|
|
|
{ |
25
|
|
|
$app['config']->set('database.default', 'testing'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function setUp () |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->artisan('migrate', ['--database' => 'testing']); |
33
|
|
|
|
34
|
|
|
$this->import = Import::create([ |
35
|
|
|
'file' => 'imports/import-1530262997.csv', |
36
|
|
|
'file_rows' => 104, |
37
|
|
|
'db_cols' => [ 'name', 'email', 'password'], |
38
|
|
|
'model_map' => ['email', 'name', 'password'] |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function save_new_log() |
46
|
|
|
{ |
47
|
|
|
$import = $this->import; |
48
|
|
|
|
49
|
|
|
$result = ImportExportLog::logImportError( $import, ['data' => 'this is test data'], 'This is not expected' ); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf( ModelImportExportLog::class, $result ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function get_saved_logs() |
58
|
|
|
{ |
59
|
|
|
$import = $this->import; |
60
|
|
|
|
61
|
|
|
$log = ImportExportLog::logImportError( $import, ['data' => 'this is test data'], 'This is not expected' ); |
62
|
|
|
|
63
|
|
|
$log_in_db = ImportExportLog::getLogs( $log->id ); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$this->assertInternalType( 'array', $log_in_db ); |
66
|
|
|
|
67
|
|
|
$this->assertArrayHasKey( 'data', $log_in_db[0] ); |
68
|
|
|
|
69
|
|
|
$this->assertArrayHasKey( 'message', $log_in_db[0] ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|