New tests.

This commit is contained in:
James Cole 2017-10-06 15:41:21 +02:00
parent 29e02ce31f
commit 67ed6e14aa
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
54 changed files with 3201 additions and 54 deletions

View File

@ -47,6 +47,7 @@ class Kernel extends ConsoleKernel
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/

View File

@ -23,6 +23,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
@ -128,8 +129,15 @@ class SingleController extends Controller
'payment_date' => $journal->getMeta('payment_date'),
'invoice_date' => $journal->getMeta('invoice_date'),
'internal_reference' => $journal->getMeta('internal_reference'),
'notes' => $journal->getMeta('notes'),
'notes' => '',
];
/** @var Note $note */
$note = $journal->notes()->first();
if (!is_null($note)) {
$preFilled['notes'] = $note->text;
}
Session::flash('preFilled', $preFilled);
return redirect(route('transactions.create', [strtolower($journal->transactionType->type)]));
@ -270,7 +278,7 @@ class SingleController extends Controller
'payment_date' => $journal->dateAsString('payment_date'),
'invoice_date' => $journal->dateAsString('invoice_date'),
'interal_reference' => $journal->getMeta('internal_reference'),
'notes' => $journal->getMeta('notes'),
'notes' => '',
// amount fields
'amount' => $pTransaction->amount,
@ -283,6 +291,11 @@ class SingleController extends Controller
'foreign_currency' => $foreignCurrency,
'destination_currency' => $foreignCurrency,
];
/** @var Note $note */
$note = $journal->notes()->first();
if (!is_null($note)) {
$preFilled['notes'] = $note->text;
}
// amounts for withdrawals and deposits:
// amount, native_amount, source_amount, destination_amount

View File

@ -20,9 +20,10 @@ use FireflyIII\TransactionRules\Actions\ActionInterface;
use Log;
/**
* Interface ActionInterface
* @codeCoverageIgnore
* Class ActionFactory
*
* @package FireflyIII\TransactionRules\Actions
* @package FireflyIII\TransactionRules\Factory
*/
class ActionFactory
{

View File

@ -21,6 +21,7 @@ use FireflyIII\TransactionRules\Triggers\TriggerInterface;
use Log;
/**
* @codeCoverageIgnore
* Interface TriggerInterface
*
* @package FireflyIII\TransactionRules\Triggers

View File

@ -38,6 +38,7 @@ class AbstractTrigger
/**
* AbstractTrigger constructor.
* @codeCoverageIgnore
*/
private function __construct()
{
@ -45,6 +46,7 @@ class AbstractTrigger
}
/**
* @codeCoverageIgnore
* @param string $triggerValue
* @param bool $stopProcessing
*
@ -60,6 +62,7 @@ class AbstractTrigger
}
/**
* @codeCoverageIgnore
* @param RuleTrigger $trigger
*
* @return AbstractTrigger
@ -74,21 +77,8 @@ class AbstractTrigger
return $self;
}
/**
* @param RuleTrigger $trigger
* @param TransactionJournal $journal
*/
public static function makeFromTriggerAndJournal(RuleTrigger $trigger, TransactionJournal $journal)
{
$self = new static;
$self->trigger = $trigger;
$self->triggerValue = $trigger->trigger_value;
$self->stopProcessing = $trigger->stop_processing;
$self->journal = $journal;
}
/**
* @codeCoverageIgnore
* @param string $triggerValue
*
* @return AbstractTrigger
@ -102,6 +92,7 @@ class AbstractTrigger
}
/**
* @codeCoverageIgnore
* @return RuleTrigger
*/
public function getTrigger(): RuleTrigger
@ -110,6 +101,7 @@ class AbstractTrigger
}
/**
* @codeCoverageIgnore
* @return string
*/
public function getTriggerValue(): string

View File

@ -66,10 +66,8 @@ final class DescriptionContains extends AbstractTrigger implements TriggerInterf
{
$search = strtolower($this->triggerValue);
$source = strtolower($journal->description ?? '');
$strpos = strpos($source, $search);
$strpos = stripos($source, $search);
if (!($strpos === false)) {
Log::debug(sprintf('RuleTrigger DescriptionContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $source, $search));
return true;

View File

@ -69,10 +69,11 @@ final class DescriptionEnds extends AbstractTrigger implements TriggerInterface
$searchLength = strlen($search);
// if the string to search for is longer than the description,
// shorten the search string.
// return false.
if ($searchLength > $descriptionLength) {
$search = substr($search, ($descriptionLength * -1));
$searchLength = strlen($search);
Log::debug(sprintf('RuleTrigger DescriptionEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $description, $search));
return false;
}
$part = substr($description, $searchLength * -1);

View File

@ -44,7 +44,12 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
return false;
$res = strval($value) === '';
if ($res === true) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
return $res;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -57,6 +58,20 @@ final class HasAnyBudget extends AbstractTrigger implements TriggerInterface
return true;
}
// perhaps transactions have budget?
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
$count = $transaction->budgets()->count();
if ($count > 0) {
Log::debug(
sprintf('RuleTrigger HasAnyBudget for journal #%d (transaction #%d): count is %d, return true.', $journal->id, $transaction->id, $count)
);
return true;
}
}
Log::debug(sprintf('RuleTrigger HasAnyBudget for journal #%d: count is %d, return false.', $journal->id, $count));
return false;

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -57,6 +58,20 @@ final class HasAnyCategory extends AbstractTrigger implements TriggerInterface
return true;
}
// perhaps transactions have category?
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
$count = $transaction->categories()->count();
if ($count > 0) {
Log::debug(
sprintf('RuleTrigger HasAnyCategory for journal #%d (transaction #%d): count is %d, return true.', $journal->id, $transaction->id, $count)
);
return true;
}
}
Log::debug(sprintf('RuleTrigger HasAnyCategory for journal #%d: count is %d, return false.', $journal->id, $count));
return false;

View File

@ -13,6 +13,7 @@ namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
class HasAttachment extends AbstractTrigger implements TriggerInterface
{
@ -50,11 +51,18 @@ class HasAttachment extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$minimum = intval($this->triggerValue);
$minimum = intval($this->triggerValue);
$attachments = $journal->attachments()->count();
if ($attachments >= $minimum) {
Log::debug(
sprintf(
'RuleTrigger HasAttachment for journal #%d: count is %d, is more than or equal to %d, return true.', $journal->id, $attachments, $minimum
)
);
return true;
}
Log::debug(sprintf('RuleTrigger HasAttachment for journal #%d: count is %d, is less than %d, return true.', $journal->id, $attachments, $minimum));
return false;
}

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -52,11 +53,18 @@ final class HasNoBudget extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->budgets()->count();
// perhaps transactions have budget?
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
$count += $transaction->budgets()->count();
}
if ($count === 0) {
Log::debug(sprintf('RuleTrigger HasNoBudget for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasNoBudget for journal #%d: count is %d, return false.', $journal->id, $count));
return false;

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -52,6 +53,13 @@ final class HasNoCategory extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->categories()->count();
// perhaps transactions have category?
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
$count += $transaction->categories()->count();
}
if ($count === 0) {
Log::debug(sprintf('RuleTrigger HasNoCategory for journal #%d: count is %d, return true.', $journal->id, $count));

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -51,9 +52,14 @@ final class NotesAny extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$notes = $journal->getMeta('notes') ?? '';
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = $note->text;
}
if (strlen($notes) > 0) {
if (strlen($text) > 0) {
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen > 0, return true.', $journal->id));

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -57,17 +58,22 @@ final class NotesAre extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$notes = strtolower($journal->getMeta('notes') ?? '');
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = strtolower($note->text);
}
$search = strtolower($this->triggerValue);
if ($notes === $search) {
if ($text === $search && strlen($text) > 0) {
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is "%s", return true.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is "%s", return true.', $journal->id, $text, $search));
return true;
}
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is NOT "%s", return false.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is NOT "%s", return false.', $journal->id, $text, $search));
return false;
}

View File

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -63,18 +64,31 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$search = strtolower($this->triggerValue);
$notes = strtolower($journal->getMeta('notes') ?? '');
$search = trim(strtolower($this->triggerValue));
$strpos = strpos($notes, $search);
if (strlen($search) === 0) {
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" is empty, return false.', $journal->id, $search));
return false;
}
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = strtolower($note->text);
}
$strpos = strpos($text, $search);
if (!($strpos === false)) {
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" contains "%s", return true.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" contains "%s", return true.', $journal->id, $text, $search));
return true;
}
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" does NOT contain "%s", return false.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" does NOT contain "%s", return false.', $journal->id, $text, $search));
return false;

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -51,9 +52,14 @@ final class NotesEmpty extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$notes = $journal->getMeta('notes') ?? '';
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = $note->text;
}
if (strlen($notes) === 0) {
if (strlen($text) === 0) {
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return true.', $journal->id));

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -62,28 +63,34 @@ final class NotesEnd extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$notes = strtolower($journal->getMeta('notes') ?? '');
$notesLength = strlen($notes);
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = strtolower($note->text);
}
$notesLength = strlen($text);
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);
// if the string to search for is longer than the description,
// shorten the search string.
// return false
if ($searchLength > $notesLength) {
$search = substr($search, ($notesLength * -1));
$searchLength = strlen($search);
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $text, $search));
return false;
}
$part = substr($notes, $searchLength * -1);
$part = substr($text, $searchLength * -1);
if ($part === $search) {
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" ends with "%s", return true.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" ends with "%s", return true.', $journal->id, $text, $search));
return true;
}
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $text, $search));
return false;
}

View File

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -63,18 +64,23 @@ final class NotesStart extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$notes = strtolower($journal->getMeta('notes') ?? '');
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
$text = strtolower($note->text);
}
$search = strtolower($this->triggerValue);
$part = substr($notes, 0, strlen($search));
$part = substr($text, 0, strlen($search));
if ($part === $search) {
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" starts with "%s", return true.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" starts with "%s", return true.', $journal->id, $text, $search));
return true;
}
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $notes, $search));
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $text, $search));
return false;

View File

@ -75,10 +75,11 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
$searchLength = strlen($search);
// if the string to search for is longer than the account name,
// shorten the search string.
// return false
if ($searchLength > $toAccountNameLength) {
$search = substr($search, ($toAccountNameLength * -1));
$searchLength = strlen($search);
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $toAccountName, $search));
return false;
}

View File

@ -37,6 +37,7 @@ final class UserAction extends AbstractTrigger implements TriggerInterface
* false.
*
* @param null $value
* @codeCoverageIgnore
*
* @return bool
*/
@ -49,6 +50,7 @@ final class UserAction extends AbstractTrigger implements TriggerInterface
* This trigger is always triggered, because the rule that it is a part of has been pre-selected on this condition.
*
* @param TransactionJournal $journal
* @codeCoverageIgnore
*
* @return bool
*/

49
phpunit.coverage.xml Normal file
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ phpunit.coverage.xml
~ Copyright (c) 2017 thegrumpydictator@gmail.com
~ This software may be modified and distributed under the terms of the
~ Creative Commons Attribution-ShareAlike 4.0 International License.
~
~ See the LICENSE file for details.
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<file>app/Http/breadcrumbs.php</file>
</exclude>
</whitelist>
<blacklist>
<directory>vendor/</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-clover" target="./storage/build/clover-all.xml" charset="UTF-8"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>

View File

@ -0,0 +1,72 @@
<?php
/**
* AmountExactlyTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\AmountExactly;
use Tests\TestCase;
/**
* Class AmountExactlyTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class AmountExactlyTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountExactly::triggered
*/
public function testTriggeredExact()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.34';
$trigger = AmountExactly::makeFromStrings('12.340', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountExactly::triggered
*/
public function testTriggeredNotExact()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.35';
$trigger = AmountExactly::makeFromStrings('12.340', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountExactly::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = AmountExactly::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountExactly::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = AmountExactly::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* AmountLessTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\AmountLess;
use Tests\TestCase;
/**
* Class AmountLessTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class AmountLessTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountLess::triggered
*/
public function testTriggeredLess()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.34';
$trigger = AmountLess::makeFromStrings('12.50', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountLess::triggered
*/
public function testTriggeredExact()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.35';
$trigger = AmountLess::makeFromStrings('12.35', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountLess::triggered
*/
public function testTriggeredNotLess()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.35';
$trigger = AmountLess::makeFromStrings('12.00', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountLess::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = AmountLess::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountLess::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = AmountLess::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* AmountMoreTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\AmountMore;
use Tests\TestCase;
/**
* Class AmountMoreTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class AmountMoreTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::triggered
*/
public function testTriggeredExact()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.35';
$trigger = AmountMore::makeFromStrings('12.35', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::triggered
*/
public function testTriggeredMore()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.34';
$trigger = AmountMore::makeFromStrings('12.10', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::triggered
*/
public function testTriggeredNotMore()
{
$journal = new TransactionJournal;
$journal->destination_amount = '12.35';
$trigger = AmountMore::makeFromStrings('12.50', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = '1';
$result = AmountMore::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = AmountMore::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\AmountMore::willMatchEverything
*/
public function testWillMatchEverythingZero()
{
$value = '0';
$result = AmountMore::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* BudgetIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\BudgetIs;
use Tests\TestCase;
/**
* Class BudgetIsTest
*
* @package Unit\TransactionRules\Triggers
*/
class BudgetIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\BudgetIs::triggered
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$trigger = BudgetIs::makeFromStrings($budget->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\BudgetIs::triggered
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$budget = $journal->user->budgets()->first();
$otherBudget = $journal->user->budgets()->where('id', '!=', $budget->id)->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$trigger = BudgetIs::makeFromStrings($otherBudget->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\BudgetIs::triggered
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$transaction->budgets()->save($budget);
$this->assertEquals(0, $journal->budgets()->count());
$this->assertEquals(1, $transaction->budgets()->count());
$trigger = BudgetIs::makeFromStrings($budget->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\BudgetIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = BudgetIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\BudgetIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = BudgetIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* CategoryIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\CategoryIs;
use Tests\TestCase;
/**
* Class CategoryIsTest
*
* @package Unit\TransactionRules\Triggers
*/
class CategoryIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\CategoryIs::triggered
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\CategoryIs::triggered
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$category = $journal->user->categories()->first();
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\CategoryIs::triggered
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\CategoryIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = CategoryIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\CategoryIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = CategoryIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* DescriptionContains.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\DescriptionContains;
use Tests\TestCase;
/**
* Class DescriptionContains
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class DescriptionContainsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::triggered
*/
public function testTriggeredCase()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUM bla bla ';
$trigger = DescriptionContains::makeFromStrings('ipsum', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::triggered
*/
public function testTriggeredNot()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUM bla bla ';
$trigger = DescriptionContains::makeFromStrings('blurb', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::triggered
*/
public function testTriggeredDefault()
{
$journal = new TransactionJournal;
$journal->description = 'Should contain test string';
$trigger = DescriptionContains::makeFromStrings('cont', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::triggered
*/
public function testTriggeredEnd()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionContains::makeFromStrings('pen', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::triggered
*/
public function testTriggeredStart()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionContains::makeFromStrings('somet', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = DescriptionContains::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = DescriptionContains::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = DescriptionContains::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* DescriptionEndsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\DescriptionEnds;
use Tests\TestCase;
/**
* Class DescriptionEnds
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class DescriptionEndsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredCase()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUMbla';
$trigger = DescriptionEnds::makeFromStrings('umbla', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredNot()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUM blabla';
$trigger = DescriptionEnds::makeFromStrings('lorem', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredDefault()
{
$journal = new TransactionJournal;
$journal->description = 'Should contain test string';
$trigger = DescriptionEnds::makeFromStrings('string', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredClose()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionEnds::makeFromStrings('happe', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredLonger()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionEnds::makeFromStrings('xhappen', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::triggered
*/
public function testTriggeredLongSearch()
{
$journal = new TransactionJournal;
$journal->description = 'Something';
$trigger = DescriptionEnds::makeFromStrings('Something is', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = DescriptionEnds::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = DescriptionEnds::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = DescriptionEnds::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* DescriptionIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\DescriptionIs;
use Tests\TestCase;
/**
* Class DescriptionIs
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class DescriptionIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::triggered
*/
public function testTriggeredCase()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUMbla';
$trigger = DescriptionIs::makeFromStrings('lorem ipsumbla', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::triggered
*/
public function testTriggeredNot()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUM blabla';
$trigger = DescriptionIs::makeFromStrings('lorem', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::triggered
*/
public function testTriggeredDefault()
{
$journal = new TransactionJournal;
$journal->description = 'Should be test string';
$trigger = DescriptionIs::makeFromStrings('Should be test string', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::triggered
*/
public function testTriggeredClose()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionIs::makeFromStrings('Something is going to happe', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = DescriptionIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = DescriptionIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* DescriptionStartsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\DescriptionStarts;
use Tests\TestCase;
/**
* Class DescriptionStarts
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class DescriptionStartsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::triggered
*/
public function testTriggeredCase()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUMbla';
$trigger = DescriptionStarts::makeFromStrings('lorem', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::triggered
*/
public function testTriggeredNot()
{
$journal = new TransactionJournal;
$journal->description = 'Lorem IPSUM blabla';
$trigger = DescriptionStarts::makeFromStrings('blabla', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::triggered
*/
public function testTriggeredDefault()
{
$journal = new TransactionJournal;
$journal->description = 'Should contain test string';
$trigger = DescriptionStarts::makeFromStrings('Should', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::triggered
*/
public function testTriggeredClose()
{
$journal = new TransactionJournal;
$journal->description = 'Something is going to happen';
$trigger = DescriptionStarts::makeFromStrings('omething', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::triggered
*/
public function testTriggeredLongSearch()
{
$journal = new TransactionJournal;
$journal->description = 'Something';
$trigger = DescriptionStarts::makeFromStrings('Something is', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = DescriptionStarts::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = DescriptionStarts::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = DescriptionStarts::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* FromAccountContainsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\FromAccountContains;
use Tests\TestCase;
/**
* Class FromAccountContainsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class FromAccountContainsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(20);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountContains::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(21);
$trigger = FromAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = FromAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = FromAccountContains::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = FromAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* FromAccountEndsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
use Tests\TestCase;
/**
* Class FromAccountEndsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class FromAccountEndsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$trigger = FromAccountEnds::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = FromAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = FromAccountEnds::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = FromAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* FromAccountIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
use Tests\TestCase;
/**
* Class FromAccountIsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class FromAccountIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountIs::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$trigger = FromAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = FromAccountIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = FromAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = FromAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* FromAccountStartsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
use Tests\TestCase;
/**
* Class FromAccountStartsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class FromAccountStartsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountStarts::makeFromStrings(substr($account->name,0, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$trigger = FromAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* HasAnyBudgetTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasAnyBudget;
use Tests\TestCase;
/**
* Class HasAnyBudgetTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class HasAnyBudgetTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget::triggered
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
// append to transaction
foreach ($journal->transactions()->get() as $index => $transaction) {
$transaction->budgets()->detach();
if ($index === 0) {
$transaction->budgets()->save($budget);
}
}
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget::willMatchEverything
*/
public function testWillMatchEverything()
{
$value = '';
$result = HasAnyBudget::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* HasAnyCategoryTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasAnyCategory;
use Tests\TestCase;
/**
* Class HasAnyCategoryTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class HasAnyCategoryTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$trigger = HasAnyCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
$trigger = HasAnyCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory::triggered
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
// append to transaction
foreach ($journal->transactions()->get() as $index => $transaction) {
$transaction->categories()->detach();
if ($index === 0) {
$transaction->categories()->save($category);
}
}
$trigger = HasAnyCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory::willMatchEverything
*/
public function testWillMatchEverything()
{
$value = '';
$result = HasAnyCategory::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasAnyTagTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasAnyTag;
use Tests\TestCase;
/**
* Class HasAnyTagTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class HasAnyTagTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);
$this->assertEquals(1, $journal->tags()->count());
$trigger = HasAnyTag::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
$trigger = HasAnyTag::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag::willMatchEverything
*/
public function testWillMatchEverything()
{
$value = '';
$result = HasAnyTag::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* HasAttachment.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasAttachment;
use Tests\TestCase;
/**
* Class HasAttachmentTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class HasAttachmentTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAttachment::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(26);
$attachment = $journal->user->attachments()->first();
$journal->attachments()->save($attachment);
$this->assertEquals(1, $journal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAttachment::triggered
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(27);
$this->assertEquals(0, $journal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAttachment::willMatchEverything
*/
public function testWillMatchEverything()
{
$value = '5';
$result = HasAttachment::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasAttachment::willMatchEverything
*/
public function testWillMatchEverythingTrue()
{
$value = -1;
$result = HasAttachment::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* HasNoBudgetTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasNoBudget;
use Tests\TestCase;
/**
* Class HasNoBudgetTest
*
* @package Unit\TransactionRules\Triggers
*/
class HasNoBudgetTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget::triggered
*/
public function testTriggeredBudget()
{
$journal = TransactionJournal::find(28);
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$trigger = HasNoBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget::triggered
*/
public function testTriggeredNoBudget()
{
$journal = TransactionJournal::find(29);
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$trigger = HasNoBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget::triggered
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(30);
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$transaction->budgets()->save($budget);
$this->assertEquals(0, $journal->budgets()->count());
$this->assertEquals(1, $transaction->budgets()->count());
$trigger = HasNoBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = HasNoBudget::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* HasNoCategoryTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasNoCategory;
use Tests\TestCase;
/**
* Class HasNoCategoryTest
*
* @package Unit\TransactionRules\Triggers
*/
class HasNoCategoryTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory::triggered
*/
public function testTriggeredCategory()
{
$journal = TransactionJournal::find(31);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$trigger = HasNoCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory::triggered
*/
public function testTriggeredNoCategory()
{
$journal = TransactionJournal::find(32);
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
$trigger = HasNoCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory::triggered
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(33);
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());
$trigger = HasNoCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = HasNoCategory::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* HasNoTagTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\HasNoTag;
use Tests\TestCase;
/**
* Class HasNoTagTest
*
* @package Unit\TransactionRules\Triggers
*/
class HasNoTagTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoTag::triggered
*/
public function testTriggeredNoTag()
{
$journal = TransactionJournal::find(34);
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
$trigger = HasNoTag::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoTag::triggered
*/
public function testTriggeredTag()
{
$journal = TransactionJournal::find(35);
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);
$this->assertEquals(1, $journal->tags()->count());
$trigger = HasNoTag::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\HasNoTag::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = HasNoTag::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* NotesAnyTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesAny;
use Tests\TestCase;
/**
* Class NotesAnyTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesAnyTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAny::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(36);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Bla bla bla';
$note->save();
$trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAny::triggered
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(37);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = '';
$note->save();
$trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAny::triggered
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(38);
$journal->notes()->delete();
$trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAny::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = NotesAny::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* NotesAreTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesAre;
use Tests\TestCase;
/**
* Class NotesAreTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesAreTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(39);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Bla bla bla';
$note->save();
$trigger = NotesAre::makeFromStrings('Bla bla bla', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::triggered
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(40);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = '';
$note->save();
$trigger = NotesAre::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::triggered
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(41);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Some note';
$note->save();
$trigger = NotesAre::makeFromStrings('Not the note', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::triggered
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(42);
$journal->notes()->delete();
$trigger = NotesAre::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = NotesAre::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesAre::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = NotesAre::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,135 @@
<?php
/**
* NotesContainTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesContain;
use Tests\TestCase;
/**
* Class NotesContainTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesContainTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(43);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Bla bliepbla bla';
$note->save();
$trigger = NotesContain::makeFromStrings('blIEp', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::triggered
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(44);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = '';
$note->save();
$trigger = NotesContain::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::triggered
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(45);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Some note';
$note->save();
$trigger = NotesContain::makeFromStrings('Some note contains', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::triggered
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(46);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Some note';
$note->save();
$trigger = NotesContain::makeFromStrings('82991911', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::triggered
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(47);
$journal->notes()->delete();
$trigger = NotesContain::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = NotesContain::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = NotesContain::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesContain::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = NotesContain::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* NotesEmptyTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesEmpty;
use Tests\TestCase;
/**
* Class NotesEmptyTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesEmptyTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(48);
$journal->notes()->delete();
$trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty::triggered
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(49);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = '';
$note->save();
$trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty::triggered
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(50);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Some note';
$note->save();
$trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = NotesEmpty::willMatchEverything($value);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* NotesEndTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesEnd;
use Tests\TestCase;
/**
* Class NotesEndTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesEndTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(51);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Bla bliepblabla';
$note->save();
$trigger = NotesEnd::makeFromStrings('blaBla', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(53);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'blabla';
$note->save();
$trigger = NotesEnd::makeFromStrings('Blablabla', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::triggered
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(52);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'blabla';
$note->save();
$trigger = NotesEnd::makeFromStrings('12345', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = NotesEnd::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = NotesEnd::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesEnd::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = NotesEnd::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* NotesStartTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\NotesStart;
use Tests\TestCase;
/**
* Class NotesStartTest
*
* @package Unit\TransactionRules\Triggers
*/
class NotesStartTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(54);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'Blabliepblabla';
$note->save();
$trigger = NotesStart::makeFromStrings('blaBlie', false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(55);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'blabla';
$note->save();
$trigger = NotesStart::makeFromStrings('Blablabla', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::triggered
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(56);
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
$note->text = 'blabla';
$note->save();
$trigger = NotesStart::makeFromStrings('12345', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = NotesStart::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = NotesStart::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\NotesStart::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = NotesStart::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* TagIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\TagIs;
use Tests\TestCase;
/**
* Class TagIsTest
*
* @package Unit\TransactionRules\Triggers
*/
class TagIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\TagIs::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(57);
$journal->tags()->detach();
$tags = $journal->user->tags()->take(3)->get();
$search = '';
foreach ($tags as $index => $tag) {
$journal->tags()->save($tag);
if ($index === 1) {
$search = $tag->tag;
}
}
$this->assertEquals(3, $journal->tags()->count());
$trigger = TagIs::makeFromStrings($search, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TagIs::triggered
*/
public function testNotTriggered()
{
$journal = TransactionJournal::find(58);
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
$trigger = TagIs::makeFromStrings('SomeTag', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TagIs::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = TagIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TagIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = TagIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TagIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = TagIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* ToAccountContainsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\ToAccountContains;
use Tests\TestCase;
/**
* Class ToAccountContainsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class ToAccountContainsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(59);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountContains::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(60);
$trigger = ToAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = ToAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = ToAccountContains::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = ToAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* ToAccountEndsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
use Tests\TestCase;
/**
* Class ToAccountEndsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class ToAccountEndsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(61);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(62);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(63);
$trigger = ToAccountEnds::makeFromStrings(strval(rand(1, 234)), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = ToAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = ToAccountEnds::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = ToAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* ToAccountIsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
use Tests\TestCase;
/**
* Class ToAccountIsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class ToAccountIsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(64);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountIs::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(65);
$trigger = ToAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = ToAccountIs::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = ToAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = ToAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* ToAccountStartsTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
use Tests\TestCase;
/**
* Class ToAccountStartsTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class ToAccountStartsTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(66);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountStarts::makeFromStrings(substr($account->name,0, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::triggered
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(67);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::triggered
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(68);
$trigger = ToAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingEmpty()
{
$value = '';
$result = ToAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = ToAccountStarts::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = ToAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* TransactionTypeTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\TransactionType;
use Tests\TestCase;
/**
* Class TransactionTypeTest
*
* @package Tests\Unit\TransactionRules\Triggers
*/
class TransactionTypeTest extends TestCase
{
/**
* @covers \FireflyIII\TransactionRules\Triggers\TransactionType::triggered
*/
public function testTriggered()
{
$journal = TransactionJournal::find(69);
$type = $journal->transactionType->type;
$trigger = TransactionType::makeFromStrings($type, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TransactionType::triggered
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(70);
$trigger = TransactionType::makeFromStrings('NonExisting', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TransactionType::willMatchEverything
*/
public function testWillMatchEverythingNotNull()
{
$value = 'x';
$result = TransactionType::willMatchEverything($value);
$this->assertFalse($result);
}
/**
* @covers \FireflyIII\TransactionRules\Triggers\TransactionType::willMatchEverything
*/
public function testWillMatchEverythingNull()
{
$value = null;
$result = TransactionType::willMatchEverything($value);
$this->assertTrue($result);
}
}