mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update tests
This commit is contained in:
parent
dd9528f531
commit
c000fe4557
@ -61,6 +61,6 @@ class AddTag implements ActionInterface
|
||||
|
||||
Log::debug(sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal->id));
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
@ -44,10 +45,16 @@ class AppendNotes implements ActionInterface
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes');
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
$notes = $dbNote->text;
|
||||
Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $notes));
|
||||
$notes = $notes . $this->action->action_value;
|
||||
$journal->setMeta('notes', $notes);
|
||||
$notes = $notes . $this->action->action_value;
|
||||
$dbNote->text = $notes;
|
||||
$dbNote->save();
|
||||
$journal->save();
|
||||
|
||||
return true;
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
@ -44,10 +45,16 @@ class PrependNotes implements ActionInterface
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes');
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
$notes = $dbNote->text;
|
||||
Log::debug(sprintf('RuleAction PrependNotes prepended "%s" with "%s".', $notes, $this->action->action_value));
|
||||
$notes = $this->action->action_value . $notes;
|
||||
$journal->setMeta('notes', $notes);
|
||||
$notes = $this->action->action_value . $notes;
|
||||
$dbNote->text = $notes;
|
||||
$dbNote->save();
|
||||
$journal->save();
|
||||
|
||||
return true;
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
@ -44,9 +45,14 @@ class SetNotes implements ActionInterface
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$oldNotes = $journal->getMeta('notes');
|
||||
|
||||
$journal->setMeta('notes', $this->action->action_value);
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
$oldNotes = $dbNote->text;
|
||||
$dbNote->text = $this->action->action_value;
|
||||
$dbNote->save();
|
||||
$journal->save();
|
||||
|
||||
Log::debug(sprintf('RuleAction SetNotes changed the notes of journal #%d from "%s" to "%s".', $journal->id, $oldNotes, $this->action->action_value));
|
||||
|
@ -107,6 +107,7 @@ class TagControllerTest extends TestCase
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('count')->andReturn(0);
|
||||
$repository->shouldReceive('tagCloud')->andReturn([]);
|
||||
$repository->shouldReceive('oldestTag')->andReturn(null)->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('tags.index'));
|
||||
@ -137,9 +138,7 @@ class TagControllerTest extends TestCase
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
|
||||
$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
|
||||
|
||||
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf()->once();
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||
|
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user