mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-10 11:48:10 +00:00
First set of new tests.
This commit is contained in:
@@ -11,9 +11,158 @@ declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use FireflyIII\Import\ImportProcedureInterface;
|
||||
use FireflyIII\Import\Setup\CsvSetup;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class ImportControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::complete
|
||||
*/
|
||||
public function testComplete()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.complete', ['complete']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::configure
|
||||
*/
|
||||
public function testConfigure()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.configure', ['configure']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::download
|
||||
*/
|
||||
public function testDownload()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.download', ['configure']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('[]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::finished
|
||||
*/
|
||||
public function testFinished()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.finished', ['finished']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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::postConfigure
|
||||
*/
|
||||
public function testPostConfigure()
|
||||
{
|
||||
$importer = $this->mock(CsvSetup::class);
|
||||
$importer->shouldReceive('setJob')->once();
|
||||
$importer->shouldReceive('saveImportConfiguration')->once();
|
||||
|
||||
$data = [];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.process-configuration', ['p-configure']), $data);
|
||||
$response->assertStatus(302);
|
||||
$this->assertRedirectedToRoute('import.settings', ['p-configure']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::postSettings
|
||||
*/
|
||||
public function testPostSettings()
|
||||
{
|
||||
$importer = $this->mock(CsvSetup::class);
|
||||
$importer->shouldReceive('setJob')->once();
|
||||
$importer->shouldReceive('storeSettings')->once();
|
||||
$data = [];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.post-settings', ['p-settings']), $data);
|
||||
$response->assertStatus(302);
|
||||
$this->assertRedirectedToRoute('import.settings', ['p-settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::settings
|
||||
*/
|
||||
public function testSettings()
|
||||
{
|
||||
$importer = $this->mock(CsvSetup::class);
|
||||
$importer->shouldReceive('setJob')->once();
|
||||
$importer->shouldReceive('requireUserSettings')->once()->andReturn(false);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.settings', ['settings']));
|
||||
$response->assertStatus(302);
|
||||
$this->assertRedirectedToRoute('import.complete', ['settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::start
|
||||
*/
|
||||
public function testStart()
|
||||
{
|
||||
/** @var ImportProcedureInterface $procedure */
|
||||
$procedure = $this->mock(ImportProcedureInterface::class);
|
||||
|
||||
$procedure->shouldReceive('runImport');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.start', ['complete']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::status
|
||||
* Implement testStatus().
|
||||
*/
|
||||
public function testStatus()
|
||||
{
|
||||
// complete
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.status', ['complete']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\ImportController::upload
|
||||
*/
|
||||
public function testUpload()
|
||||
{
|
||||
$path = resource_path('stubs/csv.csv');
|
||||
$file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);
|
||||
$response = $this->post(route('import.upload'), [], [], ['import_file' => $file], ['Accept' => 'application/json']);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user