object = new AccountRepository; parent::setUp(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ public function tearDown() { parent::tearDown(); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::countAccounts * @todo Implement testCountAccounts(). */ public function testCountAccounts() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $type = $account->accountType->type; $this->be($account->user); $this->assertEquals(1, $this->object->countAccounts([$type])); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::destroy */ public function testDestroy() { // create account: $account = FactoryMuffin::create('FireflyIII\Models\Account'); $id = $account->id; $this->be($account->user); $this->object->destroy($account); // cannot find account: $this->assertCount(0, Account::whereId($id)->whereNotNull('deleted_at')->get()); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getAccounts */ public function testGetAccounts() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $type = $account->accountType->type; $this->be($account->user); $this->assertCount(1, $this->object->getAccounts([$type])); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getCreditCards * @todo Implement testGetCreditCards(). */ public function testGetCreditCards() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); // create account meta object: $meta = new AccountMeta; $meta->name = 'accountRole'; $meta->data = 'ccAsset'; $meta->account_id = $account->id; $meta->save(); // meta account type $meta = new AccountMeta; $meta->name = 'ccType'; $meta->data = 'monthlyFull'; $meta->account_id = $account->id; $meta->save(); // login $this->be($account->user); // test! $this->assertCount(1, $this->object->getCreditCards()); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getFirstTransaction * @todo Implement testGetFirstTransaction(). */ public function testGetFirstTransaction() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // two matching transactions: $first = Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal->id, 'amount' => 100, ] ); Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal->id, 'amount' => -100, ] ); // login $this->be($account->user); $oldest = $this->object->getFirstTransaction($journal, $account); $this->assertEquals($oldest->amount, $first->amount); $this->assertEquals($oldest->id, $first->id); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts */ public function testGetFrontpageAccounts() { FactoryMuffin::create('FireflyIII\Models\AccountType'); FactoryMuffin::create('FireflyIII\Models\AccountType'); // making two account types is kind of cheating but it works. $account = FactoryMuffin::create('FireflyIII\Models\Account'); /** @var Preference $preference */ $preference = FactoryMuffin::create('FireflyIII\Models\Preference'); $preference->data = []; $preference->save(); $this->be($account->user); $set = $this->object->getFrontpageAccounts($preference); $this->assertEquals($account->id, $set->first()->id); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts */ public function testGetFrontpageAccountsWithPreference() { FactoryMuffin::create('FireflyIII\Models\AccountType'); FactoryMuffin::create('FireflyIII\Models\AccountType'); // making two account types is kind of cheating but it works. $account = FactoryMuffin::create('FireflyIII\Models\Account'); /** @var Preference $preference */ $preference = FactoryMuffin::create('FireflyIII\Models\Preference'); $preference->data = [$account->id]; $preference->save(); $this->be($account->user); $set = $this->object->getFrontpageAccounts($preference); $this->assertEquals($account->id, $set->first()->id); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageTransactions */ public function testGetFrontpageTransactions() { // three journals /** @var Account $account */ $account = FactoryMuffin::create('FireflyIII\Models\Account'); $journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // three dates (one is out of bounds) $journal1->date = new Carbon('2012-01-02'); $journal1->user_id = $account->user_id; $journal2->date = new Carbon('2012-01-09'); $journal2->user_id = $account->user_id; $journal3->date = new Carbon('2012-02-02'); $journal3->user_id = $account->user_id; // save all $journal1->save(); $journal2->save(); $journal3->save(); // transactions to match the dates (one per journal will do) Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100 ] ); Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100 ] ); Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal3->id, 'amount' => 100 ] ); // be user $this->be($journal1->user); // get set: $set = $this->object->getFrontpageTransactions($account, new Carbon('2012-01-01'), new Carbon('2012-01-31')); // should have two left. $this->assertCount(2, $set); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getJournals */ public function testGetJournals() { $date = new Carbon; // three journals /** @var Account $account */ $account = FactoryMuffin::create('FireflyIII\Models\Account'); $journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // three dates (one is out of bounds) $journal1->date = $date; $journal1->user_id = $account->user_id; $journal2->date = $date; $journal2->user_id = $account->user_id; $journal3->date = $date; $journal3->user_id = $account->user_id; // save all $journal1->save(); $journal2->save(); $journal3->save(); // transactions to match the dates (one per journal will do) Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100 ] ); Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100 ] ); Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal3->id, 'amount' => 100 ] ); // be user $this->be($journal1->user); // get paginator: /** @var LengthAwarePaginator $paginator */ $paginator = $this->object->getJournals($account, 1); // should have three entries: $this->assertEquals(3, $paginator->count()); $this->assertEquals(1, $paginator->currentPage()); $this->assertFalse($paginator->isEmpty()); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getLastActivity */ public function testGetLastActivity() { $date = new Carbon('2012-02-02'); // one journals /** @var Account $account */ $account = FactoryMuffin::create('FireflyIII\Models\Account'); $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal->date = $date; $journal->user_id = $account->user_id; $journal->save(); // transaction to match the date (one will do) Transaction::create( [ 'account_id' => $account->id, 'transaction_journal_id' => $journal->id, 'amount' => 100 ] ); // be user $this->be($journal->user); $latest = $this->object->getLastActivity($account); $this->assertEquals($date->format('Y-m-d'), $latest->format('Y-m-d')); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getLastActivity */ public function testGetLastActivityNoActivity() { $date = new Carbon('2012-02-02'); // one journals /** @var Account $account */ $account = FactoryMuffin::create('FireflyIII\Models\Account'); $this->be($account->user); $latest = $this->object->getLastActivity($account); $this->assertnull($latest); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getPiggyBankAccounts */ public function testGetPiggyBankAccounts() { $date = Carbon::now()->startOfMonth()->addDays(3); /* * Quite the collection of objects for this one. */ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $account = FactoryMuffin::create('FireflyIII\Models\Account'); $piggyBankRepetition = $piggyBank->piggybankRepetitions()->first(); /* * Update id's to match each other: */ $piggyBankRepetition->currentamount = rand(1, 100); $piggyBankRepetition->startdate = $date; $piggyBankRepetition->targetdate = $date; $piggyBank->account_id = $account->id; $piggyBankRepetition->save(); $piggyBank->save(); /* * Put dates in session: */ $this->session(['start' => Carbon::now()->startOfMonth(), 'end' => Carbon::now()->endOfMonth()]); /* * Run method: */ $this->be($account->user); $collection = $this->object->getPiggyBankAccounts(); $this->assertCount(1, $collection); $this->assertEquals($collection->first()->id, $account->id); $this->assertEquals($collection->first()->piggyBalance, $piggyBankRepetition->currentamount); $this->assertEquals(0, $collection->first()->startBalance); $this->assertEquals(0, $collection->first()->endBalance); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getSavingsAccounts */ public function testGetSavingsAccounts() { // create three accounts: FactoryMuffin::create('FireflyIII\Models\AccountType'); FactoryMuffin::create('FireflyIII\Models\AccountType'); $type = FactoryMuffin::create('FireflyIII\Models\AccountType'); $account1 = FactoryMuffin::create('FireflyIII\Models\Account'); $account1->account_type_id = $type->id; $account2 = FactoryMuffin::create('FireflyIII\Models\Account'); $account2->account_type_id = $type->id; $account3 = FactoryMuffin::create('FireflyIII\Models\Account'); $account3->account_type_id = $type->id; // make them savings accounts: $meta = new AccountMeta; $meta->name = 'accountRole'; $meta->data = 'savingAsset'; $meta->account_id = $account1->id; $meta->save(); $meta = new AccountMeta; $meta->name = 'accountRole'; $meta->data = 'savingAsset'; $meta->account_id = $account2->id; $meta->save(); $meta = new AccountMeta; $meta->name = 'accountRole'; $meta->data = 'savingAsset'; $meta->account_id = $account3->id; $meta->save(); // assign to the same user: $account2->user_id = $account1->user_id; $account3->user_id = $account1->user_id; $account1->save(); $account2->save(); $account3->save(); $this->be($account1->user); // mock steam balance: Steam::shouldReceive('balance')->andReturn(0, 0, 1, 2, 4, 3); // get the result from the method: $result = $this->object->getSavingsAccounts(); $this->assertEquals(0, $result->get(0)->difference); $this->assertEquals(1, $result->get(1)->difference); $this->assertEquals(-1, $result->get(2)->difference); $this->assertEquals(100, $result->get(0)->percentage); $this->assertEquals(100, $result->get(1)->percentage); $this->assertEquals(25, $result->get(2)->percentage); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::getTransfersInRange * @todo Implement testGetTransfersInRange(). */ public function testGetTransfersInRange() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $date = new Carbon; // three transfers, two out of range: // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::leftOnAccount * @todo Implement testLeftOnAccount(). */ public function testLeftOnAccount() { // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::openingBalanceTransaction * @todo Implement testOpeningBalanceTransaction(). */ public function testOpeningBalanceTransaction() { // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::store * @todo Implement testStore(). */ public function testStore() { // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::sumOfEverything * @todo Implement testSumOfEverything(). */ public function testSumOfEverything() { // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } /** * @covers FireflyIII\Repositories\Account\AccountRepository::update * @todo Implement testUpdate(). */ public function testUpdate() { // Remove the following lines when you implement this test. $this->markTestIncomplete('This test has not been implemented yet.'); } }