. */ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\TransactionRules\Triggers\CategoryIs; use Tests\TestCase; /** * Class CategoryIsTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class CategoryIsTest extends TestCase { /** * Set up test */ public function setUp(): void { self::markTestIncomplete('Incomplete for refactor.'); return; } /** * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs */ public function testTriggeredJournal(): void { $withdrawal = $this->getRandomWithdrawal(); $category = $withdrawal->user->categories()->first(); $withdrawal->categories()->detach(); $withdrawal->categories()->save($category); $this->assertEquals(1, $withdrawal->categories()->count()); $trigger = CategoryIs::makeFromStrings($category->name, false); $result = $trigger->triggered($withdrawal); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs */ public function testTriggeredNotJournal(): void { $withdrawal = $this->getRandomWithdrawal(); $category = $withdrawal->user->categories()->first(); $otherCategory = $withdrawal->user->categories()->where('id', '!=', $category->id)->first(); $withdrawal->categories()->detach(); $withdrawal->categories()->save($category); $this->assertEquals(1, $withdrawal->categories()->count()); $trigger = CategoryIs::makeFromStrings($otherCategory->name, false); $result = $trigger->triggered($withdrawal); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs */ public function testTriggeredTransaction(): void { $withdrawal = $this->getRandomWithdrawal(); $transaction = $withdrawal->transactions()->first(); $category = $withdrawal->user->categories()->first(); $withdrawal->categories()->detach(); $transaction->categories()->detach(); $transaction->categories()->save($category); $this->assertEquals(0, $withdrawal->categories()->count()); $this->assertEquals(1, $transaction->categories()->count()); $trigger = CategoryIs::makeFromStrings($category->name, false); $result = $trigger->triggered($withdrawal); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs */ public function testWillMatchEverythingNotNull(): void { $value = 'x'; $result = CategoryIs::willMatchEverything($value); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs */ public function testWillMatchEverythingNull(): void { $value = null; $result = CategoryIs::willMatchEverything($value); $this->assertTrue($result); } }