/**
  * @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::single
  */
 public function testSingle()
 {
     // be somebody
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->data = 'en';
     $preference->save();
     // mock language preference:
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
     // mock Steam::balance
     Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
     // data for call:
     $start = Carbon::createFromDate(2015, 1, 1);
     $end = Carbon::createFromDate(2015, 1, 15);
     $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
     // call
     $result = $this->object->single($account, $start, $end);
     // test
     $this->assertCount(15, $result['labels']);
     $this->assertEquals($account->name, $result['datasets'][0]['label']);
     $this->assertCount(15, $result['datasets'][0]['data']);
 }
 /**
  * @covers FireflyIII\Http\Controllers\JsonController::boxBillsUnpaid
  */
 public function testBoxBillsUnpaid()
 {
     $bill = FactoryMuffin::create('FireflyIII\\Models\\Bill');
     $creditCard = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $ccs = new Collection([$creditCard]);
     $collection = new Collection([$bill]);
     $ranges = [['start' => new Carbon(), 'end' => new Carbon()]];
     $this->be($bill->user);
     $bills = $this->mock('FireflyIII\\Repositories\\Bill\\BillRepositoryInterface');
     $accounts = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface');
     // mock!
     $bills->shouldReceive('getActiveBills')->andReturn($collection);
     $bills->shouldReceive('getRanges')->andReturn($ranges);
     $bills->shouldReceive('getJournalsInRange')->andReturn(new Collection());
     $bills->shouldReceive('createFakeBill')->andReturn($bill);
     $accounts->shouldReceive('getCreditCards')->andReturn($ccs);
     Amount::shouldReceive('format')->andReturn('xx');
     Amount::shouldReceive('getCurrencyCode')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     Steam::shouldReceive('balance')->andReturn(-1);
     $this->call('GET', '/json/box/bills-unpaid');
     $this->assertResponseOk();
 }
 /**
  * @covers FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator::single
  */
 public function testSingle()
 {
     // be somebody
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     /** @var Account $account */
     $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
     // data for call:
     $start = Carbon::createFromDate(2015, 1, 1);
     $end = Carbon::createFromDate(2015, 1, 15);
     // mock Steam::balance
     Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
     $data = $this->object->single($account, $start, $end);
     $this->assertCount(3, $data['cols']);
     // account, date, certainty
     // fifteen days,
     $this->assertCount(15, $data['rows']);
     // 15 days
 }
 /**
  * @covers FireflyIII\Http\Controllers\PiggyBankController::index
  */
 public function testIndex()
 {
     $piggyBank1 = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank');
     $piggyBank2 = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank');
     $piggyBank3 = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank');
     $piggyBank2->account_id = $piggyBank1->account_id;
     $user = FactoryMuffin::create('FireflyIII\\User');
     $piggyBank2->save();
     $collection = new Collection([$piggyBank1, $piggyBank2, $piggyBank3]);
     $this->be($user);
     // mock!
     $accounts = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface');
     $piggyBanks = $this->mock('FireflyIII\\Repositories\\PiggyBank\\PiggyBankRepositoryInterface');
     // act!
     $piggyBanks->shouldReceive('getPiggyBanks')->once()->andReturn($collection);
     Steam::shouldReceive('balance')->andReturn(20);
     $accounts->shouldReceive('leftOnAccount')->andReturn(12);
     Amount::shouldReceive('format')->andReturn('123');
     Amount::shouldReceive('getCurrencyCode')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     $this->call('GET', '/piggy-banks');
     $this->assertResponseOk();
 }
Beispiel #5
0
 /**
  * @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts
  */
 public function testGetAllAccountsShared()
 {
     $start = new Carbon('2015-01-01');
     $end = new Carbon('2015-02-01');
     $user = FactoryMuffin::create('FireflyIII\\User');
     FactoryMuffin::create('FireflyIII\\Models\\Account');
     FactoryMuffin::create('FireflyIII\\Models\\Account');
     $asset = FactoryMuffin::create('FireflyIII\\Models\\Account');
     for ($i = 0; $i < 10; $i++) {
         $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
         $account->account_type_id = $asset->id;
         $account->user_id = $user->id;
         $account->save();
     }
     Steam::shouldReceive('balance')->andReturn(0);
     $this->be($user);
     $set = $this->object->getAllAccounts($start, $end, true);
     $this->assertCount(10, $set);
 }
 /**
  * @covers FireflyIII\Repositories\Account\AccountRepository::getSavingsAccounts
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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);
 }