Exemplo n.º 1
0
 /**
  * @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);
 }
 /**
  * Multiple tags, withdrawal, and one is a balancingAct.
  *
  * @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
  * @covers FireflyIII\Models\TransactionJournal::amountByTag
  * @covers FireflyIII\Models\TransactionJournal::amountByTags
  */
 public function testGetAmountAttributeTagsWithdrawalAdvance()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     // has two normal tags:
     $tag = FactoryMuffin::create('FireflyIII\\Models\\Tag');
     $tag->tagMode = 'balancingAct';
     $tag->save();
     $tag2 = FactoryMuffin::create('FireflyIII\\Models\\Tag');
     $tag2->tagMode = 'nothing';
     $tag2->save();
     // make withdrawal
     $withdrawalType = FactoryMuffin::create('FireflyIII\\Models\\TransactionType');
     $withdrawal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal');
     $withdrawal->transaction_type_id = $withdrawalType->id;
     $withdrawal->save();
     // make accounts
     $expense = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $asset = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $withdrawal->transactions[0]->amount = -300;
     $withdrawal->transactions[0]->account_id = $asset->id;
     $withdrawal->transactions[0]->save();
     $withdrawal->transactions[1]->amount = 300;
     $withdrawal->transactions[1]->account_id = $expense->id;
     $withdrawal->transactions[1]->save();
     // connect to tag:
     $tag->transactionJournals()->save($withdrawal);
     $tag2->transactionJournals()->save($withdrawal);
     $withdrawal->save();
     $withdrawal = TransactionJournal::find($withdrawal->id);
     $this->assertEquals('300', $withdrawal->amount);
 }
Exemplo n.º 3
0
 /**
  * @covers FireflyIII\Repositories\Bill\BillRepository::scan
  * @covers FireflyIII\Repositories\Bill\BillRepository::doWordMatch
  * @covers FireflyIII\Repositories\Bill\BillRepository::doAmountMatch
  */
 public function testScanNoMatchButAttached()
 {
     $bill = FactoryMuffin::create('FireflyIII\\Models\\Bill');
     $bill->date = new Carbon('2012-01-07');
     $bill->match = 'blablabla';
     $bill->repeat_freq = 'monthly';
     $bill->save();
     $this->be($bill->user);
     // journal:
     $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal');
     $journal->date = Carbon::now()->format('Y-m-d');
     $journal->user_id = $bill->user_id;
     $journal->bill_id = $bill->id;
     $journal->save();
     // two transactions:
     $account1 = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $account2 = FactoryMuffin::create('FireflyIII\\Models\\Account');
     Transaction::create(['account_id' => $account1->id, 'transaction_journal_id' => $journal->id, 'amount' => 100]);
     Transaction::create(['account_id' => $account2->id, 'transaction_journal_id' => $journal->id, 'amount' => 100]);
     $this->object->scan($bill, $journal);
     $newJournal = TransactionJournal::find($journal->id);
     $this->assertNull($newJournal->bill_id);
 }