mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Update tests
This commit is contained in:
59
tests/Unit/TransactionRules/Actions/AddTagTest.php
Normal file
59
tests/Unit/TransactionRules/Actions/AddTagTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* AddTagTest.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\Actions;
|
||||
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\TransactionRules\Actions\AddTag;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddTagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Actions\AddTag::__construct
|
||||
* @covers \FireflyIII\TransactionRules\Actions\AddTag::act()
|
||||
*/
|
||||
public function testActExistingTag()
|
||||
{
|
||||
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'housing';
|
||||
$journal = TransactionJournal::find(1);
|
||||
$action = new AddTag($ruleAction);
|
||||
$result = $action->act($journal);
|
||||
$this->assertFalse($result);
|
||||
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Actions\AddTag::act()
|
||||
*/
|
||||
public function testActNoTag()
|
||||
{
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'TestTag-' . rand(1, 1000);
|
||||
$journal = TransactionJournal::find(1);
|
||||
$action = new AddTag($ruleAction);
|
||||
$result = $action->act($journal);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// find newly created tag:
|
||||
$tag = Tag::orderBy('id', 'DESC')->first();
|
||||
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => 1]);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* AppendDescriptionTest.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\Actions;
|
||||
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\TransactionRules\Actions\AppendDescription;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AppendDescriptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\TransactionRules\Actions\AppendDescription::__construct
|
||||
* @covers \FireflyIII\TransactionRules\Actions\AppendDescription::act()
|
||||
*/
|
||||
public function testActExistingTag()
|
||||
{
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'APPEND';
|
||||
|
||||
$journal = TransactionJournal::find(1);
|
||||
$oldDescription = $journal->description;
|
||||
$action = new AppendDescription($ruleAction);
|
||||
$result = $action->act($journal);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$journal = TransactionJournal::find(1);
|
||||
$this->assertEquals($oldDescription . 'APPEND', $journal->description);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user