Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix import tests.
James Cole1bca1b921b13
diff --git a/tests/Feature/Controllers/Import/FileControllerTest.php b/tests/Feature/Controllers/Import/FileControllerTest.phpnew file mode 100644index 0000000000..0c8ad37202--- /dev/null+++ b/tests/Feature/Controllers/Import/FileControllerTest.php@@ -0,0 +1,215 @@+<?php+/**+ * FileControllerTest.php+ * Copyright (c) 2017 [email protected]+ * This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.+ *+ * See the LICENSE file for details.+ */++declare(strict_types=1);++namespace Tests\Feature\Controllers\Import;++use FireflyIII\Import\Configurator\CsvConfigurator;+use FireflyIII\Import\Routine\ImportRoutine;+use FireflyIII\Models\ImportJob;+use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;+use Illuminate\Http\UploadedFile;+use Tests\TestCase;+++class FileControllerTest extends TestCase+{+ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::__construct+ * @covers \FireflyIII\Http\Controllers\Import\FileController::configure+ * @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator+ */+ public function testConfigure()+ {+ // mock stuff.+ $configurator = $this->mock(CsvConfigurator::class);+ $configurator->shouldReceive('setJob')->once();+ $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);+ $configurator->shouldReceive('getNextView')->once()->andReturn('import.csv.initial');+ $configurator->shouldReceive('getNextData')->andReturn(['specifics' => [], 'delimiters' => [], 'accounts' => []])->once();+++ $this->be($this->user());+ $response = $this->get(route('import.file.configure', ['configure']));+ $response->assertStatus(200);+ $response->assertSee('<ol class="breadcrumb">');+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::__construct+ * @covers \FireflyIII\Http\Controllers\Import\FileController::configure+ * @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator+ */+ public function testConfigured()+ {+ // mock stuff.+ $configurator = $this->mock(CsvConfigurator::class);+ $configurator->shouldReceive('setJob')->once();+ $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);++ $this->be($this->user());+ $response = $this->get(route('import.file.configure', ['configure']));+ $response->assertStatus(302);+ $response->assertRedirect(route('import.file.status', ['configure']));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::download+ */+ public function testDownload()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.download', ['configure']));+ $response->assertStatus(200);+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::initialize+ */+ public function testInitialize()+ {+ $repository = $this->mock(ImportJobRepositoryInterface::class);+ $path = resource_path('stubs/csv.csv');+ $file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);+ $configPath = resource_path('stubs/demo-configuration.json');+ $configFile = new UploadedFile($path, 'configuration.json', filesize($configPath), 'application/json', null, true);+ $job = new ImportJob;+ $job->key = 'hello';++ $repository->shouldReceive('create')->once()->andReturn($job);+ $repository->shouldReceive('processFile')->once();+ $repository->shouldReceive('processConfiguration')->once();+ $repository->shouldReceive('updateStatus')->once();++ $this->be($this->user());+ $response = $this->post(route('import.file.initialize'), ['import_file_type' => 'csv', 'import_file' => $file, 'configuration_file' => $configFile]);++ $response->assertStatus(302);+ $response->assertRedirect(route('import.file.configure', ['hello']));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::json+ */+ public function testJson()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.json', ['configure']));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::json+ */+ public function testJsonFinished()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.json', ['finished']));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::json+ */+ public function testJsonRunning()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.json', ['running']));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure+ */+ public function testPostConfigure()+ {+ $configurator = $this->mock(CsvConfigurator::class);+ $configurator->shouldReceive('setJob')->once();+ $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);+ $configurator->shouldReceive('configureJob')->once()->andReturn(false);+ $configurator->shouldReceive('getWarningMessage')->once()->andReturn('');+++ $this->be($this->user());+ $response = $this->post(route('import.file.process-configuration', ['running']));+ $response->assertStatus(302);+ $response->assertRedirect(route('import.file.configure', ['running']));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure+ */+ public function testPostConfigured()+ {+ $configurator = $this->mock(CsvConfigurator::class);+ $configurator->shouldReceive('setJob')->once();+ $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);+++ $this->be($this->user());+ $response = $this->post(route('import.file.process-configuration', ['running']));+ $response->assertStatus(302);+ $response->assertRedirect(route('import.file.status', ['running']));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::start+ */+ public function testStart()+ {+ $importer = $this->mock(ImportRoutine::class);+ $importer->shouldReceive('setJob')->once();+ $importer->shouldReceive('run')->once()->andReturn(true);+++ $this->be($this->user());+ $response = $this->post(route('import.file.start', ['running']));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::start+ * @expectedExceptionMessage Job did not complete succesfully.+ */+ public function testStartFailed()+ {+ $importer = $this->mock(ImportRoutine::class);+ $importer->shouldReceive('setJob')->once();+ $importer->shouldReceive('run')->once()->andReturn(false);+++ $this->be($this->user());+ $response = $this->post(route('import.file.start', ['running']));+ $response->assertStatus(500);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::status+ */+ public function testStatus()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.status', ['running']));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Import\FileController::status+ */+ public function testStatusNew()+ {+ $this->be($this->user());+ $response = $this->get(route('import.file.status', ['new']));+ $response->assertStatus(302);+ $response->assertRedirect(route('import.file.configure', ['new']));+ }++}\ No newline at end of filediff --git a/tests/Feature/Controllers/ImportControllerTest.php b/tests/Feature/Controllers/ImportControllerTest.phpindex 23f1d47788..16bf5c4657 100644--- a/tests/Feature/Controllers/ImportControllerTest.php+++ b/tests/Feature/Controllers/ImportControllerTest.php@@ -11,11 +11,6 @@ declare(strict_types=1);namespace Tests\Feature\Controllers;-use FireflyIII\Import\Configurator\CsvConfigurator;-use FireflyIII\Import\Routine\ImportRoutine;-use FireflyIII\Models\ImportJob;-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;-use Illuminate\Http\UploadedFile;use Tests\TestCase;/**@@ -26,55 +21,6 @@ use Tests\TestCase;class ImportControllerTest extends TestCase{- /**- * @covers \FireflyIII\Http\Controllers\ImportController::__construct- * @covers \FireflyIII\Http\Controllers\ImportController::configure- * @covers \FireflyIII\Http\Controllers\ImportController::makeConfigurator- */- public function testConfigure()- {- // mock stuff.- $configurator = $this->mock(CsvConfigurator::class);- $configurator->shouldReceive('setJob')->once();- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);- $configurator->shouldReceive('getNextView')->once()->andReturn('import.csv.initial');- $configurator->shouldReceive('getNextData')->andReturn(['specifics' => [], 'delimiters' => [], 'accounts' => []])->once();--- $this->be($this->user());- $response = $this->get(route('import.configure', ['configure']));- $response->assertStatus(200);- $response->assertSee('<ol class="breadcrumb">');- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::__construct- * @covers \FireflyIII\Http\Controllers\ImportController::configure- * @covers \FireflyIII\Http\Controllers\ImportController::makeConfigurator- */- public function testConfigured()- {- // mock stuff.- $configurator = $this->mock(CsvConfigurator::class);- $configurator->shouldReceive('setJob')->once();- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);-- $this->be($this->user());- $response = $this->get(route('import.configure', ['configure']));- $response->assertStatus(302);- $response->assertRedirect(route('import.status', ['configure']));- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::download- */- public function testDownload()- {- $this->be($this->user());- $response = $this->get(route('import.download', ['configure']));- $response->assertStatus(200);- }-/*** @covers \FireflyIII\Http\Controllers\ImportController::index*/@@ -86,146 +32,5 @@ class ImportControllerTest extends TestCase$response->assertSee('<ol class="breadcrumb">');}- /**- * @covers \FireflyIII\Http\Controllers\ImportController::initialize- */- public function testInitialize()- {- $repository = $this->mock(ImportJobRepositoryInterface::class);- $path = resource_path('stubs/csv.csv');- $file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);- $configPath = resource_path('stubs/demo-configuration.json');- $configFile = new UploadedFile($path, 'configuration.json', filesize($configPath), 'application/json', null, true);- $job = new ImportJob;- $job->key = 'hello';-- $repository->shouldReceive('create')->once()->andReturn($job);- $repository->shouldReceive('processFile')->once();- $repository->shouldReceive('processConfiguration')->once();- $repository->shouldReceive('updateStatus')->once();-- $this->be($this->user());- $response = $this->post(route('import.initialize'), ['import_file_type' => 'csv', 'import_file' => $file, 'configuration_file' => $configFile]);-- $response->assertStatus(302);- $response->assertRedirect(route('import.configure', ['hello']));- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::json- */- public function testJson()- {- $this->be($this->user());- $response = $this->get(route('import.json', ['configure']));- $response->assertStatus(200);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::json- */- public function testJsonFinished()- {- $this->be($this->user());- $response = $this->get(route('import.json', ['finished']));- $response->assertStatus(200);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::json- */- public function testJsonRunning()- {- $this->be($this->user());- $response = $this->get(route('import.json', ['running']));- $response->assertStatus(200);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::postConfigure- */- public function testPostConfigure()- {- $configurator = $this->mock(CsvConfigurator::class);- $configurator->shouldReceive('setJob')->once();- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);- $configurator->shouldReceive('configureJob')->once()->andReturn(false);- $configurator->shouldReceive('getWarningMessage')->once()->andReturn('');--- $this->be($this->user());- $response = $this->post(route('import.process-configuration', ['running']));- $response->assertStatus(302);- $response->assertRedirect(route('import.configure', ['running']));- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::postConfigure- */- public function testPostConfigured()- {- $configurator = $this->mock(CsvConfigurator::class);- $configurator->shouldReceive('setJob')->once();- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);--- $this->be($this->user());- $response = $this->post(route('import.process-configuration', ['running']));- $response->assertStatus(302);- $response->assertRedirect(route('import.status', ['running']));- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::start- */- public function testStart()- {- $importer = $this->mock(ImportRoutine::class);- $importer->shouldReceive('setJob')->once();- $importer->shouldReceive('run')->once()->andReturn(true);--- $this->be($this->user());- $response = $this->post(route('import.start', ['running']));- $response->assertStatus(200);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::start- * @expectedExceptionMessage Job did not complete succesfully.- */- public function testStartFailed()- {- $importer = $this->mock(ImportRoutine::class);- $importer->shouldReceive('setJob')->once();- $importer->shouldReceive('run')->once()->andReturn(false);--- $this->be($this->user());- $response = $this->post(route('import.start', ['running']));- $response->assertStatus(500);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::status- */- public function testStatus()- {- $this->be($this->user());- $response = $this->get(route('import.status', ['running']));- $response->assertStatus(200);- }-- /**- * @covers \FireflyIII\Http\Controllers\ImportController::status- */- public function testStatusNew()- {- $this->be($this->user());- $response = $this->get(route('import.status', ['new']));- $response->assertStatus(302);- $response->assertRedirect(route('import.configure', ['new']));- }-}