mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix and expand tests for #2723
This commit is contained in:
@@ -46,8 +46,7 @@ class FromAccountContainsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountContains::makeFromStrings($account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -64,8 +63,7 @@ class FromAccountContainsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -45,8 +45,7 @@ class FromAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -63,8 +62,7 @@ class FromAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -81,8 +79,7 @@ class FromAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -46,8 +46,7 @@ class FromAccountIsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
|
||||
$trigger = FromAccountIs::makeFromStrings($account->name, false);
|
||||
@@ -65,8 +64,7 @@ class FromAccountIsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* FromAccountNumberContainsTest.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\TransactionRules\Triggers;
|
||||
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountNumberContains;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FromAccountNumberContainsTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class FromAccountNumberContainsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testTriggeredBoth(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
|
||||
$account->iban = 'FR7620041010053537027625181';
|
||||
$account->save();
|
||||
$meta = new AccountMeta;
|
||||
$meta->account_id = $account->id;
|
||||
$meta->name = 'account_number';
|
||||
$meta->data= '7027625181';
|
||||
$meta->save();
|
||||
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountNumberContains::makeFromStrings('7027', false);
|
||||
$result = $trigger->triggered($journal);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$meta->forceDelete();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testTriggeredIban(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$account->iban = 'FR7620041010053537027625181';
|
||||
$account->save();
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountNumberContains::makeFromStrings('7027', false);
|
||||
$result = $trigger->triggered($journal);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testTriggeredNumber(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$meta = new AccountMeta;
|
||||
$meta->account_id = $account->id;
|
||||
$meta->name = 'account_number';
|
||||
$meta->data= '7027625181';
|
||||
$meta->save();
|
||||
|
||||
$trigger = FromAccountNumberContains::makeFromStrings('276251', false);
|
||||
$result = $trigger->triggered($journal);
|
||||
$this->assertTrue($result);
|
||||
$meta->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testWillMatchEverythingEmpty(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = '';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testWillMatchEverythingNotNull(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = 'x';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
|
||||
*/
|
||||
public function testWillMatchEverythingNull(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = null;
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
@@ -57,8 +57,7 @@ class FromAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -76,8 +75,7 @@ class FromAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -95,8 +93,7 @@ class FromAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -46,8 +46,7 @@ class ToAccountContainsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
|
||||
$trigger = ToAccountContains::makeFromStrings($account->name, false);
|
||||
@@ -65,8 +64,7 @@ class ToAccountContainsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
|
||||
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
|
@@ -46,8 +46,7 @@ class ToAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -64,8 +63,7 @@ class ToAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -82,8 +80,7 @@ class ToAccountEndsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings((string)$this->randomInt(), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -46,8 +46,7 @@ class ToAccountIsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings($account->name, false);
|
||||
@@ -65,8 +64,7 @@ class ToAccountIsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -46,8 +46,7 @@ class ToAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
|
||||
@@ -65,8 +64,7 @@ class ToAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -83,8 +81,7 @@ class ToAccountStartsTest extends TestCase
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
$repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
Reference in New Issue
Block a user