mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test coverage.
This commit is contained in:
@@ -36,18 +36,14 @@ class CategoryIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggeredJournal(): void
|
||||
{
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transactions = $journal->transactions()->count();
|
||||
} while ($transactions !== 2);
|
||||
|
||||
$category = $journal->user->categories()->first();
|
||||
$journal->categories()->detach();
|
||||
$journal->categories()->save($category);
|
||||
$this->assertEquals(1, $journal->categories()->count());
|
||||
$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($journal);
|
||||
$result = $trigger->triggered($withdrawal);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
@@ -56,19 +52,15 @@ class CategoryIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggeredNotJournal(): void
|
||||
{
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transactions = $journal->transactions()->count();
|
||||
} while ($transactions !== 2);
|
||||
|
||||
$category = $journal->user->categories()->first();
|
||||
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
|
||||
$journal->categories()->detach();
|
||||
$journal->categories()->save($category);
|
||||
$this->assertEquals(1, $journal->categories()->count());
|
||||
$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($journal);
|
||||
$result = $trigger->triggered($withdrawal);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
@@ -77,22 +69,18 @@ class CategoryIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggeredTransaction(): void
|
||||
{
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transactions = $journal->transactions()->count();
|
||||
} while ($transactions !== 2);
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
$transaction = $withdrawal->transactions()->first();
|
||||
$category = $withdrawal->user->categories()->first();
|
||||
|
||||
$transaction = $journal->transactions()->first();
|
||||
$category = $journal->user->categories()->first();
|
||||
|
||||
$journal->categories()->detach();
|
||||
$withdrawal->categories()->detach();
|
||||
$transaction->categories()->detach();
|
||||
$transaction->categories()->save($category);
|
||||
$this->assertEquals(0, $journal->categories()->count());
|
||||
$this->assertEquals(0, $withdrawal->categories()->count());
|
||||
$this->assertEquals(1, $transaction->categories()->count());
|
||||
|
||||
$trigger = CategoryIs::makeFromStrings($category->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
$result = $trigger->triggered($withdrawal);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user