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