Fixed all tests.

This commit is contained in:
James Cole
2014-07-15 07:36:01 +02:00
parent 09b6c4d982
commit 445de5a1d8
7 changed files with 131 additions and 42 deletions

View File

@@ -25,6 +25,7 @@ class Preference extends Elegant
$this->attributes['data'] = json_encode($value);
}
//
public function getDataAttribute($value)
{
return json_decode($value);

View File

@@ -13,11 +13,11 @@ class ChartControllerTest extends TestCase
{
// mock preference:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn('week');
$pref->shouldReceive('getAttribute', 'data')->andReturn('1M');
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// mock toolkit:
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
@@ -73,7 +73,7 @@ class ChartControllerTest extends TestCase
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// mock toolkit:
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
@@ -111,11 +111,11 @@ class ChartControllerTest extends TestCase
// mock preference:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn('week');
$pref->shouldReceive('getAttribute', 'data')->andReturn('1M');
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// mock toolkit:
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
@@ -153,7 +153,7 @@ class ChartControllerTest extends TestCase
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// call
@@ -183,7 +183,7 @@ class ChartControllerTest extends TestCase
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// call
@@ -213,7 +213,7 @@ class ChartControllerTest extends TestCase
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
// call

View File

@@ -26,10 +26,8 @@ class HomeControllerTest extends TestCase
$accounts->shouldReceive('count')->andReturn(0);
$accounts->shouldReceive('getActiveDefault')->andReturn([]);
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts',[])->andReturn(new \Preference)->once();
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn('week');
// call
$this->call('GET', '/');
@@ -73,7 +71,6 @@ class HomeControllerTest extends TestCase
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts',[])->andReturn($pref)->once();
$preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn('week');
// call
$this->call('GET', '/');

View File

@@ -0,0 +1,39 @@
<?php
class JsonControllerTest extends TestCase {
public function setUp()
{
parent::setUp();
}
public function testBeneficiaries() {
$obj = new stdClass;
$obj->name = 'Bla bla';
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getBeneficiaries')->andReturn([$obj]);
$this->call('GET', '/json/beneficiaries');
// test
$this->assertResponseOk();
}
public function testCategories() {
$obj = new stdClass;
$obj->name = 'Bla bla';
// mock category repository:
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('get')->andReturn([$obj]);
$this->call('GET', '/json/categories');
// test
$this->assertResponseOk();
}
}

View File

@@ -14,18 +14,21 @@ class PreferencesControllerTest extends TestCase
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn([]);
$viewPref = $this->mock('Preference');
$viewPref->shouldReceive('getAttribute', 'data')->andReturn('1M');
// mock view:
View::shouldReceive('share');
View::shouldReceive('make')->with('preferences.index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('accounts', [])->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('viewRange', '1M')->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('frontpageAccounts', $pref)->andReturn(\Mockery::self());
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->andReturn($viewPref);
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
@@ -39,14 +42,15 @@ class PreferencesControllerTest extends TestCase
$this->assertResponseOk();
}
public function testPostIndex() {
public function testPostIndex()
{
// mock
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('set')->with('frontpageAccounts', [1])->andReturn(true);
$preferences->shouldReceive('set')->with('viewRange', '1M')->andReturn(true);
// call
$this->call('POST', '/preferences',['frontpageAccounts' => [1]]);
$this->call('POST', '/preferences', ['frontpageAccounts' => [1], 'viewRange' => '1M']);
// test

View File

@@ -0,0 +1,25 @@
<?php
class TransactionControllerTest extends TestCase
{
public function testCreateWithdrawal()
{
View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.withdrawal')->andReturn(\Mockery::self())
->shouldReceive('with')->once()
->with('accounts', [])
->andReturn(Mockery::self());
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// call
$this->call('GET', '/transactions/add/withdrawal');
// test
$this->assertResponseOk();
}
}

View File

@@ -33,13 +33,28 @@ class AllModelsTest extends TestCase
$pref = FactoryMuff::create('Preference');
$account = FactoryMuff::create('Account');
// some more stuff:
$component = FactoryMuff::create('Component');
$budget = FactoryMuff::create('Budget');
$category = FactoryMuff::create('Category');
$account->user()->associate($user);
$pref->user()->associate($user);
$user->accounts()->save($account);
$user->preferences()->save($pref);
$user->components()->save($component);
$user->budgets()->save($budget);
$user->categories()->save($category);
$this->assertEquals($account->user_id, $user->id);
$this->assertEquals($pref->user_id,$user->id);
$this->assertEquals($pref->user_id, $user->id);
$this->assertEquals($budget->user_id, $user->id);
$this->assertEquals($category->user_id, $user->id);
$this->assertEquals($component->user_id, $user->id);
// test pref?
$pref->data = 'Blabla';
$this->assertEquals($pref->data,'Blabla');
$this->assertCount(1, $user->accounts()->get());
$this->assertCount(1, $user->preferences()->get());
@@ -63,7 +78,8 @@ class AllModelsTest extends TestCase
* Transaction journal tests.
*/
public function testTransactionJournals() {
public function testTransactionJournals()
{
$tj = FactoryMuff::create('TransactionJournal');
$t1 = FactoryMuff::create('Transaction');
@@ -80,28 +96,30 @@ class AllModelsTest extends TestCase
$tj->components()->save($budget);
$tj->components()->save($category);
$this->assertCount(2,$tj->components()->get());
$this->assertCount(1,$tj->budgets()->get());
$this->assertCount(1,$tj->categories()->get());
$this->assertCount(2, $tj->components()->get());
$this->assertCount(1, $tj->budgets()->get());
$this->assertCount(1, $tj->categories()->get());
$this->assertCount(3,$tj->transactions()->get());
$this->assertCount(3, $tj->transactions()->get());
$this->assertTrue($tj->isValid());
$this->assertEquals($tj->transaction_type_id,$tj->transactionType()->first()->id);
$this->assertEquals($tj->transaction_currency_id,$tj->transactionCurrency()->first()->id);
$this->assertEquals($tj->transaction_type_id, $tj->transactionType()->first()->id);
$this->assertEquals($tj->transaction_currency_id, $tj->transactionCurrency()->first()->id);
}
public function testTransactionJournalScope() {
public function testTransactionJournalScope()
{
$tj = FactoryMuff::create('TransactionJournal');
$tj->date = new \Carbon\Carbon('2012-01-02');
$set = $tj->after(new \Carbon\Carbon)->before(new \Carbon\Carbon)->get();
$this->assertCount(0,$set);
$this->assertCount(0, $set);
}
public function testTransactionType() {
public function testTransactionType()
{
$j1 = FactoryMuff::create('TransactionJournal');
$j2 = FactoryMuff::create('TransactionJournal');
@@ -109,11 +127,12 @@ class AllModelsTest extends TestCase
$type->transactionjournals()->save($j1);
$type->transactionjournals()->save($j2);
$this->assertCount(2,$type->transactionjournals()->get());
$this->assertCount(2, $type->transactionjournals()->get());
}
public function testTransactionCurrency() {
public function testTransactionCurrency()
{
$j1 = FactoryMuff::create('TransactionJournal');
$j2 = FactoryMuff::create('TransactionJournal');
@@ -121,11 +140,12 @@ class AllModelsTest extends TestCase
$currency->transactionjournals()->save($j1);
$currency->transactionjournals()->save($j2);
$this->assertCount(2,$currency->transactionjournals()->get());
$this->assertCount(2, $currency->transactionjournals()->get());
}
public function testAccountTypes() {
public function testAccountTypes()
{
$type = FactoryMuff::create('AccountType');
$a1 = FactoryMuff::create('Account');
$a2 = FactoryMuff::create('Account');
@@ -133,10 +153,11 @@ class AllModelsTest extends TestCase
$type->accounts()->save($a1);
$type->accounts()->save($a2);
$this->assertCount(2,$type->accounts()->get());
$this->assertCount(2, $type->accounts()->get());
}
public function testTransactions() {
public function testTransactions()
{
$transaction = FactoryMuff::create('Transaction');
$budget = FactoryMuff::create('Budget');
@@ -149,15 +170,16 @@ class AllModelsTest extends TestCase
$transaction->account()->associate($account);
$transaction->transactionjournal()->associate($journal);
$this->assertCount(1,$transaction->transactionjournal()->get());
$this->assertCount(1,$transaction->account()->get());
$this->assertCount(2,$transaction->components()->get());
$this->assertCount(1,$transaction->budgets()->get());
$this->assertCount(1,$transaction->categories()->get());
$this->assertCount(1, $transaction->transactionjournal()->get());
$this->assertCount(1, $transaction->account()->get());
$this->assertCount(2, $transaction->components()->get());
$this->assertCount(1, $transaction->budgets()->get());
$this->assertCount(1, $transaction->categories()->get());
}
public function testComponents() {
public function testComponents()
{
$component = FactoryMuff::create('Component');
$user = FactoryMuff::create('User');
$transaction = FactoryMuff::create('Transaction');
@@ -167,8 +189,9 @@ class AllModelsTest extends TestCase
$component->user()->associate($user);
$component->transactions()->save($transaction);
$this->assertCount(1,$component->transactionjournals()->get());
$this->assertCount(1,$component->user()->get());
$this->assertCount(1,$component->transactions()->get());
$this->assertCount(1, $component->transactionjournals()->get());
$this->assertCount(1, $component->user()->get());
$this->assertCount(1, $component->transactions()->get());
}
}
}