Remove import tests

This commit is contained in:
James Cole 2019-12-22 07:45:30 +01:00
parent a4d3dba662
commit dcd6a8d79f
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
39 changed files with 0 additions and 7498 deletions

View File

@ -1,199 +0,0 @@
<?php
/**
* AmountCreditTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\AmountCredit;
use Log;
use Tests\TestCase;
/**
* Class AmountCreditTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AmountCreditTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\AmountCredit
*/
public function testConvert(): void
{
$values = [
'0' => '0',
'0.0' => '0.0',
'0.1' => '0.1',
'.2' => '0.2',
'0.01' => '0.01',
'1' => '1',
'1.0' => '1.0',
'1.1' => '1.1',
'1.12' => '1.12',
'1.10' => '1.10',
'12' => '12',
'12.3' => '12.3',
'12.34' => '12.34',
'123' => '123',
'123.4' => '123.4',
'123.45' => '123.45',
'1234' => '1234',
'1234.5' => '1234.5',
'1234.56' => '1234.56',
'1 234' => '1234',
'1 234.5' => '1234.5',
'1 234.56' => '1234.56',
'1,234' => '1234',
'1,234.5' => '1234.5',
'1,234.56' => '1234.56',
'123,456,789' => '123456789',
'0,0' => '0.0',
'0,1' => '0.1',
',2' => '0.2',
'0,01' => '0.01',
'1,0' => '1.0',
'1,1' => '1.1',
'1,12' => '1.12',
'1,10' => '1.10',
'12,3' => '12.3',
'12,34' => '12.34',
'123,4' => '123.4',
'123,45' => '123.45',
'1234,5' => '1234.5',
'1234,56' => '1234.56',
'1 234,5' => '1234.5',
'1 234,56' => '1234.56',
'1.234' => '1.234', // will no longer match as 1234, but as 1.234
'1.234,5' => '1234.5',
'1.234,56' => '1234.56',
// many decimals
'2.00' => '2.00',
'3.000' => '3.000',
'4.0000' => '4.0000',
'5.000' => '5.000',
'6.0000' => '6.0000',
'7.200' => '7.200',
'8.2000' => '8.2000',
'9.330' => '9.330',
'10.3300' => '10.3300',
'11.444' => '11.444',
'12.4440' => '12.4440',
'13.5555' => '13.5555',
'14.45678' => '14.45678',
'15.456789' => '15.456789',
'16.4567898' => '16.4567898',
'17.34567898' => '17.34567898',
'18.134567898' => '18.134567898',
'19.1634567898' => '19.1634567898',
'20.16334567898' => '20.16334567898',
'21.16364567898' => '21.16364567898',
'22.163644567898' => '22.163644567898',
'22.1636445670069' => '22.1636445670069',
// many decimals, mixed, large numbers
'63522.00' => '63522.00',
'63523.000' => '63523.000',
'63524.0000' => '63524.0000',
'63525.000' => '63525.000',
'63526.0000' => '63526.0000',
'63527.200' => '63527.200',
'63528.2000' => '63528.2000',
'63529.330' => '63529.330',
'635210.3300' => '635210.3300',
'635211.444' => '635211.444',
'635212.4440' => '635212.4440',
'635213.5555' => '635213.5555',
'635214.45678' => '635214.45678',
'635215.456789' => '635215.456789',
'635216.4567898' => '635216.4567898',
'635217.34567898' => '635217.34567898',
'635218.134567898' => '635218.134567898',
'635219.1634567898' => '635219.1634567898',
'635220.16334567898' => '635220.16334567898',
'635221.16364567898' => '635221.16364567898',
'635222.163644567898' => '635222.163644567898',
// many decimals, mixed, also mixed thousands separators
'63 522.00' => '63522.00',
'63 523.000' => '63523.000',
'63,524.0000' => '63524.0000',
'63 525.000' => '63525.000',
'63,526.0000' => '63526.0000',
'63 527.200' => '63527.200',
'63 528.2000' => '63528.2000',
'63 529.330' => '63529.330',
'63,5210.3300' => '635210.3300',
'63,5211.444' => '635211.444',
'63 5212.4440' => '635212.4440',
'163 5219.1634567898' => '1635219.1634567898',
'444 163 5219.1634567898' => '4441635219.1634567898',
'-0.34918323' => '0.349183230000',
'0.208' => '0.208',
'-0.15' => '0.150000000000',
'-0.03881677' => '0.038816770000',
'0.33' => '0.33',
'-0.1' => '0.100000000000',
'0.01124' => '0.01124',
'-0.01124' => '0.011240000000',
'0.115' => '0.115',
'-0.115' => '0.115000000000',
'1.33' => '1.33',
'$1.23' => '1.23',
'€1,44' => '1.44',
'(33.52)' => '33.520000000000',
'€(63.12)' => '63.120000000000',
'($182.77)' => '182.770000000000',
// double minus because why the hell not
'--0.03881677' => '0.03881677',
'--0.33' => '0.33',
'--$1.23' => '1.23',
'--63 5212.4440' => '635212.4440',
'--,2' => '0.2',
];
foreach ($values as $value => $expected) {
$converter = new AmountCredit;
$result = $converter->convert($value);
$this->assertEquals($expected, $result, sprintf('The original value was %s, expected was %s', $value, $expected));
}
}
/**
* @covers \FireflyIII\Import\Converter\AmountCredit
*/
public function testConvertNull(): void
{
$converter = new AmountCredit;
$result = $converter->convert(null);
$this->assertEquals('0', $result);
}
}

View File

@ -1,198 +0,0 @@
<?php
/**
* AmountDebitTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\AmountDebit;
use Log;
use Tests\TestCase;
/**
* Class AmountDebitTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AmountDebitTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\AmountDebit
*/
public function testConvert(): void
{
$values = [
'0' => '0.000000000000',
'0.0' => '0.000000000000',
'0.1' => '-0.100000000000',
'.2' => '-0.200000000000',
'0.01' => '-0.010000000000',
'1' => '-1.000000000000',
'1.0' => '-1.000000000000',
'1.1' => '-1.100000000000',
'1.12' => '-1.120000000000',
'1.10' => '-1.100000000000',
'12' => '-12.000000000000',
'12.3' => '-12.300000000000',
'12.34' => '-12.340000000000',
'123' => '-123.000000000000',
'123.4' => '-123.400000000000',
'123.45' => '-123.450000000000',
'1234' => '-1234.000000000000',
'1234.5' => '-1234.500000000000',
'1234.56' => '-1234.560000000000',
'1 234' => '-1234.000000000000',
'1 234.5' => '-1234.500000000000',
'1 234.56' => '-1234.560000000000',
'1,234' => '-1234.000000000000',
'1,234.5' => '-1234.500000000000',
'1,234.56' => '-1234.560000000000',
'123,456,789' => '-123456789.000000000000',
'0,0' => '0.000000000000',
'0,1' => '-0.100000000000',
',2' => '-0.200000000000',
'0,01' => '-0.010000000000',
'1,0' => '-1.000000000000',
'1,1' => '-1.100000000000',
'1,12' => '-1.120000000000',
'1,10' => '-1.100000000000',
'12,3' => '-12.300000000000',
'12,34' => '-12.340000000000',
'123,4' => '-123.400000000000',
'123,45' => '-123.450000000000',
'1234,5' => '-1234.500000000000',
'1234,56' => '-1234.560000000000',
'1 234,5' => '-1234.500000000000',
'1 234,56' => '-1234.560000000000',
'1.234' => '-1.234000000000', // will no longer match as 1234, but as 1.234
'1.234,5' => '-1234.500000000000',
'1.234,56' => '-1234.560000000000',
// many decimals
'2.00' => '-2.000000000000',
'3.000' => '-3.000000000000',
'4.0000' => '-4.000000000000',
'5.000' => '-5.000000000000',
'6.0000' => '-6.000000000000',
'7.200' => '-7.200000000000',
'8.2000' => '-8.200000000000',
'9.330' => '-9.330000000000',
'10.3300' => '-10.330000000000',
'11.444' => '-11.444000000000',
'12.4440' => '-12.444000000000',
'13.5555' => '-13.555500000000',
'14.45678' => '-14.456780000000',
'15.456789' => '-15.456789000000',
'16.4567898' => '-16.456789800000',
'17.34567898' => '-17.345678980000',
'18.134567898' => '-18.134567898000',
'19.1634567898' => '-19.163456789800',
'20.16334567898' => '-20.163345678980',
'21.16364567898' => '-21.163645678980',
'22.163644567898' => '-22.163644567898',
'22.1636445670069' => '-22.163644567006',
// many decimals, mixed, large numbers
'63522.00' => '-63522.000000000000',
'63523.000' => '-63523.000000000000',
'63524.0000' => '-63524.000000000000',
'63525.000' => '-63525.000000000000',
'63526.0000' => '-63526.000000000000',
'63527.200' => '-63527.200000000000',
'63528.2000' => '-63528.200000000000',
'63529.330' => '-63529.330000000000',
'635210.3300' => '-635210.330000000000',
'635211.444' => '-635211.444000000000',
'635212.4440' => '-635212.444000000000',
'635213.5555' => '-635213.555500000000',
'635214.45678' => '-635214.456780000000',
'635215.456789' => '-635215.456789000000',
'635216.4567898' => '-635216.456789800000',
'635217.34567898' => '-635217.345678980000',
'635218.134567898' => '-635218.134567898000',
'635219.1634567898' => '-635219.163456789800',
'635220.16334567898' => '-635220.163345678980',
'635221.16364567898' => '-635221.163645678980',
'635222.163644567898' => '-635222.163644567898',
// many decimals, mixed, also mixed thousands separators
'63 522.00' => '-63522.000000000000',
'63 523.000' => '-63523.000000000000',
'63,524.0000' => '-63524.000000000000',
'63 525.000' => '-63525.000000000000',
'63,526.0000' => '-63526.000000000000',
'63 527.200' => '-63527.200000000000',
'63 528.2000' => '-63528.200000000000',
'63 529.330' => '-63529.330000000000',
'63,5210.3300' => '-635210.330000000000',
'63,5211.444' => '-635211.444000000000',
'63 5212.4440' => '-635212.444000000000',
'163 5219.1634567898' => '-1635219.163456789800',
'444 163 5219.1634567898' => '-4441635219.163456789800',
'-0.34918323' => '-0.349183230000',
'0.208' => '-0.208000000000',
'-0.15' => '-0.150000000000',
'-0.03881677' => '-0.038816770000',
'0.33' => '-0.330000000000',
'-0.1' => '-0.100000000000',
'0.01124' => '-0.011240000000',
'-0.01124' => '-0.011240000000',
'0.115' => '-0.115000000000',
'-0.115' => '-0.115000000000',
'1.33' => '-1.330000000000',
'$1.23' => '-1.230000000000',
'€1,44' => '-1.440000000000',
'(33.52)' => '-33.520000000000',
'€(63.12)' => '-63.120000000000',
'($182.77)' => '-182.770000000000',
// double minus because why the hell not
'--0.03881677' => '-0.038816770000',
'--0.33' => '-0.330000000000',
'--$1.23' => '-1.230000000000',
'--63 5212.4440' => '-635212.444000000000',
'--,2' => '-0.200000000000',
];
foreach ($values as $value => $expected) {
$converter = new AmountDebit;
$result = $converter->convert($value);
$this->assertEquals($expected, $result, sprintf('The original value was %s', $value));
}
}
/**
* @covers \FireflyIII\Import\Converter\AmountDebit
*/
public function testConvertNull(): void
{
$converter = new AmountDebit;
$result = $converter->convert(null);
$this->assertEquals('0.000000000000', $result);
}
}

View File

@ -1,191 +0,0 @@
<?php
/**
* AmountNegatedTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\AmountNegated;
use Tests\TestCase;
/**
* Class AmountNegatedTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AmountNegatedTest extends TestCase
{
/**
* @covers \FireflyIII\Import\Converter\AmountNegated
*/
public function testConvert(): void
{
$values = [
'0' => '0.000000000000',
'0.0' => '0.000000000000',
'0.1' => '-0.100000000000',
'.2' => '-0.200000000000',
'0.01' => '-0.010000000000',
'1' => '-1.000000000000',
'1.0' => '-1.000000000000',
'1.1' => '-1.100000000000',
'1.12' => '-1.120000000000',
'1.10' => '-1.100000000000',
'12' => '-12.000000000000',
'12.3' => '-12.300000000000',
'12.34' => '-12.340000000000',
'123' => '-123.000000000000',
'123.4' => '-123.400000000000',
'123.45' => '-123.450000000000',
'1234' => '-1234.000000000000',
'1234.5' => '-1234.500000000000',
'1234.56' => '-1234.560000000000',
'1 234' => '-1234.000000000000',
'1 234.5' => '-1234.500000000000',
'1 234.56' => '-1234.560000000000',
'1,234' => '-1234.000000000000',
'1,234.5' => '-1234.500000000000',
'1,234.56' => '-1234.560000000000',
'123,456,789' => '-123456789.000000000000',
'0,0' => '0.000000000000',
'0,1' => '-0.100000000000',
',2' => '-0.200000000000',
'0,01' => '-0.010000000000',
'1,0' => '-1.000000000000',
'1,1' => '-1.100000000000',
'1,12' => '-1.120000000000',
'1,10' => '-1.100000000000',
'12,3' => '-12.300000000000',
'12,34' => '-12.340000000000',
'123,4' => '-123.400000000000',
'123,45' => '-123.450000000000',
'1234,5' => '-1234.500000000000',
'1234,56' => '-1234.560000000000',
'1 234,5' => '-1234.500000000000',
'1 234,56' => '-1234.560000000000',
'1.234' => '-1.234000000000', // will no longer match as 1234, but as 1.234
'1.234,5' => '-1234.500000000000',
'1.234,56' => '-1234.560000000000',
// many decimals
'2.00' => '-2.000000000000',
'3.000' => '-3.000000000000',
'4.0000' => '-4.000000000000',
'5.000' => '-5.000000000000',
'6.0000' => '-6.000000000000',
'7.200' => '-7.200000000000',
'8.2000' => '-8.200000000000',
'9.330' => '-9.330000000000',
'10.3300' => '-10.330000000000',
'11.444' => '-11.444000000000',
'12.4440' => '-12.444000000000',
'13.5555' => '-13.555500000000',
'14.45678' => '-14.456780000000',
'15.456789' => '-15.456789000000',
'16.4567898' => '-16.456789800000',
'17.34567898' => '-17.345678980000',
'18.134567898' => '-18.134567898000',
'19.1634567898' => '-19.163456789800',
'20.16334567898' => '-20.163345678980',
'21.16364567898' => '-21.163645678980',
'22.163644567898' => '-22.163644567898',
'22.1636445670069' => '-22.163644567006',
// many decimals, mixed, large numbers
'63522.00' => '-63522.000000000000',
'63523.000' => '-63523.000000000000',
'63524.0000' => '-63524.000000000000',
'63525.000' => '-63525.000000000000',
'63526.0000' => '-63526.000000000000',
'63527.200' => '-63527.200000000000',
'63528.2000' => '-63528.200000000000',
'63529.330' => '-63529.330000000000',
'635210.3300' => '-635210.330000000000',
'635211.444' => '-635211.444000000000',
'635212.4440' => '-635212.444000000000',
'635213.5555' => '-635213.555500000000',
'635214.45678' => '-635214.456780000000',
'635215.456789' => '-635215.456789000000',
'635216.4567898' => '-635216.456789800000',
'635217.34567898' => '-635217.345678980000',
'635218.134567898' => '-635218.134567898000',
'635219.1634567898' => '-635219.163456789800',
'635220.16334567898' => '-635220.163345678980',
'635221.16364567898' => '-635221.163645678980',
'635222.163644567898' => '-635222.163644567898',
// many decimals, mixed, also mixed thousands separators
'63 522.00' => '-63522.000000000000',
'63 523.000' => '-63523.000000000000',
'63,524.0000' => '-63524.000000000000',
'63 525.000' => '-63525.000000000000',
'63,526.0000' => '-63526.000000000000',
'63 527.200' => '-63527.200000000000',
'63 528.2000' => '-63528.200000000000',
'63 529.330' => '-63529.330000000000',
'63,5210.3300' => '-635210.330000000000',
'63,5211.444' => '-635211.444000000000',
'63 5212.4440' => '-635212.444000000000',
'163 5219.1634567898' => '-1635219.163456789800',
'444 163 5219.1634567898' => '-4441635219.163456789800',
'-0.34918323' => '0.349183230000',
'0.208' => '-0.208000000000',
'-0.15' => '0.150000000000',
'-0.03881677' => '0.038816770000',
'0.33' => '-0.330000000000',
'-0.1' => '0.100000000000',
'0.01124' => '-0.011240000000',
'-0.01124' => '0.011240000000',
'0.115' => '-0.115000000000',
'-0.115' => '0.115000000000',
'1.33' => '-1.330000000000',
'$1.23' => '-1.230000000000',
'€1,44' => '-1.440000000000',
'(33.52)' => '33.520000000000',
'€(63.12)' => '63.120000000000',
'($182.77)' => '182.770000000000',
// double minus because why the hell not
'--0.03881677' => '-0.038816770000',
'--0.33' => '-0.330000000000',
'--$1.23' => '-1.230000000000',
'--63 5212.4440' => '-635212.444000000000',
'--,2' => '-0.200000000000',
];
foreach ($values as $value => $expected) {
$converter = new AmountNegated;
$result = $converter->convert($value);
$this->assertEquals($expected, $result, sprintf('The original value was %s, expected was %s', $value, $expected));
}
}
/**
* @covers \FireflyIII\Import\Converter\AmountNegated
*/
public function testConvertNull(): void
{
$converter = new AmountNegated;
$result = $converter->convert(null);
$this->assertEquals('0.000000000000', $result);
}
}

View File

@ -1,203 +0,0 @@
<?php
/**
* AmountTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\Amount;
use Log;
use Tests\TestCase;
/**
* Class AmountTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AmountTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\Amount
*/
public function testConvert(): void
{
$values = [
'0' => '0',
'0.0' => '0.0',
'0.1' => '0.1',
'.2' => '0.2',
'0.01' => '0.01',
'1' => '1',
'1.0' => '1.0',
'1.1' => '1.1',
'1.12' => '1.12',
'1.10' => '1.10',
'12' => '12',
'12.3' => '12.3',
'12.34' => '12.34',
'123' => '123',
'123.4' => '123.4',
'123.45' => '123.45',
'1234' => '1234',
'1234.5' => '1234.5',
'1234.56' => '1234.56',
'1 234' => '1234',
'1 234.5' => '1234.5',
'1 234.56' => '1234.56',
'1,234' => '1234',
'1,234.5' => '1234.5',
'1,234.56' => '1234.56',
'123,456,789' => '123456789',
'0,0' => '0.0',
'0,1' => '0.1',
',2' => '0.2',
'0,01' => '0.01',
'1,0' => '1.0',
'1,1' => '1.1',
'1,12' => '1.12',
'1,10' => '1.10',
'12,3' => '12.3',
'12,34' => '12.34',
'123,4' => '123.4',
'123,45' => '123.45',
'1234,5' => '1234.5',
'1234,56' => '1234.56',
'1 234,5' => '1234.5',
'1 234,56' => '1234.56',
'1.234' => '1.234', // will no longer match as 1234, but as 1.234
'1.234,5' => '1234.5',
'1.234,56' => '1234.56',
// many decimals
'2.00' => '2.00',
'3.000' => '3.000',
'4.0000' => '4.0000',
'5.000' => '5.000',
'6.0000' => '6.0000',
'7.200' => '7.200',
'8.2000' => '8.2000',
'9.330' => '9.330',
'10.3300' => '10.3300',
'11.444' => '11.444',
'12.4440' => '12.4440',
'13.5555' => '13.5555',
'14.45678' => '14.45678',
'15.456789' => '15.456789',
'16.4567898' => '16.4567898',
'17.34567898' => '17.34567898',
'18.134567898' => '18.134567898',
'19.1634567898' => '19.1634567898',
'20.16334567898' => '20.16334567898',
'21.16364567898' => '21.16364567898',
'22.163644567898' => '22.163644567898',
'22.1636445670069' => '22.1636445670069',
// many decimals, mixed, large numbers
'63522.00' => '63522.00',
'63523.000' => '63523.000',
'63524.0000' => '63524.0000',
'63525.000' => '63525.000',
'63526.0000' => '63526.0000',
'63527.200' => '63527.200',
'63528.2000' => '63528.2000',
'63529.330' => '63529.330',
'635210.3300' => '635210.3300',
'635211.444' => '635211.444',
'635212.4440' => '635212.4440',
'635213.5555' => '635213.5555',
'635214.45678' => '635214.45678',
'635215.456789' => '635215.456789',
'635216.4567898' => '635216.4567898',
'635217.34567898' => '635217.34567898',
'635218.134567898' => '635218.134567898',
'635219.1634567898' => '635219.1634567898',
'635220.16334567898' => '635220.16334567898',
'635221.16364567898' => '635221.16364567898',
'635222.163644567898' => '635222.163644567898',
// many decimals, mixed, also mixed thousands separators
'63 522.00' => '63522.00',
'63 523.000' => '63523.000',
'63,524.0000' => '63524.0000',
'63 525.000' => '63525.000',
'63,526.0000' => '63526.0000',
'63 527.200' => '63527.200',
'63 528.2000' => '63528.2000',
'63 529.330' => '63529.330',
'63,5210.3300' => '635210.3300',
'63,5211.444' => '635211.444',
'63 5212.4440' => '635212.4440',
'163 5219.1634567898' => '1635219.1634567898',
'444 163 5219.1634567898' => '4441635219.1634567898',
'-0.34918323' => '-0.34918323',
'0.208' => '0.208',
'-0.15' => '-0.15',
'-0.03881677' => '-0.03881677',
'0.33' => '0.33',
'-0.1' => '-0.1',
'0.01124' => '0.01124',
'-0.01124' => '-0.01124',
'0.115' => '0.115',
'-0.115' => '-0.115',
'1.33' => '1.33',
'$1.23' => '1.23',
'€1,44' => '1.44',
'(33.52)' => '-33.52',
'€(63.12)' => '-63.12',
'($182.77)' => '-182.77',
// double minus because why the hell not
'--0.03881677' => '0.03881677',
'--0.33' => '0.33',
'--$1.23' => '1.23',
'--63 5212.4440' => '635212.4440',
'--,2' => '0.2',
// Postbank (DE) tests
'1.000,00 €' => '1000.00',
'120,34 €' => '120.34',
'-120,34 €' => '-120.34',
'-1.000,00 €' => '-1000.00',
];
foreach ($values as $value => $expected) {
$converter = new Amount;
$result = $converter->convert($value);
$this->assertEquals($expected, $result, sprintf('The original value was "%s", returned was "%s"', $value, $result));
}
}
/**
* @covers \FireflyIII\Import\Converter\Amount
*/
public function testConvertNull(): void
{
$converter = new Amount;
$result = $converter->convert(null);
$this->assertEquals('0', $result);
}
}

View File

@ -1,98 +0,0 @@
<?php
/**
* BankDebitCreditTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\BankDebitCredit;
use FireflyIII\Import\Converter\INGDebitCredit;
use Log;
use Tests\TestCase;
/**
*
* Class BankDebitCreditTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BankDebitCreditTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertA(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('A');
$this->assertEquals(-1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertAf(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('Af');
$this->assertEquals(-1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertAnything(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('9083jkdkj');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertBij(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('Bij');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertDebet(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('Debet');
$this->assertEquals(-1, $result);
}
}

View File

@ -1,183 +0,0 @@
<?php
/**
* BunqJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\JobConfiguration\BunqJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler;
use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler;
use Illuminate\Support\MessageBag;
use Log;
use Tests\TestCase;
/**
* Class BunqJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BunqJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration
*/
public function testConfigurationComplete(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'bunq_jc_A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "NewBunqJobHandler" to be created because job is new.
$handler = $this->mock(NewBunqJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configurationComplete')->once()->andReturn(true);
$config = new BunqJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($config->configurationComplete());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration
*/
public function testConfigureJob(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'bunq_jc_B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
$configData = ['ssome' => 'values'];
$return = new MessageBag();
$return->add('some', 'return message');
// expect "NewBunqJobHandler" to be created because job is in "do-authenticate".
$handler = $this->mock(NewBunqJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return);
$config = new BunqJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($return, $config->configureJob($configData));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration
*/
public function testGetNextData(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'bunq_jc_C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
$data = ['ssome' => 'values'];
// Expect "NewBunqJobHandler" because of state.
$handler = $this->mock(NewBunqJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextData')->once()->andReturn($data);
$config = new BunqJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($data, $config->getNextData());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration
*/
public function testGetNextViewAccount(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'bunq_jc_E' . $this->randomInt();
$job->status = 'new';
$job->stage = 'choose-accounts';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "ChooseAccountsHandler" because of state.
$handler = $this->mock(ChooseAccountsHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2');
$config = new BunqJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.fake.view2', $config->getNextView());
}
}

View File

@ -1,641 +0,0 @@
<?php
/**
* FakeJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Log;
use Mockery;
use Tests\TestCase;
/**
* Class FakeJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FakeJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* No config, job is new.
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCC(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'A_unit_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
$job->file_type = '';
$job->configuration = [];
$job->save();
// should be false:
$configurator = new FakeJobConfiguration;
$configurator->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* No config, job is not new.
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCAlbumFalse(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'B_unit_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'needs_config';
$job->provider = 'fake';
$job->file_type = '';
$job->configuration = [];
$job->save();
// should be false:
$configurator = new FakeJobConfiguration;
$configurator->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* Job only says to apply rules.
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCApplyRules(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'C_unit_' . $this->randomInt();
$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->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* Job has album but wrong one.
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCBadAlbum(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'D_unit_' . $this->randomInt();
$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->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* Job has album + song, but bad content.
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCBadInfo(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'E_unit_' . $this->randomInt();
$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->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* Job has correct album
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCGoodAlbum(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'f_unit_' . $this->randomInt();
$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->setImportJob($job);
$this->assertTrue($configurator->configurationComplete());
}
/**
* Job has correct content for "new"!
*
* @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
*/
public function testCCGoodNewInfo(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'g_unit_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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_' . $this->randomInt();
$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->setImportJob($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
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'p_unit_' . $this->randomInt();
$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->setImportJob($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
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'p_unit_' . $this->randomInt();
$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->setImportJob($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
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'p_unit_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
$job->file_type = '';
$job->configuration = [];
$job->save();
// call configuration
$configurator = new FakeJobConfiguration;
$configurator->setImportJob($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
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'p_unit_' . $this->randomInt();
$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->setImportJob($job);
$view = $configurator->getNextView();
$this->assertEquals('import.fake.enter-song', $view);
}
}

View File

@ -1,404 +0,0 @@
<?php
/**
* FileJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\JobConfiguration\FileJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler;
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler;
use FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class FileJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FileJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* No config, job is new.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testCCFalse(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'File_A_unit_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
$job->file_type = '';
$job->configuration = [];
$job->save();
// should be false:
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$this->assertFalse($configurator->configurationComplete());
}
/**
* Job is ready to run.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testCCTrue(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'File_B_unit_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'ready_to_run';
$job->provider = 'fake';
$job->file_type = '';
$job->configuration = [];
$job->save();
// should be false:
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$this->assertTrue($configurator->configurationComplete());
}
/**
* Configure the job when the stage is "map". Won't test other combo's because they're covered by other tests.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testConfigureJob(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'I-Cfile_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'map';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$bag = new MessageBag;
$result = null;
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$handler = $this->mock(ConfigureMappingHandler::class);
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
$handler->shouldReceive('configureJob')->withArgs([['c' => 'd']])->andReturn($bag)->once();
try {
$result = $configurator->configureJob(['c' => 'd']);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($bag, $result);
}
/**
* Get next data when stage is "configure-upload". Expect a certain class to be called.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextDataCU(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'G-Dfile_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'configure-upload';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$handler = $this->mock(ConfigureUploadHandler::class);
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
try {
$result = $configurator->getNextData();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals(['a' => 'b'], $result);
}
/**
* Get next data when stage is "map". Expect a certain class to be called.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextDataMap(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'H-Efile_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'map';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$handler = $this->mock(ConfigureMappingHandler::class);
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
try {
$result = $configurator->getNextData();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals(['a' => 'b'], $result);
}
/**
* Get next data when stage is "new". Expect a certain class to be called.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextDataNew(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'F-fFile_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$handler = $this->mock(NewFileJobHandler::class);
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
try {
$result = $configurator->getNextData();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals(['a' => 'b'], $result);
}
/**
* Get next data when stage is "roles". Expect a certain class to be called.
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextDataRoles(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'H-fiGle_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'roles';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
$handler = $this->mock(ConfigureRolesHandler::class);
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
try {
$result = $configurator->getNextData();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals(['a' => 'b'], $result);
}
/**
* Get view when stage is "configure-upload".
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextViewCU(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'DfiHle_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'configure-upload';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
try {
$result = $configurator->getNextView();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.file.configure-upload', $result);
}
/**
* Get view when stage is "map".
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextViewMap(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'FfilIe_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'map';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
try {
$result = $configurator->getNextView();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.file.map', $result);
}
/**
* Get view when stage is "new".
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextViewNew(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'CfJile_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
try {
$result = $configurator->getNextView();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.file.new', $result);
}
/**
* Get view when stage is "roles".
*
* @covers \FireflyIII\Import\JobConfiguration\FileJobConfiguration
*/
public function testGetNextViewRoles(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once()->atLeast();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'EfiKle_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'roles';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$result = 'x';
$configurator = new FileJobConfiguration;
$configurator->setImportJob($job);
try {
$result = $configurator->getNextView();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.file.roles', $result);
}
}

View File

@ -1,172 +0,0 @@
<?php
/**
* FinTSJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\JobConfiguration\FinTSJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\FinTS\ChooseAccountHandler;
use FireflyIII\Support\Import\JobConfiguration\FinTS\NewFinTSJobHandler;
use Log;
use Tests\TestCase;
/**
* Class FinTSJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FinTSJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration
*/
public function testConfigurationComplete(): void
{
$this->mock(ImportJobRepositoryInterface::class);
$this->mock(NewFinTSJobHandler::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'fints_jc_A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'go-for-import';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
$config = new FinTSJobConfiguration;
$config->setImportJob($job);
$this->assertTrue($config->configurationComplete());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration
*/
public function testConfigureJob(): void
{
$this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(NewFinTSJobHandler::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'fints_jc_B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
$handler->shouldReceive('setImportJob')->atLeast()->once();
$handler->shouldReceive('configureJob')->atLeast()->once()->withArgs([[123]]);
$config = new FinTSJobConfiguration;
$config->setImportJob($job);
try {
$config->configureJob([123]);
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration
*/
public function testGetNextData(): void
{
$this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(ChooseAccountHandler::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'fints_jc_C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'choose_account';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
$handler->shouldReceive('setImportJob')->atLeast()->once();
$handler->shouldReceive('getNextData')->atLeast()->once()->withNoArgs()->andReturn([456]);
$res = [];
$config = new FinTSJobConfiguration;
$config->setImportJob($job);
try {
$res = $config->getNextData();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
$this->assertEquals([456], $res);
}
/**
* @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration
*/
public function testGetNextView(): void
{
$this->mock(ImportJobRepositoryInterface::class);
$this->mock(ChooseAccountHandler::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'fints_jc_D' . $this->randomInt();
$job->status = 'new';
$job->stage = 'choose_account';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
$res = [];
$config = new FinTSJobConfiguration;
$config->setImportJob($job);
try {
$res = $config->getNextView();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
$this->assertEquals('import.fints.choose_account', $res);
}
}

View File

@ -1,217 +0,0 @@
<?php
/**
* SpectreJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\JobConfiguration\SpectreJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewSpectreJobHandler;
use Illuminate\Support\MessageBag;
use Log;
use Tests\TestCase;
/**
* Class SpectreJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class SpectreJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
*/
public function testConfigurationComplete(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'spectre_jc_A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "NewSpectreJobHandler" to be created because job is new.
$handler = $this->mock(NewSpectreJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configurationComplete')->once()->andReturn(true);
$config = new SpectreJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($config->configurationComplete());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
*/
public function testConfigureJob(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'spectre_jc_B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'do-authenticate';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
$configData = ['ssome' => 'values'];
$return = new MessageBag();
$return->add('some', 'return message');
// expect "DoAuthenticateHandler" to be created because job is in "do-authenticate".
$handler = $this->mock(DoAuthenticateHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return);
$config = new SpectreJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($return, $config->configureJob($configData));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
*/
public function testGetNextData(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'spectre_jc_C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'choose-login';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
$data = ['ssome' => 'values'];
// Expect choose-login handler because of state.
$handler = $this->mock(ChooseLoginHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextData')->once()->andReturn($data);
$config = new SpectreJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($data, $config->getNextData());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
*/
public function testGetNextView(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'spectre_jc_D' . $this->randomInt();
$job->status = 'new';
$job->stage = 'authenticated';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "AuthenticatedHandler" because of state.
$handler = $this->mock(AuthenticatedHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view');
$config = new SpectreJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.fake.view', $config->getNextView());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
*/
public function testGetNextViewAccount(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'spectre_jc_E' . $this->randomInt();
$job->status = 'new';
$job->stage = 'choose-accounts';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "ChooseAccountsHandler" because of state.
$handler = $this->mock(ChooseAccountsHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2');
$config = new SpectreJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.fake.view2', $config->getNextView());
}
}

View File

@ -1,184 +0,0 @@
<?php
/**
* YnabJobConfigurationTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\JobConfiguration\YnabJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Ynab\NewYnabJobHandler;
use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectAccountsHandler;
use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectBudgetHandler;
use Illuminate\Support\MessageBag;
use Log;
use Tests\TestCase;
/**
* Class YnabJobConfigurationTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class YnabJobConfigurationTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration
*/
public function testConfigurationComplete(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_jc_A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "NewYnabJobHandler" to be created because job is new.
$handler = $this->mock(NewYnabJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configurationComplete')->once()->andReturn(true);
$config = new YnabJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($config->configurationComplete());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration
*/
public function testConfigureJob(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_jc_B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'select_budgets';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
$configData = ['ssome' => 'values'];
$return = new MessageBag();
$return->add('some', 'return message');
// expect "SelectBudgetHandler" to be created because job is in "select_budgets".
$handler = $this->mock(SelectBudgetHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return);
$config = new YnabJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($return, $config->configureJob($configData));
}
/**
* @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration
*/
public function testGetNextData(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_jc_C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'select_accounts';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
$data = ['ssome' => 'values'];
// Expect "SelectAccountsHandler" because state is "select_accounts"
$handler = $this->mock(SelectAccountsHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextData')->once()->andReturn($data);
$config = new YnabJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($data, $config->getNextData());
}
/**
* @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration
*/
public function testGetNextView(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_jc_E' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// expect "NewYnabJobHandler" because of state.
$handler = $this->mock(NewYnabJobHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2');
$config = new YnabJobConfiguration;
try {
$config->setImportJob($job);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals('import.fake.view2', $config->getNextView());
}
}

View File

@ -1,96 +0,0 @@
<?php
/**
* AssetAccountIbansTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\AssetAccountIbans;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class AssetAccountIbansTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AssetAccountIbansTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\AssetAccountIbans
*/
public function testGetMapBasic(): void
{
$asset = AccountType::where('type', AccountType::ASSET)->first();
$loan = AccountType::where('type', AccountType::LOAN)->first();
$one = new Account;
$one->id = 17;
$one->name = 'Something';
$one->iban = 'IBAN';
$one->account_type_id = $asset->id;
$two = new Account;
$two->id = 53;
$two->name = 'Else';
$two->account_type_id = $loan->id;
$three = new Account;
$three->id = 66;
$three->name = 'I have IBAN';
$three->iban = 'IBAN';
$three->account_type_id = $loan->id;
$collection = new Collection([$one, $two, $three]);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs(
[[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]]
)->andReturn($collection)->once();
$mapper = new AssetAccountIbans();
$mapping = $mapper->getMap();
$this->assertCount(4, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
53 => 'Else (liability)',
66 => 'IBAN (I have IBAN) (liability)',
17 => 'IBAN (Something)',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,91 +0,0 @@
<?php
/**
* AssetAccountsTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\AssetAccounts;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class AssetAccountsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AssetAccountsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\AssetAccounts
*/
public function testGetMapBasic(): void
{
$asset = AccountType::where('type', AccountType::ASSET)->first();
$loan = AccountType::where('type', AccountType::LOAN)->first();
$one = new Account;
$one->id = 23;
$one->name = 'Something';
$one->iban = 'IBAN';
$one->account_type_id = $asset->id;
$two = new Account;
$two->id = 19;
$two->name = 'Else';
$two->account_type_id = $loan->id;
$collection = new Collection([$one, $two]);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs(
[[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]]
)->andReturn($collection)->once();
$mapper = new AssetAccounts();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
19 => 'Liability: Else',
23 => 'Something (IBAN)',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,81 +0,0 @@
<?php
/**
* BillsTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\Bills;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class BillsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BillsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\Bills
*/
public function testGetMapBasic(): void
{
$one = new Bill;
$one->id = 5;
$one->name = 'Something';
$one->match = 'hi,bye';
$two = new Bill;
$two->id = 9;
$two->name = 'Else';
$two->match = 'match';
$collection = new Collection([$one, $two]);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getBills')->andReturn($collection)->once();
$mapper = new Bills();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
9 => 'Else',
5 => 'Something',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,79 +0,0 @@
<?php
/**
* BudgetsTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\Budgets;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class BudgetsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BudgetsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\Budgets
*/
public function testGetMapBasic(): void
{
$one = new Budget;
$one->id = 8;
$one->name = 'Something';
$two = new Budget;
$two->id = 4;
$two->name = 'Else';
$collection = new Collection([$one, $two]);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('getActiveBudgets')->andReturn($collection)->once();
$mapper = new Budgets();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
4 => 'Else',
8 => 'Something',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,80 +0,0 @@
<?php
/**
* CategoriesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\Categories;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class CategoriesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CategoriesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\Categories
*/
public function testGetMapBasic(): void
{
$one = new Category;
$one->id = 9;
$one->name = 'Something';
$two = new Category;
$two->id = 17;
$two->name = 'Else';
$collection = new Collection([$one, $two]);
$repository = $this->mock(CategoryRepositoryInterface::class);
$repository->shouldReceive('getCategories')->andReturn($collection)->once();
$mapper = new Categories();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
17 => 'Else',
9 => 'Something',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,97 +0,0 @@
<?php
/**
* OpposingAccountIbansTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\OpposingAccountIbans;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class OpposingAccountIbansTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class OpposingAccountIbansTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\OpposingAccountIbans
*/
public function testGetMapBasic(): void
{
$asset = AccountType::where('type', AccountType::ASSET)->first();
$loan = AccountType::where('type', AccountType::LOAN)->first();
$one = new Account;
$one->id = 21;
$one->name = 'Something';
$one->iban = 'IBAN';
$one->account_type_id = $asset->id;
$two = new Account;
$two->id = 17;
$two->name = 'Else';
$two->account_type_id = $loan->id;
$three = new Account;
$three->id = 66;
$three->name = 'I have IBAN';
$three->iban = 'IBAN';
$three->account_type_id = $loan->id;
$collection = new Collection([$one, $two, $three]);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs(
[[AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE, AccountType::LOAN,
AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]]
)->andReturn($collection)->once();
$mapper = new OpposingAccountIbans();
$mapping = $mapper->getMap();
$this->assertCount(4, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
17 => 'Else (liability)',
66 => 'IBAN (I have IBAN) (liability)',
21 => 'IBAN (Something)',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* OpposingAccountsTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\OpposingAccounts;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class OpposingAccountsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class OpposingAccountsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\OpposingAccounts
*/
public function testGetMapBasic(): void
{
$asset = AccountType::where('type', AccountType::ASSET)->first();
$loan = AccountType::where('type', AccountType::LOAN)->first();
$one = new Account;
$one->id = 13;
$one->name = 'Something';
$one->iban = 'IBAN';
$one->account_type_id = $asset->id;
$two = new Account;
$two->id = 9;
$two->name = 'Else';
$two->account_type_id = $loan->id;
$collection = new Collection([$one, $two]);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs(
[[
AccountType::DEFAULT, AccountType::ASSET,
AccountType::EXPENSE, AccountType::BENEFICIARY,
AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,
AccountType::CREDITCARD, AccountType::MORTGAGE,
]]
)->andReturn($collection)->once();
$mapper = new OpposingAccounts();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
9 => 'Liability: Else',
13 => 'Something (IBAN)',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,79 +0,0 @@
<?php
/**
* TagsTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\Tags;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class TagsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TagsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\Tags
*/
public function testGetMapBasic(): void
{
$one = new Tag;
$one->id = 12;
$one->tag = 'Something';
$two = new Tag;
$two->id = 14;
$two->tag = 'Else';
$collection = new Collection([$one, $two]);
$repository = $this->mock(TagRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn($collection)->once();
$mapper = new Tags();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
14 => 'Else',
12 => 'Something',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,81 +0,0 @@
<?php
/**
* TransactionCurrenciesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Mapper;
use FireflyIII\Import\Mapper\TransactionCurrencies;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class TransactionCurrenciesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TransactionCurrenciesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Mapper\TransactionCurrencies
*/
public function testGetMapBasic(): void
{
$one = new TransactionCurrency;
$one->id = 9;
$one->name = 'Something';
$one->code = 'ABC';
$two = new TransactionCurrency;
$two->id = 11;
$two->name = 'Else';
$two->code = 'DEF';
$collection = new Collection([$one, $two]);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn($collection)->once();
$mapper = new TransactionCurrencies();
$mapping = $mapper->getMap();
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => (string)trans('import.map_do_not_map'),
11 => 'Else (DEF)',
9 => 'Something (ABC)',
];
$this->assertEquals($result, $mapping);
}
}

View File

@ -1,62 +0,0 @@
<?php
/**
* TagsCommaTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsComma;
use Log;
use Tests\TestCase;
/**
* Class TagsCommaTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TagsCommaTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* \FireflyIII\Import\MapperPreProcess\TagsComma
*/
public function testBasic(): void
{
$input = 'some,tags, with, spaces ,and,without,,';
$output = ['some', 'tags', 'with', 'spaces', 'and', 'without'];
$mapper = new TagsComma();
$result = $mapper->run($input);
$this->assertEquals($output, $result);
}
}

View File

@ -1,61 +0,0 @@
<?php
/**
* TagsSpaceTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsSpace;
use Log;
use Tests\TestCase;
/**
* Class TagsSpaceTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TagsSpaceTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* \FireflyIII\Import\MapperPreProcess\TagsSpace
*/
public function testBasic(): void
{
$input = 'some tags with spaces,and without ';
$output = ['some', 'tags', 'with', 'spaces,and', 'without'];
$mapper = new TagsSpace();
$result = $mapper->run($input);
$this->assertEquals($output, $result);
}
}

View File

@ -1,232 +0,0 @@
<?php
/**
* BunqPrerequisitesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Prerequisites;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Prerequisites\BunqPrerequisites;
use FireflyIII\Models\Preference;
use FireflyIII\Services\Bunq\ApiContext;
use FireflyIII\Services\IP\IPRetrievalInterface;
use Log;
use Mockery;
use Preferences;
use Tests\Object\FakeApiContext;
use Tests\TestCase;
/**
* Class BunqPrerequisitesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BunqPrerequisitesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Has no API key, has no external IP.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testGetViewParameters(): void
{
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturnNull()->twice();
$service = $this->mock(IPRetrievalInterface::class);
$service->shouldReceive('getIP')->once()->andReturn('10.0.0.15');
$object = new BunqPrerequisites;
$object->setUser($this->user());
$parameters = $object->getViewParameters();
$this->assertEquals(['api_key' => '', 'external_ip' => '10.0.0.15'], $parameters);
}
/**
* Has empty API key, has empty external IP.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testGetViewParametersEmpty(): void
{
$pref = new Preference;
$pref->name = 'dontmatter';
$pref->data = '';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturn($pref)->twice();
$service = $this->mock(IPRetrievalInterface::class);
$service->shouldReceive('getIP')->once()->andReturn('10.0.0.15');
$object = new BunqPrerequisites;
$object->setUser($this->user());
$parameters = $object->getViewParameters();
$this->assertEquals(['api_key' => '', 'external_ip' => '10.0.0.15'], $parameters);
}
/**
* Has API key, has external IP.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testGetViewParametersFilled(): void
{
$pref = new Preference;
$pref->name = 'dontmatter';
$pref->data = 'data';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturn($pref)->times(2);
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturn($pref)->times(3);
$object = new BunqPrerequisites;
$object->setUser($this->user());
$parameters = $object->getViewParameters();
$this->assertEquals(['api_key' => 'data', 'external_ip' => 'data'], $parameters);
}
/**
* API context empty
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testIsCompleteEmpty(): void
{
$pref = new Preference;
$pref->name = 'dontmatter';
$pref->data = 'data';
$empty = new Preference;
$empty->name = 'dontmatter';
$empty->data = '';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($empty)->once();
$object = new BunqPrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
* API context filled
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testIsCompleteFilled(): void
{
$pref = new Preference;
$pref->name = 'dontmatter';
$pref->data = 'data';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($pref)->once();
$object = new BunqPrerequisites;
$object->setUser($this->user());
$this->assertTrue($object->isComplete());
}
/**
* API context null.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testIsCompleteNull(): void
{
$pref = new Preference;
$pref->name = 'dontmatter';
$pref->data = 'data';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_external_ip', null])->andReturn($pref)->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturnNull()->once();
$object = new BunqPrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
* Test call to API.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testStorePrerequisites(): void
{
$object = new BunqPrerequisites;
$object->setUser($this->user());
$data = [
'api_key' => 'Some API key',
'external_ip' => '10.0.0.15',
];
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'bunq_api_key', $data['api_key']])->once();
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'bunq_external_ip', $data['external_ip']])->once();
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'bunq_api_context', '{"a":"b"}'])->once();
// create fake context
$context = $this->mock(ApiContext::class);
$context->shouldReceive('create')
->withArgs([Mockery::any(), 'Some API key', 'Firefly III v' . config('firefly.version'), [$data['external_ip']]])
->once()->andReturn(new FakeApiContext());
$messages = $object->storePrerequisites($data);
$this->assertEquals('', $messages->first());
$this->assertCount(0, $messages);
}
/**
* Test call that throws error.
*
* @covers \FireflyIII\Import\Prerequisites\BunqPrerequisites
*/
public function testStorePrerequisitesExp(): void
{
$object = new BunqPrerequisites;
$object->setUser($this->user());
$data = [
'api_key' => 'Some API key',
'external_ip' => '10.0.0.15',
];
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'bunq_api_key', $data['api_key']])->once();
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'bunq_external_ip', $data['external_ip']])->once();
// create fake context
$context = $this->mock(ApiContext::class);
$context->shouldReceive('create')
->withArgs([Mockery::any(), 'Some API key', 'Firefly III v' . config('firefly.version'), [$data['external_ip']]])
->once()->andThrow(new FireflyException('Some exception'));
$messages = $object->storePrerequisites($data);
$this->assertEquals('Some exception', $messages->first());
$this->assertCount(1, $messages);
}
}

View File

@ -1,187 +0,0 @@
<?php
/**
* FakePrerequisitesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Prerequisites;
use FireflyIII\Import\Prerequisites\FakePrerequisites;
use FireflyIII\Models\Preference;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class FakePrerequisitesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FakePrerequisitesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* 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);
}
}

View File

@ -1,259 +0,0 @@
<?php
/**
* SpectrePrerequisitesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Prerequisites;
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
use FireflyIII\Models\Preference;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class SpectrePrerequisitesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class SpectrePrerequisitesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testGetView(): void
{
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertEquals('import.spectre.prerequisites', $object->getView());
}
/**
* Returns NULL as much as possible, forcing system to generate new keys.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testGetViewParameters(): void
{
$publicKey = new Preference;
$publicKey->name = 'spectre_public_key';
$publicKey->data = '---PUBKEY---';
$privateKey = new Preference;
$privateKey->name = 'spectre_private_key';
$privateKey->data = '---PRIVKEY---';
// get secret
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_secret', null])
->andReturnNull();
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturnNull();
// get users public key
// second time it should exist.
Preferences::shouldReceive('getForUser')->twice()
->withArgs([Mockery::any(), 'spectre_public_key', null])
->andReturn(null, $publicKey);
// SET users new pulic key
Preferences::shouldReceive('setForUser')->once()
->withArgs([Mockery::any(), 'spectre_public_key', Mockery::any()])
->andReturn($publicKey);
// SET private key
Preferences::shouldReceive('setForUser')->once()
->withArgs([Mockery::any(), 'spectre_private_key', Mockery::any()])
->andReturn($privateKey);
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$return = $object->getViewParameters();
$this->assertEquals(
[
'app_id' => '',
'secret' => '',
'public_key' => '---PUBKEY---',
], $return
);
}
/**
* App ID exists, secret is empty.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testIsComplete(): void
{
$appId = new Preference;
$appId->name = 'spectre_app_id';
$appId->data = 'Some app id';
$secret = new Preference;
$secret->name = 'spectre_secret';
$secret->data = 'Hello';
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturn($appId);
// get secret
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_secret', null])
->andReturn($secret);
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertTrue($object->isComplete());
}
/**
* App ID exists, secret is null.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testIsCompleteAppId(): void
{
$appId = new Preference;
$appId->name = 'spectre_app_id';
$appId->data = 'Some app id';
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturn($appId);
// get secret
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_secret', null])
->andReturnNull();
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
* App ID is "" and Secret is NULL. Since App ID is "" secret won't be polled.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testIsCompleteEmpty(): void
{
$appId = new Preference;
$appId->name = 'spectre_app_id';
$appId->data = '';
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturn($appId);
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
* App ID and Secret are NULL. Since App ID is null secret won't be polled.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testIsCompleteNull(): void
{
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturnNull();
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
* App ID exists, secret is empty.
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testIsCompleteSecretEmpty(): void
{
$appId = new Preference;
$appId->name = 'spectre_app_id';
$appId->data = 'Some app id';
$secret = new Preference;
$secret->name = 'spectre_secret';
$secret->data = '';
// get App ID
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', null])
->andReturn($appId);
// get secret
Preferences::shouldReceive('getForUser')->once()
->withArgs([Mockery::any(), 'spectre_secret', null])
->andReturn($secret);
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertFalse($object->isComplete());
}
/**
*
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
*/
public function testStorePrerequisites(): void
{
$data = [
'app_id' => 'Some app ID',
'secret' => 'Very secret!',
];
// set values
Preferences::shouldReceive('setForUser')->once()
->withArgs([Mockery::any(), 'spectre_app_id', $data['app_id']])
->andReturn(new Preference());
Preferences::shouldReceive('setForUser')->once()
->withArgs([Mockery::any(), 'spectre_secret', $data['secret']])
->andReturn(new Preference());
$object = new SpectrePrerequisites;
$object->setUser($this->user());
$this->assertEquals(0, $object->storePrerequisites($data)->count());
}
}

View File

@ -1,166 +0,0 @@
<?php
/**
* YnabPrerequisitesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace tests\Unit\Import\Prerequisites;
use FireflyIII\Import\Prerequisites\YnabPrerequisites;
use FireflyIII\Models\Preference;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class YnabPrerequisitesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class YnabPrerequisitesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetView(): void
{
$object = new YnabPrerequisites;
$object->setUser($this->user());
$this->assertEquals('import.ynab.prerequisites', $object->getView());
}
/**
* First test, user has empty.
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetViewParametersEmpty(): void
{
$clientId = new Preference;
$clientId->data = '';
$clientSecret = new Preference;
$clientSecret->data = '';
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn($clientId);
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn($clientSecret);
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => '', 'client_secret' => '', 'callback_uri' => 'http://localhost/import/ynab-callback', 'is_https' => false];
$this->assertEquals($expected, $result);
}
/**
* First test, user has nothing.
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetViewParametersFilled(): void
{
$clientId = new Preference;
$clientId->data = 'client-id';
$clientSecret = new Preference;
$clientSecret->data = 'client-secret';
Preferences::shouldReceive('getForUser')->twice()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn($clientId);
Preferences::shouldReceive('getForUser')->twice()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn($clientSecret);
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => 'client-id', 'client_secret' => 'client-secret', 'callback_uri' => 'http://localhost/import/ynab-callback',
'is_https' => false];
$this->assertEquals($expected, $result);
}
/**
* First test, user has nothing.
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetViewParametersNull(): void
{
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn(null);
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn(null);
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => '', 'client_secret' => '', 'callback_uri' => 'http://localhost/import/ynab-callback', 'is_https' => false];
$this->assertEquals($expected, $result);
}
/**
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testIsComplete(): void
{
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn(null);
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->isComplete();
$this->assertFalse($result);
}
/**
*
*/
public function testStorePrerequisites(): void
{
Preferences::shouldReceive('setForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', 'hello']);
Preferences::shouldReceive('setForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', 'hi there']);
$data = [
'client_id' => 'hello',
'client_secret' => 'hi there',
];
$object = new YnabPrerequisites();
$object->setUser($this->user());
$object->storePrerequisites($data);
}
}

View File

@ -1,176 +0,0 @@
<?php
/**
* BunqRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\BunqRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\Bunq\StageNewHandler;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class BunqRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BunqRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\BunqRoutine
*/
public function testRunImport(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageImportDataHandler::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']);
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']);
$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
$handler->shouldReceive('isStillRunning')->andReturn(false);
$routine = new BunqRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\BunqRoutine
*/
public function testRunImportStillRunning(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageImportDataHandler::class);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
$handler->shouldReceive('isStillRunning')->andReturn(true);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'go-for-import']);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
$routine = new BunqRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\BunqRoutine
*/
public function testRunNew(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brX_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageNewHandler::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'choose-accounts'])->once();
$routine = new BunqRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
}
}

View File

@ -1,163 +0,0 @@
<?php
/**
* FakeRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Log;
use Mockery;
use Tests\TestCase;
/**
* Class FakeRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FakeRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\FakeRoutine
*/
public function testRunAhoy(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$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(), 'running'])->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->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\FakeRoutine
*/
public function testRunFinal(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$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([]);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$handler->shouldReceive('setImportJob')->once();
$routine = new FakeRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\FakeRoutine
*/
public function testRunNew(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$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();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$handler->shouldReceive('run')->once();
$routine = new FakeRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
}

View File

@ -1,103 +0,0 @@
<?php
/**
* FileRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Import\Routine\FileRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\File\CSVProcessor;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class FileRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FileRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\FileRoutine
*/
public function testRunDefault(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageImportDataHandler::class);
$this->mock(AttachmentHelperInterface::class);
$csv = $this->mock(CSVProcessor::class);
$csv->shouldReceive('setImportJob')->atLeast()->once();
$csv->shouldReceive('run')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']);
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']);
$repository->shouldReceive('getConfiguration')->atLeast()->once()->andReturn([]);
//$repository->shouldReceive('getAttachments')->atLeast()->once()->andReturn(new Collection);
$repository->shouldReceive('setTransactions')->atLeast()->once();
//$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
//$handler->shouldReceive('setImportJob')->once();
//$handler->shouldReceive('run')->once();
//$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
$handler->shouldReceive('isStillRunning')->andReturn(false);
$routine = new FileRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
}
}

View File

@ -1,92 +0,0 @@
<?php
/**
* FinTSRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\FinTSRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class FinTSRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FinTSRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\FinTSRoutine
*/
public function testRunDefault(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_fin_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock
$handler = $this->mock(StageImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// calls
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once();
$handler->shouldReceive('setImportJob')->atLeast()->once();
$handler->shouldReceive('run')->once()->atLeast()->once();
$handler->shouldReceive('getTransactions')->atLeast()->once()->andReturn(['a' => 'b']);
$routine = new FinTSRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
}

View File

@ -1,243 +0,0 @@
<?php
/**
* SpectreRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\SpectreRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class SpectreRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class SpectreRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunAuthenticated(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR2b' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'authenticated';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageAuthenticatedHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'choose-accounts'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunDoAuthenticate(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR1A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'do-authenticate';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunGoImport(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR3c' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'do_import'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunNewOneLogin(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR4A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageNewHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'choose-login'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getCountLogins')->once()->andReturn(2);
$handler->shouldReceive('run')->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunNewZeroLogins(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR5A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageNewHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'do-authenticate'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('getCountLogins')->once()->andReturn(0);
$handler->shouldReceive('run')->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
}

View File

@ -1,321 +0,0 @@
<?php
/**
* YnabRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\YnabRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Ynab\GetAccountsHandler;
use FireflyIII\Support\Import\Routine\Ynab\ImportDataHandler;
use FireflyIII\Support\Import\Routine\Ynab\StageGetAccessHandler;
use FireflyIII\Support\Import\Routine\Ynab\StageGetBudgetsHandler;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class YnabRoutineTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class YnabRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunBadStatus(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_7_' . $this->randomInt();
$job->status = 'not_ready_to_run';
$job->stage = 'bad_state';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(ImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertEquals('YNAB import routine cannot handle stage "bad_state"', $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunException(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_6_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'bad_state';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(ImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertEquals('YNAB import routine cannot handle stage "bad_state"', $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunGetAccessToken(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_1_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_access_token';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageGetAccessHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'get_budgets'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunGetAccounts(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_4_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_accounts';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(GetAccountsHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'select_accounts'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunGoForImport(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_5_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(ImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'do_import'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunMultiBudgets(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_2_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_budgets';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageGetBudgetsHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$config = ['budgets' => [1, 2, 3]];
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('getConfiguration')->once()->andReturn($config);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'select_budgets'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\YnabRoutine
*/
public function testRunSingleBudget(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_3_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_budgets';
$job->provider = 'ynab';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$handler = $this->mock(StageGetBudgetsHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$config = ['budgets' => [1]];
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('getConfiguration')->once()->andReturn($config);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'get_accounts'])->once();
// mock calls for handler
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$routine = new YnabRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
}

View File

@ -1,190 +0,0 @@
<?php
/**
* AbnAmroDescriptionTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\AbnAmroDescription;
use Log;
use Tests\TestCase;
/**
* Class AbnAmroDescriptionTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AbnAmroDescriptionTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* 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]);
}
}

View File

@ -1,92 +0,0 @@
<?php
/**
* BelfiusTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\Belfius;
use Log;
use Tests\TestCase;
/**
* Class BelfiusTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BelfiusTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Should return the exact same array.
*
* @covers \FireflyIII\Import\Specifics\Belfius
*/
public function testEmptyRow(): void
{
$row = [1, 2, 3, 4];
$parser = new Belfius;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
/**
* Data with recurring transaction.
*
* @covers \FireflyIII\Import\Specifics\Belfius
*/
public function testProcessRecurringTransaction(): void
{
$row = [0, 1, 2, 3, 4, 'Tom Jones', 6, 7, 8, 9, 10, 11, 12, 13,
'DOORLOPENDE OPDRACHT 12345678 NAAR BE01 1234 5678 9012 Tom Jones My Description REF. : 01234567890 VAL. 01-01'];
$parser = new Belfius;
$result = $parser->run($row);
$this->assertEquals('My Description', $result[14]);
}
/**
* Data that cannot be parsed.
*
* @covers \FireflyIII\Import\Specifics\Belfius
*/
public function testProcessUnknown(): void
{
$row = [0, 1, 2, 3, 4, 'STORE BRUSSEL n/v', 6, 7, 8, 9, 10, 11, 12, 13,
'AANKOOP BANCONTACT CONTACTLESS MET KAART NR 01234 5678 9012 3456 - FOO BAR OP 01/01 00:01 STORE BRUSSEL n/v REF. : 01234567890 VAL. 01-01'];
$parser = new Belfius;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
}

View File

@ -1,135 +0,0 @@
<?php
/**
* IngBelgiumTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\IngBelgium;
use Log;
use Tests\TestCase;
/**
* Class IngBelgiumTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class IngBelgiumTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Should return the exact same array.
*
* @covers \FireflyIII\Import\Specifics\IngBelgium
*/
public function testEmptyRow(): void
{
$row = [0, 1, 2, 3, 4];
$parser = new IngBelgium;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
/**
* Data with description and opposing account information.
*
* @covers \FireflyIII\Import\Specifics\IngBelgium
*/
public function testParseDescriptionAndOpposingAccountInformation(): void
{
$row = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
'Europese overschrijving Van: DE H JOHN DOE De Laan 123 1000 BRUSSEL België IBAN: BE01123456789012 Mededeling: A random description ',
10
];
$parser = new IngBelgium;
$result = $parser->run($row);
$this->assertEquals($row, array_slice($result, 0, 11));
$this->assertEquals('DE H JOHN DOE', $result[11]);
$this->assertEquals('BE01123456789012', $result[12]);
$this->assertEquals('A random description', $result[13]);
}
/**
* Data with structured description.
*
* @covers \FireflyIII\Import\Specifics\IngBelgium
*/
public function testParseStructuredDescription(): void
{
$row = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
'Europese overschrijving Mededeling: ***090/9337/55493*** ',
10
];
$parser = new IngBelgium;
$result = $parser->run($row);
$this->assertEquals($row, array_slice($result, 0, 11));
$this->assertEquals('+++090/9337/55493+++', $result[13]);
}
/**
* Empty transaction details
*
* @covers \FireflyIII\Import\Specifics\IngBelgium
*/
public function testEmptyTransactionDetails(): void
{
$row = [0, 1, 2, 3, 4, 5, 6, 7, 8, '', 10];
$parser = new IngBelgium;
$result = $parser->run($row);
$this->assertEquals($row, array_slice($result, 0, 11));
$this->assertEquals('', $result[11]);
$this->assertEquals('', $result[12]);
$this->assertEquals('', $result[13]);
}
}

View File

@ -1,153 +0,0 @@
<?php
/**
* IngDescriptionTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\IngDescription;
use Log;
use Tests\TestCase;
/**
* Class IngDescriptionTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class IngDescriptionTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* 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]);
}
/**
* 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]);
}
/**
* 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]);
}
/**
* 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 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]);
}
/**
* 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]);
}
/**
* @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);
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* PresidentsChoiceTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\PresidentsChoice;
use Log;
use Tests\TestCase;
/**
* Class PresidentsChoiceTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class PresidentsChoiceTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
*/
public function testRunAmount(): void
{
$row = ['', 'Descr', '12.34', '', ''];
$parser = new PresidentsChoice;
$result = $parser->run($row);
$this->assertEquals('-12.340000000000', $result[3]);
$this->assertEquals('Descr', $result[2]);
}
/**
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
*/
public function testRunBasic(): void
{
$row = [''];
$parser = new PresidentsChoice;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
}

View File

@ -1,86 +0,0 @@
<?php
/**
* SnsDescriptionTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\SnsDescription;
use Log;
use Tests\TestCase;
/**
* Class SnsDescriptionTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class SnsDescriptionTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Specifics\SnsDescription
*/
public function testRunBasic(): void
{
$row = ['a', 'b', 'c'];
$parser = new SnsDescription;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
/**
* @covers \FireflyIII\Import\Specifics\SnsDescription
*/
public function testRunNoQuotes(): void
{
$row = ['a', 'b', 'c', 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'Some text'];
$parser = new SnsDescription;
$result = $parser->run($row);
$this->assertEquals($row, $result);
$this->assertEquals('Some text', $result[17]);
}
/**
* @covers \FireflyIII\Import\Specifics\SnsDescription
*/
public function testRunQuotes(): void
{
$row = ['a', 'b', 'c', 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, '\'Some text\''];
$parser = new SnsDescription;
$result = $parser->run($row);
$this->assertEquals('Some text', $result[17]);
}
}

File diff suppressed because it is too large Load Diff