@@ -15,110 +15,110 @@ |
||
| 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 getPackageProviders($app) |
|
| 23 | - { |
|
| 24 | - return ['Ladybirdweb\ImportExport\ImportExportServiceProvider']; |
|
| 25 | - } |
|
| 22 | + protected function getPackageProviders($app) |
|
| 23 | + { |
|
| 24 | + return ['Ladybirdweb\ImportExport\ImportExportServiceProvider']; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function setUp () |
|
| 28 | - { |
|
| 29 | - parent::setUp(); |
|
| 27 | + protected function setUp () |
|
| 28 | + { |
|
| 29 | + parent::setUp(); |
|
| 30 | 30 | |
| 31 | - $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
|
| 31 | + $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
|
| 32 | 32 | |
| 33 | - Route::middleware('web')->group(function() { |
|
| 33 | + Route::middleware('web')->group(function() { |
|
| 34 | 34 | |
| 35 | - Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); |
|
| 36 | - |
|
| 37 | - }); |
|
| 38 | - |
|
| 39 | - Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); |
|
| 40 | - |
|
| 41 | - $this->import = ModelImport::create([ |
|
| 42 | - 'file' => 'imports/test.csv', |
|
| 43 | - 'file_rows' => 104, |
|
| 44 | - 'db_cols' => [ 'name', 'email', 'password'], |
|
| 45 | - 'model_map' => ['email', 'name', 'password'] |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @test |
|
| 51 | - */ |
|
| 52 | - public function create_new_import_success() |
|
| 53 | - { |
|
| 54 | - $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); |
|
| 55 | - |
|
| 56 | - $this->assertInstanceOf(ModelImport::class, $import); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @test |
|
| 61 | - */ |
|
| 62 | - public function fetch_import() |
|
| 63 | - { |
|
| 64 | - $import = Import::getImport($this->import->id); |
|
| 65 | - |
|
| 66 | - $this->assertInstanceOf(ModelImport::class, $import); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @test |
|
| 71 | - */ |
|
| 72 | - public function get_few_rows_from_uploaded_file() |
|
| 73 | - { |
|
| 74 | - $csv_data = Import::getImportFileData($this->import->id); |
|
| 75 | - |
|
| 76 | - $this->assertInternalType( 'array', $csv_data ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @test |
|
| 81 | - */ |
|
| 82 | - public function store_data_map_with_csv_cols() |
|
| 83 | - { |
|
| 84 | - $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id); |
|
| 85 | - |
|
| 86 | - $this->assertInstanceOf(ModelImport::class, $import); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @test |
|
| 91 | - */ |
|
| 92 | - public function sucess_to_dispatch_given_job_class() |
|
| 93 | - { |
|
| 94 | - $import = $id = $this->import; |
|
| 95 | - |
|
| 96 | - Queue::fake(); |
|
| 97 | - |
|
| 98 | - Import::dispatchImportJob( FakeJob::class, $import ); |
|
| 99 | - |
|
| 100 | - Queue::assertPushedOn('importing', FakeJob::class); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @test |
|
| 105 | - */ |
|
| 106 | - public function check_import_progress() |
|
| 107 | - { |
|
| 108 | - $response = $this->json( 'GET', '/import/1/progress' ); |
|
| 109 | - |
|
| 110 | - $response->assertStatus(200); |
|
| 111 | - |
|
| 112 | - $response->assertJsonFragment( ['status' => 200] ); |
|
| 113 | - |
|
| 114 | - $response->assertJsonFragment( ['progress'] ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @test |
|
| 119 | - */ |
|
| 120 | - public function remove_import() |
|
| 121 | - { |
|
| 122 | - $this->assertTrue(Import::removeImport($this->import->id)); |
|
| 123 | - } |
|
| 35 | + Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); |
|
| 36 | + |
|
| 37 | + }); |
|
| 38 | + |
|
| 39 | + Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); |
|
| 40 | + |
|
| 41 | + $this->import = ModelImport::create([ |
|
| 42 | + 'file' => 'imports/test.csv', |
|
| 43 | + 'file_rows' => 104, |
|
| 44 | + 'db_cols' => [ 'name', 'email', 'password'], |
|
| 45 | + 'model_map' => ['email', 'name', 'password'] |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @test |
|
| 51 | + */ |
|
| 52 | + public function create_new_import_success() |
|
| 53 | + { |
|
| 54 | + $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); |
|
| 55 | + |
|
| 56 | + $this->assertInstanceOf(ModelImport::class, $import); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @test |
|
| 61 | + */ |
|
| 62 | + public function fetch_import() |
|
| 63 | + { |
|
| 64 | + $import = Import::getImport($this->import->id); |
|
| 65 | + |
|
| 66 | + $this->assertInstanceOf(ModelImport::class, $import); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @test |
|
| 71 | + */ |
|
| 72 | + public function get_few_rows_from_uploaded_file() |
|
| 73 | + { |
|
| 74 | + $csv_data = Import::getImportFileData($this->import->id); |
|
| 75 | + |
|
| 76 | + $this->assertInternalType( 'array', $csv_data ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @test |
|
| 81 | + */ |
|
| 82 | + public function store_data_map_with_csv_cols() |
|
| 83 | + { |
|
| 84 | + $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id); |
|
| 85 | + |
|
| 86 | + $this->assertInstanceOf(ModelImport::class, $import); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @test |
|
| 91 | + */ |
|
| 92 | + public function sucess_to_dispatch_given_job_class() |
|
| 93 | + { |
|
| 94 | + $import = $id = $this->import; |
|
| 95 | + |
|
| 96 | + Queue::fake(); |
|
| 97 | + |
|
| 98 | + Import::dispatchImportJob( FakeJob::class, $import ); |
|
| 99 | + |
|
| 100 | + Queue::assertPushedOn('importing', FakeJob::class); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @test |
|
| 105 | + */ |
|
| 106 | + public function check_import_progress() |
|
| 107 | + { |
|
| 108 | + $response = $this->json( 'GET', '/import/1/progress' ); |
|
| 109 | + |
|
| 110 | + $response->assertStatus(200); |
|
| 111 | + |
|
| 112 | + $response->assertJsonFragment( ['status' => 200] ); |
|
| 113 | + |
|
| 114 | + $response->assertJsonFragment( ['progress'] ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @test |
|
| 119 | + */ |
|
| 120 | + public function remove_import() |
|
| 121 | + { |
|
| 122 | + $this->assertTrue(Import::removeImport($this->import->id)); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -24,24 +24,24 @@ discard block |
||
| 24 | 24 | return ['Ladybirdweb\ImportExport\ImportExportServiceProvider']; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - protected function setUp () |
|
| 27 | + protected function setUp() |
|
| 28 | 28 | { |
| 29 | 29 | parent::setUp(); |
| 30 | 30 | |
| 31 | - $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
|
| 31 | + $this->loadMigrationsFrom(__DIR__.'/database/migrations'); |
|
| 32 | 32 | |
| 33 | 33 | Route::middleware('web')->group(function() { |
| 34 | 34 | |
| 35 | - Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); |
|
| 35 | + Route::get('/import/{id}/progress', ['as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']); |
|
| 36 | 36 | |
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | - Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv'); |
|
| 39 | + Storage::putFileAs('imports', new File(storage_path('test/test.csv')), 'test.csv'); |
|
| 40 | 40 | |
| 41 | 41 | $this->import = ModelImport::create([ |
| 42 | 42 | 'file' => 'imports/test.csv', |
| 43 | 43 | 'file_rows' => 104, |
| 44 | - 'db_cols' => [ 'name', 'email', 'password'], |
|
| 44 | + 'db_cols' => ['name', 'email', 'password'], |
|
| 45 | 45 | 'model_map' => ['email', 'name', 'password'] |
| 46 | 46 | ]); |
| 47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function create_new_import_success() |
| 53 | 53 | { |
| 54 | - $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']); |
|
| 54 | + $import = Import::createImport('imports/test.csv', ['name', 'email', 'password']); |
|
| 55 | 55 | |
| 56 | 56 | $this->assertInstanceOf(ModelImport::class, $import); |
| 57 | 57 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $csv_data = Import::getImportFileData($this->import->id); |
| 75 | 75 | |
| 76 | - $this->assertInternalType( 'array', $csv_data ); |
|
| 76 | + $this->assertInternalType('array', $csv_data); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | Queue::fake(); |
| 97 | 97 | |
| 98 | - Import::dispatchImportJob( FakeJob::class, $import ); |
|
| 98 | + Import::dispatchImportJob(FakeJob::class, $import); |
|
| 99 | 99 | |
| 100 | 100 | Queue::assertPushedOn('importing', FakeJob::class); |
| 101 | 101 | } |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function check_import_progress() |
| 107 | 107 | { |
| 108 | - $response = $this->json( 'GET', '/import/1/progress' ); |
|
| 108 | + $response = $this->json('GET', '/import/1/progress'); |
|
| 109 | 109 | |
| 110 | 110 | $response->assertStatus(200); |
| 111 | 111 | |
| 112 | - $response->assertJsonFragment( ['status' => 200] ); |
|
| 112 | + $response->assertJsonFragment(['status' => 200]); |
|
| 113 | 113 | |
| 114 | - $response->assertJsonFragment( ['progress'] ); |
|
| 114 | + $response->assertJsonFragment(['progress']); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |