/** * @covers FireflyIII\Repositories\Tag\TagRepository::coveredByBalancingActs */ public function testCoveredByBalancingActs() { // create a user: $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); // create transaction and account types: FactoryMuffin::create('FireflyIII\\Models\\TransactionType'); // withdrawal FactoryMuffin::create('FireflyIII\\Models\\TransactionType'); // deposit $transfer = FactoryMuffin::create('FireflyIII\\Models\\TransactionType'); // transfer FactoryMuffin::create('FireflyIII\\Models\\AccountType'); // expense FactoryMuffin::create('FireflyIII\\Models\\AccountType'); // revenue $asset = FactoryMuffin::create('FireflyIII\\Models\\AccountType'); // asset // create two accounts: $fromAccount = FactoryMuffin::create('FireflyIII\\Models\\Account'); // asset $toAccount = FactoryMuffin::create('FireflyIII\\Models\\Account'); // asset $fromAccount->account_type_id = $asset->id; $toAccount->account_type_id = $asset->id; $fromAccount->save(); $toAccount->save(); // create a tag $tag = FactoryMuffin::create('FireflyIII\\Models\\Tag'); $tag->tagMode = 'balancingAct'; $tag->user_id = $user->id; $tag->save(); // date $today = new Carbon('2014-01-12'); $start = new Carbon('2014-01-01'); $end = new Carbon('2014-01-31'); // store five journals for ($i = 0; $i < 5; $i++) { $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); // deposit! // set date: $journal->date = $today; $journal->user_id = $user->id; $journal->transaction_type_id = $transfer->id; $journal->tags()->save($tag); $journal->save(); // update accounts: $journal->transactions[0]->account_id = $fromAccount->id; $journal->transactions[0]->amount = '-100'; $journal->transactions[0]->save(); $journal->transactions[1]->account_id = $toAccount->id; $journal->transactions[1]->amount = '100'; $journal->transactions[1]->save(); } $amount = $this->object->coveredByBalancingActs($toAccount, $start, $end); // five transactions, 100 each. $this->assertEquals('500', $amount); }
/** * When the tag has more than 2 transactions connected to it, it cannot become abalancing act. * * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing */ public function testTagAllowBalancingManyJournals() { // create a tag $user = FactoryMuffin::create('FireflyIII\\User'); $tag = FactoryMuffin::create('FireflyIII\\Models\\Tag'); $tag->tagMode = 'nothing'; $tag->user_id = $user->id; $tag->save(); // create three journals and connect them: for ($i = 0; $i < 3; $i++) { $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); $journal->tags()->save($tag); } $result = $this->object->tagAllowBalancing($tag); $this->assertFalse($result); }