@@ -15,103 +15,103 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | class ImportTest extends TestCase  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - use RefreshDatabase;  | 
                                                        |
| 18 | + use RefreshDatabase;  | 
                                                        |
| 19 | 19 | |
| 20 | - protected $import;  | 
                                                        |
| 20 | + protected $import;  | 
                                                        |
| 21 | 21 | |
| 22 | - protected function setUp ()  | 
                                                        |
| 23 | -	{ | 
                                                        |
| 24 | - parent::setUp();  | 
                                                        |
| 22 | + protected function setUp ()  | 
                                                        |
| 23 | +    { | 
                                                        |
| 24 | + parent::setUp();  | 
                                                        |
| 25 | 25 | |
| 26 | -	    Route::middleware('web')->group(function() { | 
                                                        |
| 26 | +        Route::middleware('web')->group(function() { | 
                                                        |
| 27 | 27 | |
| 28 | -			Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - });  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | -		Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - $this->import = ModelImport::create([  | 
                                                        |
| 35 | - 'file' => 'imports/test.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 create_new_import_success()  | 
                                                        |
| 46 | -	{ | 
                                                        |
| 47 | -		$import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | - $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 50 | - }  | 
                                                        |
| 51 | -  | 
                                                        |
| 52 | - /**  | 
                                                        |
| 53 | - * @test  | 
                                                        |
| 54 | - */  | 
                                                        |
| 55 | - public function fetch_import()  | 
                                                        |
| 56 | -	{ | 
                                                        |
| 57 | - $import = Import::getImport($this->import->id);  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /**  | 
                                                        |
| 63 | - * @test  | 
                                                        |
| 64 | - */  | 
                                                        |
| 65 | - public function get_few_rows_from_uploaded_file()  | 
                                                        |
| 66 | -	{ | 
                                                        |
| 67 | - $csv_data = Import::getImportFileData($this->import->id);  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - $this->assertInternalType( 'array', $csv_data );  | 
                                                        |
| 70 | - }  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - /**  | 
                                                        |
| 73 | - * @test  | 
                                                        |
| 74 | - */  | 
                                                        |
| 75 | - public function store_data_map_with_csv_cols()  | 
                                                        |
| 76 | -	{ | 
                                                        |
| 77 | - $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);  | 
                                                        |
| 78 | -  | 
                                                        |
| 79 | - $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 80 | - }  | 
                                                        |
| 81 | -  | 
                                                        |
| 82 | - /**  | 
                                                        |
| 83 | - * @test  | 
                                                        |
| 84 | - */  | 
                                                        |
| 85 | - public function sucess_to_dispatch_given_job_class()  | 
                                                        |
| 86 | -	{ | 
                                                        |
| 87 | - $import = $id = $this->import;  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | - Queue::fake();  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - Import::dispatchImportJob( FakeJob::class, $import );  | 
                                                        |
| 92 | -  | 
                                                        |
| 93 | -		Queue::assertPushedOn('importing', FakeJob::class); | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * @test  | 
                                                        |
| 98 | - */  | 
                                                        |
| 99 | - public function check_import_progress()  | 
                                                        |
| 100 | -	{ | 
                                                        |
| 101 | - $response = $this->json( 'GET', '/import/1/progress' );  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | - $response->assertStatus(200);  | 
                                                        |
| 104 | -  | 
                                                        |
| 105 | - $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | - $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 108 | - }  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /**  | 
                                                        |
| 111 | - * @test  | 
                                                        |
| 112 | - */  | 
                                                        |
| 113 | - public function remove_import()  | 
                                                        |
| 114 | -	{ | 
                                                        |
| 115 | - $this->assertTrue(Import::removeImport($this->import->id));  | 
                                                        |
| 116 | - }  | 
                                                        |
| 28 | +            Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + });  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | +        Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + $this->import = ModelImport::create([  | 
                                                        |
| 35 | + 'file' => 'imports/test.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 create_new_import_success()  | 
                                                        |
| 46 | +    { | 
                                                        |
| 47 | +        $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | + $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 50 | + }  | 
                                                        |
| 51 | +  | 
                                                        |
| 52 | + /**  | 
                                                        |
| 53 | + * @test  | 
                                                        |
| 54 | + */  | 
                                                        |
| 55 | + public function fetch_import()  | 
                                                        |
| 56 | +    { | 
                                                        |
| 57 | + $import = Import::getImport($this->import->id);  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * @test  | 
                                                        |
| 64 | + */  | 
                                                        |
| 65 | + public function get_few_rows_from_uploaded_file()  | 
                                                        |
| 66 | +    { | 
                                                        |
| 67 | + $csv_data = Import::getImportFileData($this->import->id);  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + $this->assertInternalType( 'array', $csv_data );  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + /**  | 
                                                        |
| 73 | + * @test  | 
                                                        |
| 74 | + */  | 
                                                        |
| 75 | + public function store_data_map_with_csv_cols()  | 
                                                        |
| 76 | +    { | 
                                                        |
| 77 | + $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);  | 
                                                        |
| 78 | +  | 
                                                        |
| 79 | + $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        |
| 80 | + }  | 
                                                        |
| 81 | +  | 
                                                        |
| 82 | + /**  | 
                                                        |
| 83 | + * @test  | 
                                                        |
| 84 | + */  | 
                                                        |
| 85 | + public function sucess_to_dispatch_given_job_class()  | 
                                                        |
| 86 | +    { | 
                                                        |
| 87 | + $import = $id = $this->import;  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | + Queue::fake();  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + Import::dispatchImportJob( FakeJob::class, $import );  | 
                                                        |
| 92 | +  | 
                                                        |
| 93 | +        Queue::assertPushedOn('importing', FakeJob::class); | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * @test  | 
                                                        |
| 98 | + */  | 
                                                        |
| 99 | + public function check_import_progress()  | 
                                                        |
| 100 | +    { | 
                                                        |
| 101 | + $response = $this->json( 'GET', '/import/1/progress' );  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | + $response->assertStatus(200);  | 
                                                        |
| 104 | +  | 
                                                        |
| 105 | + $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | + $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * @test  | 
                                                        |
| 112 | + */  | 
                                                        |
| 113 | + public function remove_import()  | 
                                                        |
| 114 | +    { | 
                                                        |
| 115 | + $this->assertTrue(Import::removeImport($this->import->id));  | 
                                                        |
| 116 | + }  | 
                                                        |
| 117 | 117 | }  | 
                                                        
@@ -19,22 +19,22 @@ discard block  | 
                                                    ||
| 19 | 19 | |
| 20 | 20 | protected $import;  | 
                                                        
| 21 | 21 | |
| 22 | - protected function setUp ()  | 
                                                        |
| 22 | + protected function setUp()  | 
                                                        |
| 23 | 23 |  	{ | 
                                                        
| 24 | 24 | parent::setUp();  | 
                                                        
| 25 | 25 | |
| 26 | 26 |  	    Route::middleware('web')->group(function() { | 
                                                        
| 27 | 27 | |
| 28 | -			Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); | 
                                                        |
| 28 | +			Route::get('/import/{id}/progress', ['as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); | 
                                                        |
| 29 | 29 | |
| 30 | 30 | });  | 
                                                        
| 31 | 31 | |
| 32 | -		Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); | 
                                                        |
| 32 | +		Storage::putFileAs('imports', new File(storage_path('test/test.csv')), 'test.csv'); | 
                                                        |
| 33 | 33 | |
| 34 | 34 | $this->import = ModelImport::create([  | 
                                                        
| 35 | 35 | 'file' => 'imports/test.csv',  | 
                                                        
| 36 | 36 | 'file_rows' => 104,  | 
                                                        
| 37 | - 'db_cols' => [ 'name', 'email', 'password'],  | 
                                                        |
| 37 | + 'db_cols' => ['name', 'email', 'password'],  | 
                                                        |
| 38 | 38 | 'model_map' => ['email', 'name', 'password']  | 
                                                        
| 39 | 39 | ]);  | 
                                                        
| 40 | 40 | }  | 
                                                        
@@ -44,7 +44,7 @@ discard block  | 
                                                    ||
| 44 | 44 | */  | 
                                                        
| 45 | 45 | public function create_new_import_success()  | 
                                                        
| 46 | 46 |  	{ | 
                                                        
| 47 | -		$import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); | 
                                                        |
| 47 | +		$import = Import::createImport('imports/test.csv', ['name', 'email', 'password']); | 
                                                        |
| 48 | 48 | |
| 49 | 49 | $this->assertInstanceOf(ModelImport::class, $import);  | 
                                                        
| 50 | 50 | }  | 
                                                        
@@ -66,7 +66,7 @@ discard block  | 
                                                    ||
| 66 | 66 |  	{ | 
                                                        
| 67 | 67 | $csv_data = Import::getImportFileData($this->import->id);  | 
                                                        
| 68 | 68 | |
| 69 | - $this->assertInternalType( 'array', $csv_data );  | 
                                                        |
| 69 | +		$this->assertInternalType('array', $csv_data); | 
                                                        |
| 70 | 70 | }  | 
                                                        
| 71 | 71 | |
| 72 | 72 | /**  | 
                                                        
@@ -88,7 +88,7 @@ discard block  | 
                                                    ||
| 88 | 88 | |
| 89 | 89 | Queue::fake();  | 
                                                        
| 90 | 90 | |
| 91 | - Import::dispatchImportJob( FakeJob::class, $import );  | 
                                                        |
| 91 | + Import::dispatchImportJob(FakeJob::class, $import);  | 
                                                        |
| 92 | 92 | |
| 93 | 93 |  		Queue::assertPushedOn('importing', FakeJob::class); | 
                                                        
| 94 | 94 | }  | 
                                                        
@@ -98,13 +98,13 @@ discard block  | 
                                                    ||
| 98 | 98 | */  | 
                                                        
| 99 | 99 | public function check_import_progress()  | 
                                                        
| 100 | 100 |  	{ | 
                                                        
| 101 | - $response = $this->json( 'GET', '/import/1/progress' );  | 
                                                        |
| 101 | +		$response = $this->json('GET', '/import/1/progress'); | 
                                                        |
| 102 | 102 | |
| 103 | 103 | $response->assertStatus(200);  | 
                                                        
| 104 | 104 | |
| 105 | - $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 105 | + $response->assertJsonFragment(['status' => 200]);  | 
                                                        |
| 106 | 106 | |
| 107 | - $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 107 | + $response->assertJsonFragment(['progress']);  | 
                                                        |
| 108 | 108 | }  | 
                                                        
| 109 | 109 | |
| 110 | 110 | /**  | 
                                                        
@@ -16,90 +16,90 @@  | 
                                                    ||
| 16 | 16 | |
| 17 | 17 | class ExportTest extends TestCase  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | - use RefreshDatabase;  | 
                                                        |
| 19 | + use RefreshDatabase;  | 
                                                        |
| 20 | 20 | |
| 21 | - protected $export;  | 
                                                        |
| 21 | + protected $export;  | 
                                                        |
| 22 | 22 | |
| 23 | - protected function setUp ()  | 
                                                        |
| 24 | -	{ | 
                                                        |
| 25 | - parent::setUp();  | 
                                                        |
| 23 | + protected function setUp ()  | 
                                                        |
| 24 | +    { | 
                                                        |
| 25 | + parent::setUp();  | 
                                                        |
| 26 | 26 | |
| 27 | -	    Route::middleware('web')->group(function() { | 
                                                        |
| 27 | +        Route::middleware('web')->group(function() { | 
                                                        |
| 28 | 28 | |
| 29 | -			Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']); | 
                                                        |
| 29 | +            Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']); | 
                                                        |
| 30 | 30 | |
| 31 | -			Route::get( '/export/{id}/download',  [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); | 
                                                        |
| 31 | +            Route::get( '/export/{id}/download',  [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); | 
                                                        |
| 32 | 32 | |
| 33 | - });  | 
                                                        |
| 33 | + });  | 
                                                        |
| 34 | 34 | |
| 35 | -		Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls'); | 
                                                        |
| 35 | +        Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls'); | 
                                                        |
| 36 | 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 | - }  | 
                                                        |
| 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 | 43 | |
| 44 | - /**  | 
                                                        |
| 45 | - * @test  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - public function data_export_initiated_and_dispatched()  | 
                                                        |
| 48 | -	{ | 
                                                        |
| 49 | - Queue::fake();  | 
                                                        |
| 44 | + /**  | 
                                                        |
| 45 | + * @test  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + public function data_export_initiated_and_dispatched()  | 
                                                        |
| 48 | +    { | 
                                                        |
| 49 | + Queue::fake();  | 
                                                        |
| 50 | 50 | |
| 51 | - $export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' );  | 
                                                        |
| 51 | + $export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' );  | 
                                                        |
| 52 | 52 | |
| 53 | - $this->assertInstanceOf( ModelExport::class, $export );  | 
                                                        |
| 53 | + $this->assertInstanceOf( ModelExport::class, $export );  | 
                                                        |
| 54 | 54 | |
| 55 | -		Queue::assertPushedOn('exporting', ExportJob::class); | 
                                                        |
| 56 | - }  | 
                                                        |
| 55 | +        Queue::assertPushedOn('exporting', ExportJob::class); | 
                                                        |
| 56 | + }  | 
                                                        |
| 57 | 57 | |
| 58 | - /**  | 
                                                        |
| 59 | - * @test  | 
                                                        |
| 60 | - */  | 
                                                        |
| 61 | - public function see_export_progress_page()  | 
                                                        |
| 62 | -	{ | 
                                                        |
| 63 | -		$response =  $this->get('/ticket/export/' . $this->export->id); | 
                                                        |
| 58 | + /**  | 
                                                        |
| 59 | + * @test  | 
                                                        |
| 60 | + */  | 
                                                        |
| 61 | + public function see_export_progress_page()  | 
                                                        |
| 62 | +    { | 
                                                        |
| 63 | +        $response =  $this->get('/ticket/export/' . $this->export->id); | 
                                                        |
| 64 | 64 | |
| 65 | - $response->assertStatus(200);  | 
                                                        |
| 65 | + $response->assertStatus(200);  | 
                                                        |
| 66 | 66 | |
| 67 | -		$response->assertSee('Export'); | 
                                                        |
| 68 | - }  | 
                                                        |
| 67 | +        $response->assertSee('Export'); | 
                                                        |
| 68 | + }  | 
                                                        |
| 69 | 69 | |
| 70 | - /**  | 
                                                        |
| 71 | - * @test  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - public function check_export_progress_ajax()  | 
                                                        |
| 74 | -	{ | 
                                                        |
| 75 | - $response = $this->json( 'GET', '/export/' . $this->export->id . '/progress');  | 
                                                        |
| 70 | + /**  | 
                                                        |
| 71 | + * @test  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + public function check_export_progress_ajax()  | 
                                                        |
| 74 | +    { | 
                                                        |
| 75 | + $response = $this->json( 'GET', '/export/' . $this->export->id . '/progress');  | 
                                                        |
| 76 | 76 | |
| 77 | - $response->assertStatus(200);  | 
                                                        |
| 77 | + $response->assertStatus(200);  | 
                                                        |
| 78 | 78 | |
| 79 | - $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 79 | + $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 80 | 80 | |
| 81 | - $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 82 | - }  | 
                                                        |
| 81 | + $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 82 | + }  | 
                                                        |
| 83 | 83 | |
| 84 | - /**  | 
                                                        |
| 85 | - * @test  | 
                                                        |
| 86 | - */  | 
                                                        |
| 87 | - public function try_download_exported_file()  | 
                                                        |
| 88 | -	{ | 
                                                        |
| 89 | -		$response = $this->get('/export/' . $this->export->id . '/download'); | 
                                                        |
| 84 | + /**  | 
                                                        |
| 85 | + * @test  | 
                                                        |
| 86 | + */  | 
                                                        |
| 87 | + public function try_download_exported_file()  | 
                                                        |
| 88 | +    { | 
                                                        |
| 89 | +        $response = $this->get('/export/' . $this->export->id . '/download'); | 
                                                        |
| 90 | 90 | |
| 91 | - $response->assertHeader( 'content-disposition', 'attachment; filename="test.xls"');  | 
                                                        |
| 91 | + $response->assertHeader( 'content-disposition', 'attachment; filename="test.xls"');  | 
                                                        |
| 92 | 92 | |
| 93 | - $response->assertStatus(200);  | 
                                                        |
| 94 | - }  | 
                                                        |
| 93 | + $response->assertStatus(200);  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | 95 | |
| 96 | - /**  | 
                                                        |
| 97 | - * @test  | 
                                                        |
| 98 | - */  | 
                                                        |
| 99 | - public function fail_download_exported_file()  | 
                                                        |
| 100 | -	{ | 
                                                        |
| 101 | -		$response = $this->get('/export/987654321/download'); | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * @test  | 
                                                        |
| 98 | + */  | 
                                                        |
| 99 | + public function fail_download_exported_file()  | 
                                                        |
| 100 | +    { | 
                                                        |
| 101 | +        $response = $this->get('/export/987654321/download'); | 
                                                        |
| 102 | 102 | |
| 103 | - $response->assertStatus(404);  | 
                                                        |
| 104 | - }  | 
                                                        |
| 103 | + $response->assertStatus(404);  | 
                                                        |
| 104 | + }  | 
                                                        |
| 105 | 105 | }  | 
                                                        
@@ -20,23 +20,23 @@ discard block  | 
                                                    ||
| 20 | 20 | |
| 21 | 21 | protected $export;  | 
                                                        
| 22 | 22 | |
| 23 | - protected function setUp ()  | 
                                                        |
| 23 | + protected function setUp()  | 
                                                        |
| 24 | 24 |  	{ | 
                                                        
| 25 | 25 | parent::setUp();  | 
                                                        
| 26 | 26 | |
| 27 | 27 |  	    Route::middleware('web')->group(function() { | 
                                                        
| 28 | 28 | |
| 29 | -			Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']); | 
                                                        |
| 29 | +			Route::get('/ticket/export/{id}', ['as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']); | 
                                                        |
| 30 | 30 | |
| 31 | -			Route::get( '/export/{id}/download',  [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); | 
                                                        |
| 31 | +			Route::get('/export/{id}/download', ['as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); | 
                                                        |
| 32 | 32 | |
| 33 | 33 | });  | 
                                                        
| 34 | 34 | |
| 35 | -		Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls'); | 
                                                        |
| 35 | +		Storage::putFileAs('exports', new File(storage_path('test/test.csv')), 'test.xls'); | 
                                                        |
| 36 | 36 | |
| 37 | 37 | $this->export = ModelExport::create([  | 
                                                        
| 38 | 38 | 'file' => 'test.xls',  | 
                                                        
| 39 | - 'query' => \App\Models\User::select([ 'name', 'email', 'created_at' ])->getModel(),  | 
                                                        |
| 39 | + 'query' => \App\Models\User::select(['name', 'email', 'created_at'])->getModel(),  | 
                                                        |
| 40 | 40 | 'type' => 'xls'  | 
                                                        
| 41 | 41 | ]);  | 
                                                        
| 42 | 42 | }  | 
                                                        
@@ -48,9 +48,9 @@ discard block  | 
                                                    ||
| 48 | 48 |  	{ | 
                                                        
| 49 | 49 | Queue::fake();  | 
                                                        
| 50 | 50 | |
| 51 | - $export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' );  | 
                                                        |
| 51 | + $export = Export::export(\App\Models\User::select(['name', 'email', 'created_at']), 'xls');  | 
                                                        |
| 52 | 52 | |
| 53 | - $this->assertInstanceOf( ModelExport::class, $export );  | 
                                                        |
| 53 | + $this->assertInstanceOf(ModelExport::class, $export);  | 
                                                        |
| 54 | 54 | |
| 55 | 55 |  		Queue::assertPushedOn('exporting', ExportJob::class); | 
                                                        
| 56 | 56 | }  | 
                                                        
@@ -60,7 +60,7 @@ discard block  | 
                                                    ||
| 60 | 60 | */  | 
                                                        
| 61 | 61 | public function see_export_progress_page()  | 
                                                        
| 62 | 62 |  	{ | 
                                                        
| 63 | -		$response =  $this->get('/ticket/export/' . $this->export->id); | 
                                                        |
| 63 | +		$response = $this->get('/ticket/export/'.$this->export->id); | 
                                                        |
| 64 | 64 | |
| 65 | 65 | $response->assertStatus(200);  | 
                                                        
| 66 | 66 | |
@@ -72,13 +72,13 @@ discard block  | 
                                                    ||
| 72 | 72 | */  | 
                                                        
| 73 | 73 | public function check_export_progress_ajax()  | 
                                                        
| 74 | 74 |  	{ | 
                                                        
| 75 | - $response = $this->json( 'GET', '/export/' . $this->export->id . '/progress');  | 
                                                        |
| 75 | +		$response = $this->json('GET', '/export/'.$this->export->id.'/progress'); | 
                                                        |
| 76 | 76 | |
| 77 | 77 | $response->assertStatus(200);  | 
                                                        
| 78 | 78 | |
| 79 | - $response->assertJsonFragment( ['status' => 200] );  | 
                                                        |
| 79 | + $response->assertJsonFragment(['status' => 200]);  | 
                                                        |
| 80 | 80 | |
| 81 | - $response->assertJsonFragment( ['progress'] );  | 
                                                        |
| 81 | + $response->assertJsonFragment(['progress']);  | 
                                                        |
| 82 | 82 | }  | 
                                                        
| 83 | 83 | |
| 84 | 84 | /**  | 
                                                        
@@ -86,9 +86,9 @@ discard block  | 
                                                    ||
| 86 | 86 | */  | 
                                                        
| 87 | 87 | public function try_download_exported_file()  | 
                                                        
| 88 | 88 |  	{ | 
                                                        
| 89 | -		$response = $this->get('/export/' . $this->export->id . '/download'); | 
                                                        |
| 89 | +		$response = $this->get('/export/'.$this->export->id.'/download'); | 
                                                        |
| 90 | 90 | |
| 91 | - $response->assertHeader( 'content-disposition', 'attachment; filename="test.xls"');  | 
                                                        |
| 91 | +		$response->assertHeader('content-disposition', 'attachment; filename="test.xls"'); | 
                                                        |
| 92 | 92 | |
| 93 | 93 | $response->assertStatus(200);  | 
                                                        
| 94 | 94 | }  | 
                                                        
@@ -3,13 +3,13 @@  | 
                                                    ||
| 3 | 3 | return [  | 
                                                        
| 4 | 4 | // Route for export process ajax  | 
                                                        
| 5 | 5 | 'export_progress' => [  | 
                                                        
| 6 | -    	'url' => '/export/{id}/progress', | 
                                                        |
| 7 | - 'name' => 'ladybirdweb.export.ajax.progress'  | 
                                                        |
| 6 | +        'url' => '/export/{id}/progress', | 
                                                        |
| 7 | + 'name' => 'ladybirdweb.export.ajax.progress'  | 
                                                        |
| 8 | 8 | ],  | 
                                                        
| 9 | 9 | |
| 10 | 10 | // Route for download exported file  | 
                                                        
| 11 | 11 | 'export_download' => [  | 
                                                        
| 12 | -    	'url' => '/export/{id}/download', | 
                                                        |
| 13 | - 'name' => 'ladybirdweb.export.download'  | 
                                                        |
| 12 | +        'url' => '/export/{id}/download', | 
                                                        |
| 13 | + 'name' => 'ladybirdweb.export.download'  | 
                                                        |
| 14 | 14 | ]  | 
                                                        
| 15 | 15 | ];  | 
                                                        
@@ -3,7 +3,7 @@  | 
                                                    ||
| 3 | 3 | return [  | 
                                                        
| 4 | 4 | // Route for import process ajax  | 
                                                        
| 5 | 5 | 'import_progress' => [  | 
                                                        
| 6 | -    	'url' => '/import/{id}/progress', | 
                                                        |
| 7 | - 'name' => 'ladybirdweb.import.ajax.progress'  | 
                                                        |
| 6 | +        'url' => '/import/{id}/progress', | 
                                                        |
| 7 | + 'name' => 'ladybirdweb.import.ajax.progress'  | 
                                                        |
| 8 | 8 | ]  | 
                                                        
| 9 | 9 | ];  | 
                                                        
@@ -3,12 +3,12 @@  | 
                                                    ||
| 3 | 3 |  Route::middleware('web')->group(function() { | 
                                                        
| 4 | 4 | |
| 5 | 5 | // Ajax GET import progress  | 
                                                        
| 6 | -Route::get( config( 'import.import_progress.url' ), [ 'as' => config( 'import.import_progress.name' ), 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']);  | 
                                                        |
| 6 | +Route::get(config('import.import_progress.url'), ['as' => config('import.import_progress.name'), 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); | 
                                                        |
| 7 | 7 | |
| 8 | 8 | // Ajax GET export progress  | 
                                                        
| 9 | -Route::get( config( 'export.export_progress.url' ), [ 'as' => config( 'export.export_progress.name' ), 'uses' => 'Ladybirdweb\ImportExport\Export@returnExportProgress']);  | 
                                                        |
| 9 | +Route::get(config('export.export_progress.url'), ['as' => config('export.export_progress.name'), 'uses' => 'Ladybirdweb\ImportExport\Export@returnExportProgress']); | 
                                                        |
| 10 | 10 | |
| 11 | 11 | // GET export download  | 
                                                        
| 12 | -Route::get( config( 'export.export_download.url' ), [ 'as' => config( 'export.export_download.name' ), 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']);  | 
                                                        |
| 12 | +Route::get(config('export.export_download.url'), ['as' => config('export.export_download.name'), 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']); | 
                                                        |
| 13 | 13 | |
| 14 | 14 | });  | 
                                                        
@@ -18,7 +18,7 @@ discard block  | 
                                                    ||
| 18 | 18 | // Store file path and model class to db  | 
                                                        
| 19 | 19 | $import = ModelImport::create([  | 
                                                        
| 20 | 20 | 'file' => $path,  | 
                                                        
| 21 | - 'file_rows' => count( file( storage_path( 'app/' . $path ) ) ) - 1,  | 
                                                        |
| 21 | +            'file_rows' => count(file(storage_path('app/'.$path))) - 1, | 
                                                        |
| 22 | 22 | 'db_cols' => $columns  | 
                                                        
| 23 | 23 | ]);  | 
                                                        
| 24 | 24 | |
@@ -33,28 +33,28 @@ discard block  | 
                                                    ||
| 33 | 33 | */  | 
                                                        
| 34 | 34 | public function getImport($id)  | 
                                                        
| 35 | 35 |      { | 
                                                        
| 36 | - return ModelImport::findOrFail( $id );  | 
                                                        |
| 36 | + return ModelImport::findOrFail($id);  | 
                                                        |
| 37 | 37 | }  | 
                                                        
| 38 | 38 | |
| 39 | 39 | public function getImportFileData($id, $rows = 5)  | 
                                                        
| 40 | 40 |      { | 
                                                        
| 41 | 41 | // Get import instance  | 
                                                        
| 42 | - $import = $this->getImport( $id );  | 
                                                        |
| 42 | + $import = $this->getImport($id);  | 
                                                        |
| 43 | 43 | |
| 44 | 44 | // Read 5 rows from csv  | 
                                                        
| 45 | 45 | $read_line = 1;  | 
                                                        
| 46 | 46 | |
| 47 | - $file = fopen( storage_path( 'app/' . $import->file ), 'r' );  | 
                                                        |
| 47 | +        $file = fopen(storage_path('app/'.$import->file), 'r'); | 
                                                        |
| 48 | 48 | |
| 49 | -        while ( $csv_line = fgetcsv( $file ) ) { | 
                                                        |
| 49 | +        while ($csv_line = fgetcsv($file)) { | 
                                                        |
| 50 | 50 | $csv_data[] = $csv_line;  | 
                                                        
| 51 | 51 | |
| 52 | - if ( $read_line > $rows ) break;  | 
                                                        |
| 52 | + if ($read_line > $rows) break;  | 
                                                        |
| 53 | 53 | |
| 54 | 54 | $read_line++;  | 
                                                        
| 55 | 55 | }  | 
                                                        
| 56 | 56 | |
| 57 | - fclose( $file );  | 
                                                        |
| 57 | + fclose($file);  | 
                                                        |
| 58 | 58 | |
| 59 | 59 | return $csv_data;  | 
                                                        
| 60 | 60 | }  | 
                                                        
@@ -107,11 +107,11 @@ discard block  | 
                                                    ||
| 107 | 107 | $data['progress'] = round(($import->row_processed / $import->file_rows) * 100);  | 
                                                        
| 108 | 108 | |
| 109 | 109 | // If progress completed return successful imported rows count  | 
                                                        
| 110 | -        if ( $data['progress'] == 100 ) { | 
                                                        |
| 110 | +        if ($data['progress'] == 100) { | 
                                                        |
| 111 | 111 | $data['imported'] = $import->row_imported;  | 
                                                        
| 112 | 112 | }  | 
                                                        
| 113 | 113 | |
| 114 | - return response()->json( $data );  | 
                                                        |
| 114 | + return response()->json($data);  | 
                                                        |
| 115 | 115 | }  | 
                                                        
| 116 | 116 | |
| 117 | 117 | |
@@ -124,7 +124,7 @@ discard block  | 
                                                    ||
| 124 | 124 | public function removeImport($id)  | 
                                                        
| 125 | 125 |      { | 
                                                        
| 126 | 126 | // Get import instance  | 
                                                        
| 127 | - $import = $this->getImport( $id );  | 
                                                        |
| 127 | + $import = $this->getImport($id);  | 
                                                        |
| 128 | 128 | |
| 129 | 129 | // Remove a import from db  | 
                                                        
| 130 | 130 | return $import->delete();  | 
                                                        
@@ -49,7 +49,9 @@  | 
                                                    ||
| 49 | 49 |          while ( $csv_line = fgetcsv( $file ) ) { | 
                                                        
| 50 | 50 | $csv_data[] = $csv_line;  | 
                                                        
| 51 | 51 | |
| 52 | - if ( $read_line > $rows ) break;  | 
                                                        |
| 52 | +            if ( $read_line > $rows ) { | 
                                                        |
| 53 | + break;  | 
                                                        |
| 54 | + }  | 
                                                        |
| 53 | 55 | |
| 54 | 56 | $read_line++;  | 
                                                        
| 55 | 57 | }  |