Files
firefly-iii/tests/Feature/Controllers/Import/IndexControllerTest.php

136 lines
4.6 KiB
PHP
Raw Normal View History

2017-12-23 17:42:07 +01:00
<?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\Prerequisites\BunqPrerequisites;
use FireflyIII\Import\Prerequisites\FakePrerequisites;
use FireflyIII\Import\Prerequisites\FilePrerequisites;
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
use FireflyIII\Models\ImportJob;
2017-12-23 17:42:07 +01:00
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
2018-03-24 06:08:50 +01:00
use Log;
use Mockery;
2017-12-23 17:42:07 +01:00
use Tests\TestCase;
/**
* Class IndexControllerTest
2017-12-23 17:42:07 +01:00
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
public function setUp()
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-12-23 17:42:07 +01:00
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
2017-12-23 17:42:07 +01:00
*/
public function testCreateFake()
2017-12-23 17:42:07 +01:00
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'fake';
$importJob->key = 'fake_job_1';
// mock call:
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(false);
$fakePrerequisites->shouldReceive('setUser')->once();
2017-12-23 17:42:07 +01:00
$this->be($this->user());
$response = $this->get(route('import.create', ['fake']));
2017-12-23 17:42:07 +01:00
$response->assertStatus(302);
// expect a redirect to prerequisites
$response->assertRedirect(route('import.prerequisites.index', ['fake', 'fake_job_1']));
2017-12-23 17:42:07 +01:00
}
2017-12-23 17:42:07 +01:00
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
2017-12-23 17:42:07 +01:00
*/
public function testCreateFakeNoPrereq()
2017-12-23 17:42:07 +01:00
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'fake';
$importJob->key = 'fake_job_2';
// mock call:
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$fakePrerequisites->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
2017-12-23 17:42:07 +01:00
$this->be($this->user());
$response = $this->get(route('import.create', ['fake']));
$response->assertStatus(302);
// expect a redirect to prerequisites
$response->assertRedirect(route('import.job.configuration.index', ['fake_job_2']));
2017-12-23 17:42:07 +01:00
}
public function testIndex()
{
$this->be($this->user());
// fake prerequisites providers:
$fake = $this->mock(FakePrerequisites::class);
$file = $this->mock(FilePrerequisites::class);
$bunq = $this->mock(BunqPrerequisites::class);
$spectre = $this->mock(SpectrePrerequisites::class);
2017-12-23 17:42:07 +01:00
// call methods:
$fake->shouldReceive('setUser')->once();
$file->shouldReceive('setUser')->once();
$bunq->shouldReceive('setUser')->once();
$spectre->shouldReceive('setUser')->once();
2017-12-23 17:42:07 +01:00
$fake->shouldReceive('isComplete')->once()->andReturn(true);
$file->shouldReceive('isComplete')->once()->andReturn(true);
$bunq->shouldReceive('isComplete')->once()->andReturn(true);
$spectre->shouldReceive('isComplete')->once()->andReturn(true);
2017-12-23 17:42:07 +01:00
$response = $this->get(route('import.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
2017-12-23 17:42:07 +01:00
}
}