2017-12-28 20:06:16 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AmountDebitTest.php
|
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Unit\Import\Converter;
|
|
|
|
|
|
|
|
use FireflyIII\Import\Converter\AmountDebit;
|
2018-09-04 09:52:19 +02:00
|
|
|
use Log;
|
2017-12-28 20:06:16 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AmountDebitTest
|
|
|
|
*/
|
|
|
|
class AmountDebitTest extends TestCase
|
|
|
|
{
|
2018-09-04 09:52:19 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-09-04 09:52:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-28 20:06:16 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Import\Converter\AmountDebit
|
2017-12-28 20:06:16 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testConvert(): void
|
2017-12-28 20:06:16 +01:00
|
|
|
{
|
|
|
|
$values = [
|
2018-07-01 13:34:57 +02:00
|
|
|
|
2017-12-28 20:06:16 +01:00
|
|
|
'0' => '0',
|
2018-07-01 13:34:57 +02:00
|
|
|
'0.0' => '0.0',
|
2017-12-28 20:06:16 +01:00
|
|
|
'0.1' => '-0.1',
|
|
|
|
'.2' => '-0.2',
|
|
|
|
'0.01' => '-0.01',
|
|
|
|
'1' => '-1',
|
2018-07-01 13:34:57 +02:00
|
|
|
'1.0' => '-1.0',
|
2017-12-28 20:06:16 +01:00
|
|
|
'1.1' => '-1.1',
|
|
|
|
'1.12' => '-1.12',
|
2018-07-01 13:34:57 +02:00
|
|
|
'1.10' => '-1.10',
|
2017-12-28 20:06:16 +01:00
|
|
|
'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',
|
2018-07-01 13:34:57 +02:00
|
|
|
'0,0' => '0.0',
|
2017-12-28 20:06:16 +01:00
|
|
|
'0,1' => '-0.1',
|
|
|
|
',2' => '-0.2',
|
|
|
|
'0,01' => '-0.01',
|
2018-07-01 13:34:57 +02:00
|
|
|
'1,0' => '-1.0',
|
2017-12-28 20:06:16 +01:00
|
|
|
'1,1' => '-1.1',
|
|
|
|
'1,12' => '-1.12',
|
2018-07-01 13:34:57 +02:00
|
|
|
'1,10' => '-1.10',
|
2017-12-28 20:06:16 +01:00
|
|
|
'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
|
2018-07-01 13:34:57 +02:00
|
|
|
'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',
|
2017-12-28 20:06:16 +01:00
|
|
|
'11.444' => '-11.444',
|
2018-07-01 13:34:57 +02:00
|
|
|
'12.4440' => '-12.4440',
|
2017-12-28 20:06:16 +01:00
|
|
|
'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',
|
2018-07-01 13:34:57 +02:00
|
|
|
'22.1636445670069' => '-22.163644567006',
|
2017-12-28 20:06:16 +01:00
|
|
|
// many decimals, mixed, large numbers
|
2018-07-01 13:34:57 +02:00
|
|
|
'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',
|
2017-12-28 20:06:16 +01:00
|
|
|
'635211.444' => '-635211.444',
|
2018-07-01 13:34:57 +02:00
|
|
|
'635212.4440' => '-635212.4440',
|
2017-12-28 20:06:16 +01:00
|
|
|
'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
|
2018-07-01 13:34:57 +02:00
|
|
|
'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',
|
2017-12-28 20:06:16 +01:00
|
|
|
'63,5211.444' => '-635211.444',
|
2018-07-01 13:34:57 +02:00
|
|
|
'63 5212.4440' => '-635212.4440',
|
2017-12-28 20:06:16 +01:00
|
|
|
'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',
|
2018-07-01 13:34:57 +02:00
|
|
|
'$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',
|
2017-12-28 20:06:16 +01:00
|
|
|
];
|
|
|
|
foreach ($values as $value => $expected) {
|
|
|
|
$converter = new AmountDebit;
|
|
|
|
$result = $converter->convert($value);
|
2018-07-01 13:34:57 +02:00
|
|
|
$this->assertEquals($expected, $result, sprintf('The original value was %s', $value));
|
2017-12-28 20:06:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Import\Converter\AmountDebit
|
2017-12-28 20:06:16 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testConvertNull(): void
|
2017-12-28 20:06:16 +01:00
|
|
|
{
|
|
|
|
$converter = new AmountDebit;
|
|
|
|
$result = $converter->convert(null);
|
|
|
|
$this->assertEquals('0', $result);
|
|
|
|
}
|
|
|
|
}
|