Expand test coverage.

This commit is contained in:
James Cole
2017-12-23 17:42:07 +01:00
parent 8bd76d1ff0
commit 08b743ddcb
82 changed files with 1413 additions and 142 deletions

View File

@@ -0,0 +1,119 @@
<?php
/**
* ConfigurationControllerTest.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\Configuration\FileConfigurator;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ConfigurationControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::__construct
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::index
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::makeConfigurator
*/
public function testIndex()
{
/** @var ImportJob $job */
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
$configurator = $this->mock(FileConfigurator::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
$configurator->shouldReceive('getNextView')->once()->andReturn('error'); // does not matter which view is returned.
$configurator->shouldReceive('getNextData')->once()->andReturn([]);
$repository->shouldReceive('updateStatus')->once();
$this->be($this->user());
$response = $this->get(route('import.configure', [$job->key]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::__construct
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::index
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::makeConfigurator
*/
public function testIndexConfigured()
{
/** @var ImportJob $job */
$job = $this->user()->importJobs()->where('key', 'configured')->first();
$configurator = $this->mock(FileConfigurator::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
$repository->shouldReceive('updateStatus')->once();
$this->be($this->user());
$response = $this->get(route('import.configure', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.status', [$job->key]));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::post
*/
public function testPost()
{
/** @var ImportJob $job */
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
$data = ['some' => 'config'];
$configurator = $this->mock(FileConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
$configurator->shouldReceive('configureJob')->once()->withArgs([$data]);
$configurator->shouldReceive('getWarningMessage')->once()->andReturn('Some warning');
$this->be($this->user());
$response = $this->post(route('import.configure.post', [$job->key]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('import.configure', [$job->key]));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::post
*/
public function testPostConfigured()
{
/** @var ImportJob $job */
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
$data = ['some' => 'config'];
$configurator = $this->mock(FileConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
$this->be($this->user());
$response = $this->post(route('import.configure.post', [$job->key]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('import.status', [$job->key]));
}
}

View File

@@ -0,0 +1,105 @@
<?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 Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
/**
* @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()
{
//$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()
{
$this->be($this->user());
$response = $this->get(route('import.index'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController::start
*/
public function testStart()
{
$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()
{
$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);
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* PrerequisitesControllerTest.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\Prerequisites\FilePrerequisites;
use Illuminate\Support\MessageBag;
use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PrerequisitesControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::__construct
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::index
*/
public function testIndex()
{
$object = $this->mock(FilePrerequisites::class);
$object->shouldReceive('setUser');
$object->shouldReceive('hasPrerequisites')->andReturn(true);
$object->shouldReceive('getView')->andReturn('error'); // does not matter which view is returned
$object->shouldReceive('getViewParameters')->andReturn([]);
$this->be($this->user());
$response = $this->get(route('import.prerequisites', ['file']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::index
*/
public function testIndexRedirect()
{
$object = $this->mock(FilePrerequisites::class);
$object->shouldReceive('setUser');
$object->shouldReceive('hasPrerequisites')->andReturn(false);
$this->be($this->user());
$response = $this->get(route('import.prerequisites', ['file']));
$response->assertStatus(302);
$response->assertRedirect(route('import.create-job', ['file']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::post
*/
public function testPost()
{
$messageBag = new MessageBag;
$messageBag->add('nomessage', 'nothing');
$object = $this->mock(FilePrerequisites::class);
$object->shouldReceive('setUser');
$object->shouldReceive('hasPrerequisites')->andReturn(true);
$object->shouldReceive('storePrerequisites')->andReturn($messageBag);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['file']), []);
$response->assertStatus(302);
$response->assertSessionHas('error');
$response->assertRedirect(route('import.prerequisites', ['file']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::post
*/
public function testPostDone()
{
$messageBag = new MessageBag;
$messageBag->add('nomessage', 'nothing');
$object = $this->mock(FilePrerequisites::class);
$object->shouldReceive('setUser');
$object->shouldReceive('hasPrerequisites')->andReturn(false);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['file']), []);
$response->assertStatus(302);
$response->assertRedirect(route('import.create-job', ['file']));
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* StatusControllerTest.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\Repositories\Tag\TagRepositoryInterface;
use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class StatusControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
* @covers \FireflyIII\Http\Controllers\Import\StatusController::index
*/
public function testIndex()
{
$this->be($this->user());
$response = $this->get(route('import.status', ['configured']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
* @covers \FireflyIII\Http\Controllers\Import\StatusController::index
*/
public function testIndexRedirect()
{
$this->be($this->user());
$response = $this->get(route('import.status', ['new']));
$response->assertStatus(302);
$response->assertRedirect(route('import.configure', ['new']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
* @covers \FireflyIII\Http\Controllers\Import\StatusController::json
*/
public function testStatusFinished()
{
$tag = $this->user()->tags()->first();
$repository = $this->mock(TagRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn($tag);
$this->be($this->user());
$response = $this->get(route('import.status.json', ['finished']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
* @covers \FireflyIII\Http\Controllers\Import\StatusController::json
*/
public function testStatusRunning()
{
$this->be($this->user());
$response = $this->get(route('import.status.json', ['running']));
$response->assertStatus(200);
}
}