firefly-iii/tests/Feature/Controllers/Import/IndexControllerTest.php
2018-03-24 06:08:50 +01:00

119 lines
3.9 KiB
PHP

<?php
/**
* IndexControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Import\Routine\FileRoutine;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Log;
use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
/**
*
*/
public function setUp()
{
parent::setUp();
Log::debug(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::create
*/
public function testCreate()
{
$job = $this->user()->importJobs()->where('key', 'new')->first();
$repository = $this->mock(ImportJobRepositoryInterface::class);
$repository->shouldReceive('create')->withArgs(['file'])->andReturn($job);
$this->be($this->user());
$response = $this->get(route('import.create-job', ['file']));
$response->assertStatus(302);
$response->assertRedirect(route('import.configure', ['new']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::download
*/
public function testDownload()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
//$job = $this->user()->importJobs()->where('key', 'testImport')->first();
$this->be($this->user());
$response = $this->get(route('import.download', ['testImport']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::__construct
* @covers \FireflyIII\Http\Controllers\Import\IndexController::index
*/
public function testIndex()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->be($this->user());
$response = $this->get(route('import.index'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::start
*/
public function testStart()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FileRoutine::class);
$routine->shouldReceive('setJob')->once();
$routine->shouldReceive('run')->once()->andReturn(true);
$this->be($this->user());
$response = $this->post(route('import.start', ['configured']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::start
* @expectedExceptionMessage Job did not complete successfully.
*/
public function testStartFailed()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FileRoutine::class);
$routine->shouldReceive('setJob')->once();
$routine->shouldReceive('run')->once()->andReturn(false);
$this->be($this->user());
$response = $this->post(route('import.start', ['configured']));
$response->assertStatus(500);
}
}