mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Improve test coverage and remove deprecated code.
This commit is contained in:
@@ -1,688 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FileConfiguratorTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Configuration;
|
||||
|
||||
use FireflyIII\Import\Configuration\FileConfigurator;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\Initial;
|
||||
use FireflyIII\Support\Import\Configuration\File\Map;
|
||||
use FireflyIII\Support\Import\Configuration\File\Roles;
|
||||
use FireflyIII\Support\Import\Configuration\File\UploadConfig;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FileConfiguratorTest
|
||||
*/
|
||||
class FileConfiguratorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::setJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfig
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
|
||||
*/
|
||||
public function testConfigureJobInitial()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'initial'];
|
||||
$data = ['some' => 'array'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
|
||||
// assert that new initial is created:
|
||||
$processor = $this->mock(Initial::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
|
||||
$processor->shouldReceive('getWarningMessage')->andReturn('')->once();
|
||||
|
||||
// config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
|
||||
*/
|
||||
public function testConfigureJobMap()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'map'];
|
||||
$data = ['some' => 'array'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Roles is created:
|
||||
$processor = $this->mock(Map::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
|
||||
$processor->shouldReceive('getWarningMessage')->andReturn('')->once();
|
||||
|
||||
// config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should throw a FireflyException when $job is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::__construct
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function testConfigureJobNoJob()
|
||||
{
|
||||
// config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->configureJob([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage Cannot handle job stage "ready" in getConfigurationClass().
|
||||
*/
|
||||
public function testConfigureJobReady()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'ready'];
|
||||
$data = ['some' => 'array'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
|
||||
*/
|
||||
public function testConfigureJobRoles()
|
||||
{
|
||||
$config = ['stage' => 'roles'];
|
||||
$data = ['some' => 'array'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Roles is created:
|
||||
$processor = $this->mock(Roles::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
|
||||
$processor->shouldReceive('getWarningMessage')->andReturn('')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
|
||||
*/
|
||||
public function testConfigureJobUploadConfig()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'upload-config'];
|
||||
$data = ['some' => 'array'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new UploadConfig is created:
|
||||
$processor = $this->mock(UploadConfig::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
|
||||
$processor->shouldReceive('getWarningMessage')->andReturn('')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
*/
|
||||
public function testGetNextDataInitial()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'initial'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Initial is created:
|
||||
$processor = $this->mock(Initial::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('getData')->once();
|
||||
|
||||
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Should throw a FireflyException when $job is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function testGetNextDataNoJob()
|
||||
{
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
*/
|
||||
public function testGetNextDataUploadConfig()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'upload-config'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Initial is created:
|
||||
$processor = $this->mock(UploadConfig::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('getData')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage Cannot handle job stage "ksksjje" in getConfigurationClass().
|
||||
*/
|
||||
public function testGetNextDataUploadInvalid()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'ksksjje'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// should throw error
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
*/
|
||||
public function testGetNextDataUploadMap()
|
||||
{
|
||||
// data:
|
||||
$config = ['stage' => 'map'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Initial is created:
|
||||
$processor = $this->mock(Map::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('getData')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage Cannot handle job stage "ready" in getConfigurationClass().
|
||||
*/
|
||||
public function testGetNextDataUploadReady()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'ready'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
|
||||
*/
|
||||
public function testGetNextDataUploadRoles()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'roles'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// assert that new Initial is created:
|
||||
$processor = $this->mock(Roles::class);
|
||||
$processor->shouldReceive('setJob')->withArgs([$job])->once();
|
||||
$processor->shouldReceive('getData')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
*/
|
||||
public function testGetNextViewInitial()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'initial'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
|
||||
// test
|
||||
$this->assertEquals('import.file.initial', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage No view for stage "slkds903ms90k"
|
||||
*/
|
||||
public function testGetNextViewInvalid()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'slkds903ms90k'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
*/
|
||||
public function testGetNextViewMap()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'map'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
|
||||
// test
|
||||
$this->assertEquals('import.file.map', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should throw a FireflyException when $job is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function testGetNextViewNoJob()
|
||||
{
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage No view for stage "ready"
|
||||
*/
|
||||
public function testGetNextViewReady()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'ready'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run configx§
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$configurator->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
*/
|
||||
public function testGetNextViewRoles()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'roles'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
|
||||
// test
|
||||
$this->assertEquals('import.file.roles', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
|
||||
*/
|
||||
public function testGetNextViewUploadConfig()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'upload-config'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
|
||||
// test
|
||||
$this->assertEquals('import.file.upload-config', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getWarningMessage
|
||||
*/
|
||||
public function testGetWarningMessage()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'upload-config'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->once();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$warning = $configurator->getWarningMessage();
|
||||
|
||||
// test
|
||||
$this->assertEquals('', $warning);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Should throw a FireflyException when $job is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::getWarningMessage
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function testGetWarningMessageNoJob()
|
||||
{
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->getWarningMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
|
||||
*/
|
||||
public function testIsJobConfiguredFalse()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'upload-config'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$result = $configurator->isJobConfigured();
|
||||
|
||||
// test
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should throw a FireflyException when $job is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function testIsJobConfiguredNoJob()
|
||||
{
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->isJobConfigured();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
|
||||
*/
|
||||
public function testIsJobConfiguredTrue()
|
||||
{
|
||||
// data
|
||||
$config = ['stage' => 'ready'];
|
||||
$extended = ['steps' => 0, 'done' => 0];
|
||||
$job = $this->getJob($config);
|
||||
|
||||
// mock repos
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
|
||||
$repository->shouldReceive('setConfiguration')->once();
|
||||
$repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
|
||||
$repository->shouldReceive('setExtendedStatus')->once();
|
||||
|
||||
// run config
|
||||
$configurator = new FileConfigurator();
|
||||
$configurator->setJob($job);
|
||||
$result = $configurator->isJobConfigured();
|
||||
|
||||
// test
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
protected function getJob(array $config): ImportJob
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->file_type = 'file';
|
||||
$job->status = 'new';
|
||||
$job->key = 'x' . random_int(1, 100000);
|
||||
$job->user()->associate($this->user());
|
||||
$job->configuration = $config;
|
||||
|
||||
return $job;
|
||||
}
|
||||
}
|
593
tests/Unit/Import/JobConfiguration/FakeJobConfigurationTest.php
Normal file
593
tests/Unit/Import/JobConfiguration/FakeJobConfigurationTest.php
Normal file
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
/**
|
||||
* FakeJobConfigurationTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FakeJobConfigurationTest
|
||||
*/
|
||||
class FakeJobConfigurationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* No config, job is new.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCC(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'A_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertFalse($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* No config, job is not new.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCAlbumFalse(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'B_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'needs_config';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertFalse($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Job only says to apply rules.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCApplyRules(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'C_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'apply-rules' => true,
|
||||
];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertFalse($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Job has album but wrong one.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCBadAlbum(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'D_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'config';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'song' => 'golden years',
|
||||
'artist' => 'david bowie',
|
||||
'album' => 'some album',
|
||||
'apply-rules' => true,
|
||||
];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertFalse($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Job has album + song, but bad content.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCBadInfo(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'E_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'song' => 'some song',
|
||||
'artist' => 'david bowie',
|
||||
'apply-rules' => true,
|
||||
];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertFalse($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Job has correct album
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCGoodAlbum(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'f_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'config';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'song' => 'golden years',
|
||||
'artist' => 'david bowie',
|
||||
'album' => 'station to station',
|
||||
'apply-rules' => true,
|
||||
];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertTrue($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Job has correct content for "new"!
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testCCGoodNewInfo(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'g_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'song' => 'golden years',
|
||||
'artist' => 'david bowie',
|
||||
'apply-rules' => true,
|
||||
];
|
||||
$job->save();
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$this->assertTrue($configurator->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply rules with submitted "false"
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobARFalse(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'h_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['apply_rules' => 0];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), ['apply-rules' => false]])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply rules with submitted "false"
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobARTrue(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'i_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['apply_rules' => 1];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), ['apply-rules' => true]])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with bad song.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobBadAlbum(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'j_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['album' => 'Station to Bowie'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), []])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with bad artist.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobBadArtist(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'k_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['artist' => 'DaViD BoWXXXXXiE'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), []])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with bad song.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobBadSong(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'l_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['song' => 'Golden Bowie'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), []])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with good album.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobGoodAlbum(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'm_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['album' => 'Station to Station'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), ['album' => 'station to station']])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with good artist.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobGoodArtist(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'n_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['artist' => 'DaViD BoWiE'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), ['artist' => 'david bowie']])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit job with good song.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testConfigureJobGoodSong(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'o_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// data to submit:
|
||||
$data = ['song' => 'Golden Years'];
|
||||
|
||||
// expect the config to update:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setConfiguration')
|
||||
->withArgs([Mockery::any(), ['song' => 'golden years']])->once();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$messages = $configurator->configureJob($data);
|
||||
$this->assertTrue($messages->has('some_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Have rules, have artist, have song, must ask album
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testGetNextViewAlbum(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'not_new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = ['apply-rules' => false, 'artist' => 'david bowie', 'song' => 'golden years'];
|
||||
$job->save();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
$this->assertEquals('import.fake.enter-album', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Have rules, must ask artist
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testGetNextViewArtist(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = ['apply-rules' => false];
|
||||
$job->save();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
$this->assertEquals('import.fake.enter-artist', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* With empty config, should return view for rules.
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testGetNextViewRules(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
$this->assertEquals('import.fake.apply-rules', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Have rules, have artist, must ask song
|
||||
*
|
||||
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
|
||||
*/
|
||||
public function testGetNextViewSong(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = ['apply-rules' => false, 'artist' => 'david bowie'];
|
||||
$job->save();
|
||||
|
||||
// call configuration
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setJob($job);
|
||||
$view = $configurator->getNextView();
|
||||
$this->assertEquals('import.fake.enter-song', $view);
|
||||
}
|
||||
}
|
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportAccountTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Object;
|
||||
|
||||
use FireflyIII\Import\Object\ImportAccount;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ImportAccountTest
|
||||
*/
|
||||
class ImportAccountTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Should error because it requires a default asset account.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Object\ImportAccount
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountType = AccountType::where('type', AccountType::ASSET)->first();
|
||||
$account = Account::find(1);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
|
||||
$repository->shouldReceive('getAccountType')->twice()->withArgs([AccountType::ASSET])->andReturn($accountType);
|
||||
//$repository->shouldReceive('getAccountsByType')->twice()->withArgs([[AccountType::ASSET]])->andReturn(new Collection());
|
||||
$repository->shouldReceive('findNull')->once()->withArgs([1])->andReturn($account);
|
||||
|
||||
// create import account.
|
||||
$importAccount = new ImportAccount;
|
||||
$importAccount->setUser($this->user());
|
||||
$importAccount->setDefaultAccountId(1);
|
||||
$found = $importAccount->getAccount();
|
||||
$this->assertEquals(1, $found->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Should error because it requires a default asset account.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Object\ImportAccount
|
||||
*/
|
||||
public function testEmptyMappingAccountId()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountType = AccountType::where('type', AccountType::ASSET)->first();
|
||||
$account = Account::find(1);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
|
||||
$repository->shouldReceive('getAccountType')->once()->withArgs([AccountType::ASSET])->andReturn($accountType);
|
||||
|
||||
// create import account.
|
||||
$importAccount = new ImportAccount;
|
||||
$importAccount->setUser($this->user());
|
||||
$importAccount->setDefaultAccountId(1);
|
||||
|
||||
// add an account id:
|
||||
$accountId = [
|
||||
'role' => 'account-id',
|
||||
'mapped' => null,
|
||||
'value' => 2,
|
||||
];
|
||||
$importAccount->setAccountId($accountId);
|
||||
|
||||
|
||||
$found = $importAccount->getAccount();
|
||||
$this->assertEquals(2, $found->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Object\ImportAccount
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage ImportAccount cannot continue without a default account to fall back on.
|
||||
*/
|
||||
public function testNoAccount()
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
|
||||
$importAccount = new ImportAccount;
|
||||
$importAccount->setUser($this->user());
|
||||
$importAccount->getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Object\ImportAccount
|
||||
* @expectedException \FireflyIII\Exceptions\FireflyException
|
||||
* @expectedExceptionMessage ImportAccount cannot continue without user.
|
||||
*/
|
||||
public function testNoUser()
|
||||
{
|
||||
$this->mock(AccountRepositoryInterface::class);
|
||||
$importAccount = new ImportAccount;
|
||||
$importAccount->getAccount();
|
||||
}
|
||||
}
|
174
tests/Unit/Import/Prerequisites/FakePrerequisitesTest.php
Normal file
174
tests/Unit/Import/Prerequisites/FakePrerequisitesTest.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* FakePrerequisitesTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Prerequisites;
|
||||
|
||||
|
||||
use FireflyIII\Import\Prerequisites\FakePrerequisites;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FakePrerequisitesTest
|
||||
*/
|
||||
class FakePrerequisitesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Bad API key length in preferences
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testGetViewParametersBadLength(): void
|
||||
{
|
||||
// API key should be empty:
|
||||
$apiPref = new Preference;
|
||||
$apiPref->data = 'abc';
|
||||
|
||||
Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'fake_api_key', false])->once()
|
||||
->andReturn($apiPref);
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$result = $object->getViewParameters();
|
||||
$this->assertEquals(['api_key' => ''], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* No API key in preference.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testGetViewParametersDataNull(): void
|
||||
{
|
||||
// API key should be empty:
|
||||
$apiPref = new Preference;
|
||||
$apiPref->data = null;
|
||||
|
||||
Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'fake_api_key', false])->once()
|
||||
->andReturn($apiPref);
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$result = $object->getViewParameters();
|
||||
$this->assertEquals(['api_key' => ''], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Good API key length in preferences
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testGetViewParametersGoodLength(): void
|
||||
{
|
||||
// API key should be empty:
|
||||
$apiPref = new Preference;
|
||||
$apiPref->data = '123456789012345678901234567890AA';
|
||||
|
||||
Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'fake_api_key', false])->twice()
|
||||
->andReturn($apiPref);
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$result = $object->getViewParameters();
|
||||
$this->assertEquals(['api_key' => '123456789012345678901234567890AA'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* No preference at all.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testGetViewParametersPrefNull(): void
|
||||
{
|
||||
Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'fake_api_key', false])->once()
|
||||
->andReturn(null);
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$result = $object->getViewParameters();
|
||||
$this->assertEquals(['api_key' => ''], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Also test hasApiKey but that one is covered.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testIsComplete(): void
|
||||
{
|
||||
// API key should be empty:
|
||||
$apiPref = new Preference;
|
||||
$apiPref->data = null;
|
||||
|
||||
Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'fake_api_key', false])->once()
|
||||
->andReturn($apiPref);
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$this->assertFalse($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* Also test hasApiKey but that one is covered.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testStorePrerequisitesBad(): void
|
||||
{
|
||||
$data = [
|
||||
'api_key' => 'Hallo',
|
||||
];
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$messages = $object->storePrerequisites($data);
|
||||
$this->assertCount(1, $messages);
|
||||
$this->assertEquals('API key must be 32 chars.', $messages->first());
|
||||
}
|
||||
|
||||
/**
|
||||
* Also test hasApiKey but that one is covered.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
|
||||
*/
|
||||
public function testStorePrerequisitesGood(): void
|
||||
{
|
||||
$data = [
|
||||
'api_key' => '123456789012345678901234567890AA',
|
||||
];
|
||||
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'fake_api_key', '123456789012345678901234567890AA'])->once();
|
||||
|
||||
$object = new FakePrerequisites();
|
||||
$object->setUser($this->user());
|
||||
$messages = $object->storePrerequisites($data);
|
||||
$this->assertCount(0, $messages);
|
||||
}
|
||||
|
||||
}
|
147
tests/Unit/Import/Routine/FakeRoutineTest.php
Normal file
147
tests/Unit/Import/Routine/FakeRoutineTest.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* FakeRoutineTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\Routine\FakeRoutine;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageAhoyHandler;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageFinalHandler;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageNewHandler;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FakeRoutineTest
|
||||
*/
|
||||
class FakeRoutineTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\FakeRoutine
|
||||
*/
|
||||
public function testRunAhoy()
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'a_route_' . random_int(1, 1000);
|
||||
$job->status = 'running';
|
||||
$job->stage = 'ahoy';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock
|
||||
$handler = $this->mock(StageAhoyHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// calls
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
|
||||
$routine = new FakeRoutine;
|
||||
$routine->setJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\FakeRoutine
|
||||
*/
|
||||
public function testRunFinal()
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'a_route_' . random_int(1, 1000);
|
||||
$job->status = 'running';
|
||||
$job->stage = 'final';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock
|
||||
$handler = $this->mock(StageFinalHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// calls
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
||||
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), []])->once();
|
||||
$handler->shouldReceive('getTransactions')->once()->andReturn([]);
|
||||
$handler->shouldReceive('setJob')->once();
|
||||
|
||||
$routine = new FakeRoutine;
|
||||
$routine->setJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\FakeRoutine
|
||||
*/
|
||||
public function testRunNew()
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'a_route_' . random_int(1, 1000);
|
||||
$job->status = 'running';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock
|
||||
$handler = $this->mock(StageNewHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// calls
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'ahoy'])->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
|
||||
$routine = new FakeRoutine;
|
||||
$routine->setJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
168
tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php
Normal file
168
tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* AbnAmroDescriptionTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Specifics;
|
||||
|
||||
|
||||
use FireflyIII\Import\Specifics\AbnAmroDescription;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AbnAmroDescriptionTest
|
||||
*/
|
||||
class AbnAmroDescriptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Should return the exact same array.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testEmptyRow(): void
|
||||
{
|
||||
$row = [1, 2, 3, 4];
|
||||
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals($row, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that cannot be parsed.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testParseABN(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'ABN AMRO 12345678901234567890ABC SomeOtherDescr', ''];
|
||||
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('SomeOtherDescr', $result[7]);
|
||||
$this->assertEquals('ABN AMRO', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GEA
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testParseGea(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'BEA: GEA NR:00AJ01 31.01.01/19.54 Van HarenSchoenen132 UDE,PAS333', ''];
|
||||
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Van HarenSchoenen132 UDE', $result[8]);
|
||||
$this->assertEquals('GEA Van HarenSchoenen132 UDE', $result[7]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gea bea
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testParseGeaBea(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'BEA: BEA NR:00AJ01 31.01.01/19.54 Van HarenSchoenen132 UDE,PAS333', ''];
|
||||
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Van HarenSchoenen132 UDE', $result[8]);
|
||||
$this->assertEquals('Van HarenSchoenen132 UDE', $result[7]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that cannot be parsed.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testParseUnknown(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'Blabla', ''];
|
||||
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Unknown', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic SEPA data.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testSepaBasic(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: 1232138 1232131233 412321 iBOOD.com iBOOD.com B.V. Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('1232138 1232131233 412321 iBOOD.com iBOOD.com B.V.', $result[7]);
|
||||
$this->assertEquals('Silver Ocean B.V.', $result[8]);
|
||||
$this->assertEquals('NL12RABO0121212212', $result[9]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic SEPA data.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testSepaBasicNoDescription(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals(' PLAIN: SEPA iDEAL - Silver Ocean B.V. (12-12-2014)', $result[7]);
|
||||
$this->assertEquals('Silver Ocean B.V.', $result[8]);
|
||||
$this->assertEquals('NL12RABO0121212212', $result[9]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic TRTP data.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testTRTPBasic(): void {
|
||||
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI/Nullijn/EREF/NOTPROVIDED', '',''];
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Nullijn', $result[7]);
|
||||
$this->assertEquals('baasd dsdsT CJ', $result[8]);
|
||||
$this->assertEquals('NL23ABNA0000000000', $result[9]);
|
||||
}
|
||||
/**
|
||||
* Basic TRTP data with empty description
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
|
||||
*/
|
||||
public function testTRTPEmptyDescr(): void {
|
||||
|
||||
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI//EREF/NOTPROVIDED', '',''];
|
||||
$parser = new AbnAmroDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('SEPA OVERBOEKING - (NOTPROVIDED)', $result[7]);
|
||||
$this->assertEquals('baasd dsdsT CJ', $result[8]);
|
||||
$this->assertEquals('NL23ABNA0000000000', $result[9]);
|
||||
}
|
||||
|
||||
|
||||
}
|
138
tests/Unit/Import/Specifics/IngDescriptionTest.php
Normal file
138
tests/Unit/Import/Specifics/IngDescriptionTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* IngDescriptionTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Specifics;
|
||||
|
||||
|
||||
use FireflyIII\Import\Specifics\IngDescription;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IngDescriptionTest
|
||||
*/
|
||||
class IngDescriptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Try if the IBAN is removed in GT transactions
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunGTRemoveIban(): void
|
||||
{
|
||||
$iban = 'NL66INGB0665877351';
|
||||
$row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Should be removed', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try if the IBAN is removed in OV transactions
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunOVRemoveIban(): void
|
||||
{
|
||||
$iban = 'NL66INGB0665877351';
|
||||
$row = [0, 1, 2, $iban, 'OV', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Should be removed', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try if the IBAN is removed in IC transactions
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunICRemoveIban(): void
|
||||
{
|
||||
$iban = 'NL66INGB0665877351';
|
||||
$row = [0, 1, 2, $iban, 'IC', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Should be removed', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty description? Use "tegenrekening".
|
||||
* Remove specific fields.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunEmptyDescr(): void
|
||||
{
|
||||
$row = [0, 1, 2, '', 'GT', 5, 6, 7, 'Naar Oranje Spaarrekening Bla bla', 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Bla bla', $result[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test changes to BA row.
|
||||
*
|
||||
* Remove specific fields.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunBABasic(): void
|
||||
{
|
||||
$row = [0, 'XX', 2, '', 'BA', 5, 6, 7, 'XX', 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('XX XX', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the description is removed
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunGTRemoveDescr(): void
|
||||
{
|
||||
$iban = 'NL66INGB0665877351';
|
||||
$row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Bla bla bla Omschrijving: Should be removed IBAN: ' . $iban, 9, 10];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Should be removed', $result[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Specifics\IngDescription
|
||||
*/
|
||||
public function testRunShortArray(): void
|
||||
{
|
||||
$row = [0, 1, 2, 3];
|
||||
|
||||
$parser = new IngDescription;
|
||||
$result = $parser->run($row);
|
||||
|
||||
$this->assertEquals($row, $result);
|
||||
}
|
||||
|
||||
}
|
61
tests/Unit/Import/Specifics/PresidentsChoiceTest.php
Normal file
61
tests/Unit/Import/Specifics/PresidentsChoiceTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* PresidentsChoiceTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Specifics;
|
||||
|
||||
|
||||
use FireflyIII\Import\Specifics\PresidentsChoice;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PresidentsChoiceTest
|
||||
*/
|
||||
class PresidentsChoiceTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
|
||||
*/
|
||||
public function testRunBasic():void {
|
||||
$row = [''];
|
||||
|
||||
$parser = new PresidentsChoice;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals($row, $result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
|
||||
*/
|
||||
public function testRunAmount():void {
|
||||
$row = ['','Descr','12.34','',''];
|
||||
|
||||
$parser = new PresidentsChoice;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('-12.34', $result[3]);
|
||||
$this->assertEquals('Descr', $result[2]);
|
||||
|
||||
}
|
||||
|
||||
}
|
39
tests/Unit/Import/Specifics/RabobankDescriptionTest.php
Normal file
39
tests/Unit/Import/Specifics/RabobankDescriptionTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* RabobankDescriptionTest.php
|
||||
* Copyright (c) 2018 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\Unit\Import\Specifics;
|
||||
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RabobankDescriptionTest
|
||||
*/
|
||||
class RabobankDescriptionTest extends TestCase
|
||||
{
|
||||
public function testRunBasic(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user