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\Export; |
14
|
|
|
use Ladybirdweb\ImportExport\Jobs\ExportJob; |
15
|
|
|
use Ladybirdweb\ImportExport\Models\Export as ModelExport; |
16
|
|
|
|
17
|
|
|
class ExportTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
use RefreshDatabase; |
20
|
|
|
|
21
|
|
|
protected $export; |
22
|
|
|
|
23
|
|
|
protected function setUp () |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
Route::middleware('web')->group(function() { |
28
|
|
|
|
29
|
|
|
Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']); |
30
|
|
|
|
31
|
|
|
Route::get( '/export/{id}/download', [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); |
32
|
|
|
|
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls'); |
36
|
|
|
|
37
|
|
|
$this->export = ModelExport::create([ |
38
|
|
|
'file' => 'test.xls', |
39
|
|
|
'query' => \App\Models\User::select([ 'name', 'email', 'created_at' ])->getModel(), |
|
|
|
|
40
|
|
|
'type' => 'xls' |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function data_export_initiated_and_dispatched() |
48
|
|
|
{ |
49
|
|
|
Queue::fake(); |
50
|
|
|
|
51
|
|
|
$export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' ); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf( ModelExport::class, $export ); |
54
|
|
|
|
55
|
|
|
Queue::assertPushedOn('exporting', ExportJob::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
*/ |
61
|
|
|
public function see_export_progress_page() |
62
|
|
|
{ |
63
|
|
|
$response = $this->get('/ticket/export/' . $this->export->id); |
64
|
|
|
|
65
|
|
|
$response->assertStatus(200); |
66
|
|
|
|
67
|
|
|
$response->assertSee('Export'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function check_export_progress_ajax() |
74
|
|
|
{ |
75
|
|
|
$response = $this->json( 'GET', '/export/' . $this->export->id . '/progress'); |
76
|
|
|
|
77
|
|
|
$response->assertStatus(200); |
78
|
|
|
|
79
|
|
|
$response->assertJsonFragment( ['status' => 200] ); |
80
|
|
|
|
81
|
|
|
$response->assertJsonFragment( ['progress'] ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
*/ |
87
|
|
|
public function try_download_exported_file() |
88
|
|
|
{ |
89
|
|
|
$response = $this->get('/export/' . $this->export->id . '/download'); |
90
|
|
|
|
91
|
|
|
$response->assertHeader( 'content-disposition', 'attachment; filename="test.xls"'); |
92
|
|
|
|
93
|
|
|
$response->assertStatus(200); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @test |
98
|
|
|
*/ |
99
|
|
|
public function fail_download_exported_file() |
100
|
|
|
{ |
101
|
|
|
$response = $this->get('/export/' . rand(1, 100) . '/download'); |
102
|
|
|
|
103
|
|
|
$response->assertStatus(404); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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