firefly-iii/tests/Unit/TransactionRules/Actions/SetNotesTest.php

89 lines
3.0 KiB
PHP
Raw Normal View History

2017-10-04 08:27:20 -05:00
<?php
/**
* SetNotesTest.php
2020-02-16 06:59:55 -06:00
* Copyright (c) 2019 james@firefly-iii.org
2017-10-04 08:27:20 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 01:40:00 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 01:40:00 -05:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 01:40:00 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 01:40:00 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-10-04 08:27:20 -05:00
*/
declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\Note;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Actions\SetNotes;
use Tests\TestCase;
/**
* Class SetNotesTest
2019-08-17 03:48:28 -05:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2017-10-04 08:27:20 -05:00
*/
class SetNotesTest extends TestCase
{
/**
2018-08-09 13:17:15 -05:00
* @covers \FireflyIII\TransactionRules\Actions\SetNotes
2017-10-04 08:27:20 -05:00
*/
2018-05-11 12:58:10 -05:00
public function testAct(): void
2017-10-04 08:27:20 -05:00
{
// give journal a note:
2019-07-31 23:21:44 -05:00
$journal = $this->getRandomWithdrawal();
2017-10-04 08:27:20 -05:00
$note = $journal->notes()->first();
2018-04-02 07:17:11 -05:00
if (null === $note) {
2017-10-04 08:27:20 -05:00
$note = new Note;
$note->noteable()->associate($journal);
}
$note->text = 'Hello test note';
$note->save();
$this->assertEquals(1, $journal->notes()->count());
// fire the action:
$ruleAction = new RuleAction;
2019-07-31 23:21:44 -05:00
$ruleAction->action_value = 'These are new notes ' . $this->randomInt();
2017-10-04 08:27:20 -05:00
$action = new SetNotes($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
// assert result
$this->assertEquals(1, $journal->notes()->count());
$this->assertEquals($note->id, $journal->notes()->first()->id);
}
/**
2018-08-09 13:17:15 -05:00
* @covers \FireflyIII\TransactionRules\Actions\SetNotes()
* @covers \FireflyIII\TransactionRules\Actions\SetNotes
2017-10-04 08:27:20 -05:00
*/
2018-05-11 12:58:10 -05:00
public function testActNoNotes(): void
2017-10-04 08:27:20 -05:00
{
// give journal a note:
2019-07-31 23:21:44 -05:00
$journal = $this->getRandomWithdrawal();
2017-10-04 08:27:20 -05:00
$journal->notes()->forceDelete();
$this->assertEquals(0, $journal->notes()->count());
// fire the action:
$ruleAction = new RuleAction;
2019-07-31 23:21:44 -05:00
$ruleAction->action_value = 'These are new notes ' . $this->randomInt();
2017-10-04 08:27:20 -05:00
$action = new SetNotes($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
// assert result
$this->assertEquals(1, $journal->notes()->count());
}
2017-11-08 02:05:10 -06:00
}