2018-10-20 15:50:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* FinTS.php
|
|
|
|
* Copyright (c) 2018 https://github.com/bnw
|
|
|
|
*
|
|
|
|
* 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\Support\FinTS;
|
|
|
|
|
|
|
|
use Fhp\Model\StatementOfAccount\Transaction as FinTSTransaction;
|
|
|
|
use FireflyIII\Support\FinTS\MetadataParser;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2018-10-21 11:08:36 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class MetadataParserTest
|
|
|
|
*/
|
2018-10-20 15:50:53 +02:00
|
|
|
class MetadataParserTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
/** @var MetadataParser */
|
|
|
|
private $metadataParser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
Log::info(sprintf('Now in %s.', \get_class($this)));
|
|
|
|
$this->metadataParser = new MetadataParser();
|
|
|
|
}
|
|
|
|
|
2018-10-21 11:08:36 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
|
|
|
*/
|
|
|
|
public function testDescriptionIsCorrectlyExtractedFromBeginning(): void
|
2018-10-20 15:50:53 +02:00
|
|
|
{
|
|
|
|
$transaction = $this->createTransactionWithDescription1('SVWZ+DescriptionABWA+xxx');
|
|
|
|
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
|
|
|
}
|
|
|
|
|
2018-10-21 11:08:36 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
|
|
|
*/
|
|
|
|
public function testDescriptionIsCorrectlyExtractedFromEnd(): void
|
2018-10-20 15:50:53 +02:00
|
|
|
{
|
2018-10-21 11:08:36 +02:00
|
|
|
$transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+Description');
|
2018-10-20 15:50:53 +02:00
|
|
|
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
|
|
|
}
|
|
|
|
|
2018-10-21 11:08:36 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
|
|
|
*/
|
|
|
|
public function testDescriptionIsCorrectlyExtractedFromMiddle(): void
|
2018-10-20 15:50:53 +02:00
|
|
|
{
|
2018-10-21 11:08:36 +02:00
|
|
|
$transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+DescriptionABWA+Ghi');
|
2018-10-20 15:50:53 +02:00
|
|
|
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
|
|
|
}
|
|
|
|
|
2018-10-21 11:08:36 +02:00
|
|
|
/**
|
|
|
|
* @param string $description1
|
|
|
|
*
|
|
|
|
* @return FinTSTransaction
|
|
|
|
*/
|
|
|
|
private function createTransactionWithDescription1(string $description1): FinTSTransaction
|
2018-10-20 15:50:53 +02:00
|
|
|
{
|
|
|
|
$transaction = $this->mock(FinTSTransaction::class);
|
|
|
|
$transaction->shouldReceive('getDescription1')->atLeast()->once()->andReturn($description1);
|
2018-10-21 11:08:36 +02:00
|
|
|
|
2018-10-20 15:50:53 +02:00
|
|
|
return $transaction;
|
|
|
|
}
|
|
|
|
}
|