Skip to content

Firefly III: a personal finances manager

Fixed some tests.

James Colebf2a104a4e43
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index d4eccee6d3..f0018f7025 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -159,12 +159,12 @@ class TransactionJournal extends Model
}
}
- if ($this->tag_count === 1) {
+ if (intval($this->tag_count) === 1) {
// get amount for single tag:
$amount = $this->amountByTag($this->tags()->first(), $amount);
}
- if ($this->tag_count > 1) {
+ if (intval($this->tag_count) > 1) {
// get amount for either tag.
$amount = $this->amountByTags($amount);
diff --git a/tests/models/AccountModelTest.php b/tests/models/AccountModelTest.php
index 7537c9ea79..662a2a73a2 100644
--- a/tests/models/AccountModelTest.php
+++ b/tests/models/AccountModelTest.php
@@ -137,4 +137,26 @@ class AccountModelTest extends TestCase
}
+ /**
+ * @covers FireflyIII\Models\Account::getNameForEditformAttribute
+ */
+ public function testGetNameForEditformAttribute()
+ {
+ // normal name is normal
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $this->assertEquals($account->name, $account->getNameForEditformAttribute());
+ }
+ /**
+ * @covers FireflyIII\Models\Account::getNameForEditformAttribute
+ */
+ public function testGetNameForEditformAttributeCash()
+ {
+ FactoryMuffin::create('FireflyIII\Models\AccountType');
+ FactoryMuffin::create('FireflyIII\Models\AccountType');
+ FactoryMuffin::create('FireflyIII\Models\AccountType');
+ // cash name is empty
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $this->assertEquals('', $account->getNameForEditformAttribute());
+ }
+
}
diff --git a/tests/models/TagModelTest.php b/tests/models/TagModelTest.php
index c0d7db2afa..b4411d1eb1 100644
--- a/tests/models/TagModelTest.php
+++ b/tests/models/TagModelTest.php
@@ -1,6 +1,7 @@
<?php
use FireflyIII\Models\Tag;
+use FireflyIII\Models\TransactionJournal;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
@@ -74,4 +75,21 @@ class TagModelTest extends TestCase
$this->assertNotEquals($tag->id, $result->id);
}
+ /**
+ * @covers FireflyIII\Models\Tag::save
+ */
+ public function testSave()
+ {
+ $tag = FactoryMuffin::create('FireflyIII\Models\Tag');
+ // connect some transaction journals to the tag:
+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
+ $journal->tags()->save($tag);
+ $tag->save();
+ $journal = TransactionJournal::find($journal->id);
+
+ $this->assertEquals(1, $journal->tag_count);
+
+
+ }
+
}
diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.php
index cc7d59ec92..17d8646557 100644
--- a/tests/models/TransactionJournalModelTest.php
+++ b/tests/models/TransactionJournalModelTest.php
@@ -1,5 +1,6 @@
<?php
+use FireflyIII\Models\TransactionJournal;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
@@ -55,8 +56,11 @@ class TransactionJournalModelTest extends TestCase
}
/**
+ * Journal has one tag.
+ *
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
+ * @covers FireflyIII\Models\TransactionJournal::save
* @covers FireflyIII\Models\TransactionJournal::amountByTags
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
@@ -111,6 +115,8 @@ class TransactionJournalModelTest extends TestCase
$withdrawal->save();
$deposit->save();
+ $withdrawal = TransactionJournal::find($withdrawal->id);
+ $deposit = TransactionJournal::find($deposit->id);
// amount should be 210.12:
$this->assertEquals('210.12', $withdrawal->amount);
@@ -121,6 +127,8 @@ class TransactionJournalModelTest extends TestCase
/**
+ * Journal has one tag.
+ *
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
@@ -179,14 +187,18 @@ class TransactionJournalModelTest extends TestCase
$transfer->transactions[1]->save();
$withdrawal->save();
- $amount = $withdrawal->amount;
+ $withdrawal = TransactionJournal::find($withdrawal->id);
+
+ $amount = $withdrawal->amount;
$this->assertEquals('0', $amount);
}
/**
+ * Journal has no tags.
+ *
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
@@ -208,6 +220,9 @@ class TransactionJournalModelTest extends TestCase
}
/**
+ *
+ * Journal has one tag.
+ *
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
@@ -244,13 +259,16 @@ class TransactionJournalModelTest extends TestCase
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
+ $withdrawal->save();
+ $withdrawal = TransactionJournal::find($withdrawal->id);
+
$this->assertEquals('300', $withdrawal->amount);
}
/**
- * Multiple tags, withdrawal.
+ * Journal has multiple tags, withdrawal. All default tag.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
@@ -291,6 +309,10 @@ class TransactionJournalModelTest extends TestCase
$tag->transactionJournals()->save($withdrawal);
$tag2->transactionJournals()->save($withdrawal);
+ // grab withdrawal again to update tag count:
+ $withdrawal->save();
+ $withdrawal = TransactionJournal::find($withdrawal->id);
+
$this->assertEquals('300', $withdrawal->amount);
@@ -340,6 +362,9 @@ class TransactionJournalModelTest extends TestCase
$tag->transactionJournals()->save($transfer);
$tag2->transactionJournals()->save($transfer);
+ $transfer->save();
+ $transfer = TransactionJournal::find($transfer->id);
+
$this->assertEquals('300', $transfer->amount);
@@ -389,6 +414,9 @@ class TransactionJournalModelTest extends TestCase
$tag->transactionJournals()->save($transfer);
$tag2->transactionJournals()->save($transfer);
+ $transfer->save();
+ $transfer = TransactionJournal::find($transfer->id);
+
$this->assertEquals('300', $transfer->amount);
@@ -415,8 +443,8 @@ class TransactionJournalModelTest extends TestCase
$tag2->save();
// make withdrawal
- $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
- $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
+ $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
+ $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
@@ -436,6 +464,9 @@ class TransactionJournalModelTest extends TestCase
$tag->transactionJournals()->save($withdrawal);
$tag2->transactionJournals()->save($withdrawal);
+ $withdrawal->save();
+ $withdrawal = TransactionJournal::find($withdrawal->id);
+
$this->assertEquals('300', $withdrawal->amount);