/**
  * FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator::yearInOut
  */
 public function testYearInOut()
 {
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->data = 'en';
     $preference->save();
     // mock language preference:
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
     // make set:
     $collection = new Collection();
     for ($i = 0; $i < 5; $i++) {
         $collection->push([new Carbon(), 200, 100]);
     }
     $data = $this->object->yearInOut($collection);
     $this->assertEquals(200, $data['datasets'][0]['data'][0]);
     $this->assertEquals(100, $data['datasets'][1]['data'][0]);
     $this->assertCount(5, $data['labels']);
 }
 public function testIndexNoAccounts()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface');
     $this->be($user);
     // mock ALL THE THINGS!
     $repository->shouldReceive('countAccounts')->once()->andReturn(3);
     // language preference:
     $language = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $language->data = 'en';
     $language->save();
     Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
     $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $lastActivity->data = microtime();
     Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
     $this->call('GET', '/new-user');
     $this->assertResponseStatus(302);
     $this->assertRedirectedToRoute('index');
 }
 /**
  * @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::year
  */
 public function testYear()
 {
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->data = 'en';
     $preference->save();
     $budgets = new Collection();
     $entries = new Collection();
     // make some budgets:
     for ($i = 0; $i < 5; $i++) {
         $budgets->push(FactoryMuffin::create('FireflyIII\\Models\\Budget'));
         $entries->push([new Carbon(), 100, 100, 100]);
     }
     // mock language preference:
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
     $data = $this->object->year($budgets, $entries);
     $this->assertCount(5, $data['labels']);
     $this->assertCount(5, $data['datasets']);
     $this->assertCount(3, $data['datasets'][0]['data']);
 }
 /**
  * @covers FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator::single
  */
 public function testSingle()
 {
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->data = 'en';
     $preference->save();
     // mock language preference:
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
     $bill = FactoryMuffin::create('FireflyIII\\Models\\Bill');
     $entries = new Collection();
     for ($i = 0; $i < 5; $i++) {
         $obj = new stdClass();
         $obj->amount = 100;
         $obj->date = new Carbon();
         $entries->push($obj);
     }
     $data = $this->object->single($bill, $entries);
     $this->assertCount(5, $data['labels']);
     $this->assertCount(5, $data['datasets'][1]['data']);
     $this->assertEquals(100, $data['datasets'][1]['data'][0]);
     // see if first is equal.
 }
 /**
  * @covers FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator::history
  */
 public function testHistory()
 {
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->data = 'en';
     $preference->save();
     // mock language preference:
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
     // create a set
     $set = new Collection();
     for ($i = 0; $i < 5; $i++) {
         $obj = new stdClass();
         $obj->date = new Carbon();
         $obj->sum = 100;
         $set->push($obj);
     }
     $data = $this->object->history($set);
     $this->assertCount(5, $data['labels']);
     $this->assertCount(5, $data['datasets'][0]['data']);
     $this->assertEquals(100, $data['datasets'][0]['data'][0]);
     $this->assertEquals(500, $data['datasets'][0]['data'][4]);
 }
 /**
  * @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\AccountController::create
  */
 public function testCreate()
 {
     $pref = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $pref->data = '1M';
     $this->be($pref->user);
     Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($pref);
     $language = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $language->data = 'en';
     Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language);
     // CURRENCY:
     $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency');
     Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
     Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
     Amount::shouldReceive('getCurrencyCode')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $lastActivity->data = microtime();
     Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
     $this->call('GET', '/accounts/create/asset');
     $this->assertResponseOk();
     $this->assertViewHas('subTitle', 'Create a new asset account');
     $this->assertViewHas('subTitleIcon', 'fa-money');
     $this->assertViewHas('what', 'asset');
 }
 /**
  * @covers FireflyIII\Support\Amount::getCurrencyCode
  */
 public function testGetCurrencyCodeNoSuchCurrency()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     // delete any currency preferences:
     Preference::where('user_id', $user->id)->delete();
     // delete transaction currencies:
     foreach (TransactionCurrency::get() as $c) {
         $c->delete();
     }
     $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $preference->user_id = $user->id;
     $preference->name = 'currencyPreference';
     $preference->data = 'SOM';
     $preference->save();
     Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($preference);
     $code = $this->object->getCurrencyCode();
     $this->assertEquals('EUR', $code);
 }
 /**
  * @covers FireflyIII\Http\Controllers\PreferencesController::postIndex
  */
 public function testPostIndex()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     $data = ['frontPageAccounts' => [1, 2, 3], '_token' => 'replaceMe', 'viewRange' => '1M', 'language' => 'en'];
     // language preference:
     $language = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $language->data = 'en';
     $language->save();
     Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
     Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]);
     Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']);
     Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]);
     Preferences::shouldReceive('set')->once()->withArgs(['language', 'en']);
     Preferences::shouldReceive('mark')->once()->andReturn(true);
     // language preference:
     $language = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $language->data = 'en';
     $language->save();
     Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
     $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $lastActivity->data = microtime();
     Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
     $this->call('POST', '/preferences', $data);
     $this->assertResponseStatus(302);
 }
 /**
  * @covers FireflyIII\Http\Controllers\BudgetController::updateIncome
  */
 public function testUpdateIncome()
 {
     // a budget:
     $budget = FactoryMuffin::create('FireflyIII\\Models\\Budget');
     $this->be($budget->user);
     $date = Carbon::now()->format('FY');
     $pref = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     Preferences::shouldReceive('get')->withArgs(['budgetIncomeTotal' . $date, 1000])->andReturn($pref);
     Amount::shouldReceive('format')->andReturn('xx');
     Amount::shouldReceive('getCurrencyCode')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $lastActivity->data = microtime();
     Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
     // language preference:
     $language = FactoryMuffin::create('FireflyIII\\Models\\Preference');
     $language->data = 'en';
     $language->save();
     Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
     $this->call('GET', '/budgets/income');
     $this->assertResponseOk();
     $this->assertViewHas('amount');
 }