. */ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\TransactionRules\Triggers\HasNoCategory; use Tests\TestCase; /** * Class HasNoCategoryTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class HasNoCategoryTest extends TestCase { /** * Set up test */ public function setUp(): void { self::markTestIncomplete('Incomplete for refactor.'); return; } /** * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory */ public function testTriggeredCategory(): void { $journal = $this->getRandomWithdrawal(); $category = $this->getRandomCategory();; $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 */ public function testTriggeredNoCategory(): void { $journal = $this->getRandomWithdrawal(); $journal->categories()->detach(); // also detach transactions: /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { $transaction->categories()->detach(); $this->assertEquals(0, $transaction->categories()->count()); } $this->assertEquals(0, $journal->categories()->count()); $trigger = HasNoCategory::makeFromStrings('', false); $result = $trigger->triggered($journal); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory */ public function testTriggeredTransaction(): void { $withdrawal = $this->getRandomWithdrawal(); $transaction = $withdrawal->transactions()->first(); $category = $withdrawal->user->categories()->first(); $withdrawal->categories()->detach(); $transaction->categories()->sync([$category->id]); $this->assertEquals(0, $withdrawal->categories()->count()); $this->assertEquals(1, $transaction->categories()->count()); $trigger = HasNoCategory::makeFromStrings('', false); $result = $trigger->triggered($withdrawal); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory */ public function testWillMatchEverythingNull(): void { $value = null; $result = HasNoCategory::willMatchEverything($value); $this->assertFalse($result); } }