Skip to content

Firefly III: a personal finances manager

Tests for homecontroller. Updated travis configuration.

James Cole905e590c12ad
diff --git a/.travis.yml b/.travis.yml
index 0aec6d1d08..48aa3ad7af 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,8 @@ language: php
php:
- 5.5
+ - 5.4
+ - hhvm
install:
- composer install
diff --git a/app/tests/controllers/HomeControllerTest.php b/app/tests/controllers/HomeControllerTest.php
new file mode 100644
index 0000000000..ec44dc3280
--- /dev/null
+++ b/app/tests/controllers/HomeControllerTest.php
@@ -0,0 +1,120 @@
+<?php
+use Carbon\Carbon as Carbon;
+use Mockery as m;
+use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
+
+/**
+ * Class HomeControllerTest
+ */
+class HomeControllerTest extends TestCase
+{
+ protected $_accounts;
+ protected $_repository;
+ protected $_preferences;
+ protected $_journals;
+
+ public function setUp()
+ {
+ parent::setUp();
+ Artisan::call('migrate');
+ Artisan::call('db:seed');
+ $this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
+ $this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
+ $this->_preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
+ $this->_journals = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
+
+
+ }
+
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testFlush()
+ {
+ $this->action('GET', 'HomeController@flush');
+ $this->assertRedirectedToRoute('index');
+
+ }
+
+ public function testIndex()
+ {
+ // mock preference:
+ $preference = $this->mock('Preference');
+ $preference->shouldReceive('getAttribute')->with('data')->andReturn([]);
+
+
+ // mock accounts:
+ $this->_repository->shouldReceive('count')->once()->andReturn(0);
+ $this->_repository->shouldReceive('getActiveDefault')->once()->andReturn([]);
+
+ // mock preferences:
+ $this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
+
+ $this->action('GET', 'HomeController@index');
+ $this->assertResponseOk();
+ }
+
+ public function testIndexWithAccount()
+ {
+ $account = f::create('Account');
+ $start = new Carbon;
+ $end = new Carbon;
+ $this->session(['start' => $start, 'end' => $end]);
+
+
+ // mock preference:
+ $preference = $this->mock('Preference');
+ $preference->shouldReceive('getAttribute')->with('data')->andReturn([$account->id]);
+
+
+ // mock accounts:
+ $this->_repository->shouldReceive('count')->once()->andReturn(0);
+ $this->_repository->shouldReceive('getByIds')->with([$account->id])->once()->andReturn([$account]);
+
+ // mock preferences:
+ $this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
+
+ // mock journals:
+ $this->_journals->shouldReceive('getByAccountInDateRange')->once()->with($account, 15, $start, $end)->andReturn(
+ [1, 2]
+ );
+
+ $this->action('GET', 'HomeController@index');
+ $this->assertResponseOk();
+ }
+
+ public function testIndexWithAccounts()
+ {
+ $accountOne = f::create('Account');
+ $accountTwo = f::create('Account');
+ $accounThree = f::create('Account');
+ $set = [$accountOne, $accountTwo, $accounThree];
+ $ids = [$accountOne->id, $accountTwo->id, $accounThree->id];
+ $start = new Carbon;
+ $end = new Carbon;
+ $this->session(['start' => $start, 'end' => $end]);
+
+
+ // mock preference:
+ $preference = $this->mock('Preference');
+ $preference->shouldReceive('getAttribute')->with('data')->andReturn($ids);
+
+
+ // mock accounts:
+ $this->_repository->shouldReceive('count')->once()->andReturn(0);
+ $this->_repository->shouldReceive('getByIds')->with($ids)->once()->andReturn(
+ $set
+ );
+
+ // mock preferences:
+ $this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
+
+ // mock journals:
+ $this->_journals->shouldReceive('getByAccountInDateRange')->andReturn([1, 2]);
+
+ $this->action('GET', 'HomeController@index');
+ $this->assertResponseOk();
+ }
+}
\ No newline at end of file