1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Tests\TestCase; |
|
|
|
|
6
|
|
|
use Illuminate\Http\File; |
7
|
|
|
use Illuminate\Http\UploadedFile; |
8
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
9
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware; |
10
|
|
|
use Illuminate\Support\Facades\Queue; |
11
|
|
|
use Illuminate\Support\Facades\Route; |
12
|
|
|
use Illuminate\Support\Facades\Storage; |
13
|
|
|
use Ladybirdweb\ImportExport\Facades\Import; |
14
|
|
|
use Ladybirdweb\ImportExport\Models\Import as ModelImport; |
15
|
|
|
|
16
|
|
|
class ImportTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
use RefreshDatabase; |
19
|
|
|
|
20
|
|
|
protected $import; |
21
|
|
|
|
22
|
|
|
protected function setUp () |
23
|
|
|
{ |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
Route::middleware('web')->group(function() { |
27
|
|
|
|
28
|
|
|
Route::get('ticket/import', ['as' => 'ticket.import', 'uses' => 'Ladybirdweb\ImportExport\Import@showImportForm'] ); |
29
|
|
|
Route::post('ticket/import', ['as' => 'ticket.import', 'uses' => 'Ladybirdweb\ImportExport\Import@uploadImportFile'] ); |
30
|
|
|
|
31
|
|
|
Route::get('/ticket/import/{id}/map', [ 'as' => 'ticket.import.show.map', 'uses' => 'Ladybirdweb\ImportExport\Import@showColumnsMapForm']); |
32
|
|
|
Route::post('/ticket/import/{id}', [ 'as' => 'ticket.import.map', 'uses' => 'Ladybirdweb\ImportExport\Import@storeColumnsMap']); |
33
|
|
|
|
34
|
|
|
Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); |
35
|
|
|
|
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); |
39
|
|
|
|
40
|
|
|
$this->import = ModelImport::create([ |
41
|
|
|
'file' => 'imports/test.csv', |
42
|
|
|
'file_rows' => 104, |
43
|
|
|
'db_cols' => [ 'name', 'email', 'password'], |
44
|
|
|
'model_map' => ['email', 'name', 'password'] |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test |
50
|
|
|
*/ |
51
|
|
|
public function see_import_form() |
52
|
|
|
{ |
53
|
|
|
Import::setUploadRoute('ticket.import'); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$response = $this->get('ticket/import'); |
56
|
|
|
|
57
|
|
|
$response->assertSee( 'importer' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @test |
62
|
|
|
*/ |
63
|
|
|
public function try_file_upload() |
64
|
|
|
{ |
65
|
|
|
Storage::fake('file'); |
66
|
|
|
|
67
|
|
|
$response = $this->json( 'POST', '/ticket/import', [ |
68
|
|
|
'file' => UploadedFile::fake()->create('file.csv', 100) |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
$response->assertStatus(200); |
72
|
|
|
|
73
|
|
|
$response->assertJsonFragment( ['status' => 'ready'] ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function fail_file_upload() |
80
|
|
|
{ |
81
|
|
|
Storage::fake('file'); |
82
|
|
|
|
83
|
|
|
$response = $this->json( 'POST', '/ticket/import', [ |
84
|
|
|
'file' => UploadedFile::fake()->image('file.jpg') |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
$response->assertStatus(200); |
88
|
|
|
|
89
|
|
|
$response->assertJsonFragment( ['status' => 'failed'] ); |
90
|
|
|
|
91
|
|
|
$this->assertArrayHasKey( 'errors', Import::getImportErrors() ); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @test |
96
|
|
|
*/ |
97
|
|
|
public function map_data_with_csv_cols() |
98
|
|
|
{ |
99
|
|
|
Import::setImportMapRoute('ticket.import.map'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$id = $this->import->id; |
102
|
|
|
|
103
|
|
|
$response = $this->get('/ticket/import/' . $id . '/map'); |
104
|
|
|
|
105
|
|
|
$response->assertStatus(200); |
106
|
|
|
|
107
|
|
|
$response->assertSee( 'Confirm Import' ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @test |
112
|
|
|
*/ |
113
|
|
|
public function store_data_map_with_csv_cols() |
114
|
|
|
{ |
115
|
|
|
$id = $this->import->id; |
116
|
|
|
|
117
|
|
|
$response = $this->post( '/ticket/import/' . $id, [ |
118
|
|
|
'db_column' => ['email', 'name', 'password'] |
119
|
|
|
] ); |
120
|
|
|
|
121
|
|
|
$response->assertStatus(200); |
122
|
|
|
|
123
|
|
|
$response->assertSessionMissing( 'errors' ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @test |
128
|
|
|
*/ |
129
|
|
|
public function store_data_map_with_csv_cols_failed_validation() |
130
|
|
|
{ |
131
|
|
|
$id = $this->import->id; |
132
|
|
|
|
133
|
|
|
$response = $this->post( '/ticket/import/' . $id, [ |
134
|
|
|
'db_column' => ['name', 'name', 'name'] |
135
|
|
|
] ); |
136
|
|
|
|
137
|
|
|
$response->assertStatus(302); |
138
|
|
|
|
139
|
|
|
$response->assertSessionHas( 'errors' ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @test |
144
|
|
|
*/ |
145
|
|
|
public function sucess_to_dispatch_given_job_class() |
146
|
|
|
{ |
147
|
|
|
$import = $id = $this->import; |
|
|
|
|
148
|
|
|
|
149
|
|
|
Queue::fake(); |
150
|
|
|
|
151
|
|
|
Import::dispatchImportJob( FakeJob::class, $import ); |
|
|
|
|
152
|
|
|
|
153
|
|
|
Queue::assertPushedOn('importing', FakeJob::class); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @test |
158
|
|
|
*/ |
159
|
|
|
public function check_import_progress() |
160
|
|
|
{ |
161
|
|
|
$response = $this->json( 'GET', '/import/1/progress' ); |
162
|
|
|
|
163
|
|
|
$response->assertStatus(200); |
164
|
|
|
|
165
|
|
|
$response->assertJsonFragment( ['status' => 200] ); |
166
|
|
|
|
167
|
|
|
$response->assertJsonFragment( ['progress'] ); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths