diff --git a/pu.sh b/pu.sh
index a532d9ecf0..26c595cfb4 100755
--- a/pu.sh
+++ b/pu.sh
@@ -18,4 +18,4 @@ then
fi
# restore .env file
-mv .env.backup .env
+cp .env.local .env
diff --git a/resources/views/profile/delete-account.blade.php b/resources/views/profile/delete-account.blade.php
new file mode 100644
index 0000000000..a181f16a68
--- /dev/null
+++ b/resources/views/profile/delete-account.blade.php
@@ -0,0 +1,49 @@
+@extends('layouts.default')
+@section('content')
+{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) !!}
+
+
+
+
+ Delete your account
+
+
+
+
+ Deleting your account will also delete any accounts, transactions, anything
+ you might have saved into Firefly III. It'll be GONE.
+
+
+ Enter your password to continue.
+
+
+ @if($errors->count() > 0)
+
+ @foreach($errors->all() as $err)
+ - {{$err}}
+ @endforeach
+
+
+ @endif
+
+ {!! Form::open(['class' => 'form-horizontal','id' => 'change-password']) !!}
+
+
+
+ {!! Form::close() !!}
+
+
+
+
+@stop
+@section('scripts')
+@stop
diff --git a/resources/views/profile/index.blade.php b/resources/views/profile/index.blade.php
index e6eab98606..660cd54bcc 100644
--- a/resources/views/profile/index.blade.php
+++ b/resources/views/profile/index.blade.php
@@ -8,7 +8,10 @@
Options
diff --git a/resources/views/reports/month.blade.php b/resources/views/reports/month.blade.php
index a7a9504352..a906fd2019 100644
--- a/resources/views/reports/month.blade.php
+++ b/resources/views/reports/month.blade.php
@@ -25,15 +25,15 @@
{{{$entry->description}}}
- amount);?>
+ queryAmount);?>
@if($entry->type == 'Withdrawal')
- {{Amount::format($entry->amount,false)}}
+ {{Amount::format($entry->queryAmount,false)}}
@endif
@if($entry->type == 'Deposit')
- {{Amount::format($entry->amount,false)}}
+ {{Amount::format($entry->queryAmount,false)}}
@endif
@if($entry->type == 'Transfer')
- {{Amount::format($entry->amount,false)}}
+ {{Amount::format($entry->queryAmount,false)}}
@endif
|
diff --git a/storage/database/.gitignore b/storage/database/.gitignore
new file mode 100644
index 0000000000..3997beadf8
--- /dev/null
+++ b/storage/database/.gitignore
@@ -0,0 +1 @@
+*.db
\ No newline at end of file
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 336e5f2a9a..cc436f7446 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -29,7 +29,22 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
public function setUp()
{
parent::setUp();
- Artisan::call('migrate');
+
+ // if the database copy does not exist, call migrate.
+ $copy = __DIR__.'/../storage/database/testing-copy.db';
+ $original = __DIR__.'/../storage/database/testing.db';
+ if (!file_exists($copy)) {
+ Log::debug('Created new database.');
+ touch($original);
+ Artisan::call('migrate');
+ copy($original, $copy);
+ } else {
+ if (file_exists($copy)) {
+ copy($copy, $original);
+ }
+ }
+ // if the database copy does exists, copy back as original.
+
FactoryMuffin::loadFactories(__DIR__ . '/factories');
}
@@ -44,10 +59,24 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
parent::setUpBeforeClass();
}
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ public function tearDown()
+ {
+ parent::tearDown();
+
+ // delete copy original.
+ //$original = __DIR__.'/../storage/database/testing.db';
+ //unlink($original);
+
+ }
+
/**
* @param string $class
*
- * @return mixed
+ * @return Mockery\MockInterface
*/
public function mock($class)
{
diff --git a/tests/controllers/JsonControllerTest.php b/tests/controllers/JsonControllerTest.php
index 4a902079f6..0f8390d6cc 100644
--- a/tests/controllers/JsonControllerTest.php
+++ b/tests/controllers/JsonControllerTest.php
@@ -35,7 +35,6 @@ class JsonControllerTest extends TestCase
public function tearDown()
{
parent::tearDown();
-
}
public function testBoxBillsPaid()
diff --git a/tests/controllers/PiggyBankControllerTest.php b/tests/controllers/PiggyBankControllerTest.php
new file mode 100644
index 0000000000..63964eb163
--- /dev/null
+++ b/tests/controllers/PiggyBankControllerTest.php
@@ -0,0 +1,399 @@
+be($piggyBank->account->user);
+
+
+ // mock
+ /** @var Mockery\MockInterface $repository */
+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $repository->shouldReceive('leftOnAccount')->withAnyArgs()->andReturn(12);
+ Amount::shouldReceive('format')->andReturn('XXxx');
+
+ $this->call('GET', '/piggy-banks/add/' . $piggyBank->id);
+ $this->assertResponseOk();
+ }
+
+ public function testCreate()
+ {
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $collection = new Collection([$account]);
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+
+ // mock
+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
+ ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
+
+ // also cover the view now that we've touched ExpandedForm:
+ ExpandedForm::shouldReceive('text')->andReturn('');
+ ExpandedForm::shouldReceive('select')->andReturn('');
+ ExpandedForm::shouldReceive('amount')->andReturn('');
+ ExpandedForm::shouldReceive('date')->andReturn('');
+ ExpandedForm::shouldReceive('checkbox')->andReturn('');
+ ExpandedForm::shouldReceive('optionsList')->andReturn('');
+
+ $this->call('GET', '/piggy-banks/create');
+ $this->assertResponseOk();
+ }
+
+ public function testDelete()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+
+ $this->call('GET', '/piggy-banks/delete/' . $piggyBank->id);
+ $this->assertResponseOk();
+ $this->assertViewHas('subTitle', 'Delete "' . e($piggyBank->name) . '"');
+ }
+
+ public function testDestroy()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+
+ $repository = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $repository->shouldReceive('destroy')->once()->withAnyArgs()->andReturn(true);
+
+
+ $this->call('POST', '/piggy-banks/destroy/' . $piggyBank->id, ['_token' => 'replaceMe']);
+ $this->assertResponseStatus(302);
+ $this->assertSessionHas('success');
+
+ }
+
+ public function testEdit()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $collection = new Collection([$account]);
+
+ // mock!
+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
+ ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
+
+ // also cover the view now that we've touched ExpandedForm:
+ ExpandedForm::shouldReceive('text')->andReturn('');
+ ExpandedForm::shouldReceive('select')->andReturn('');
+ ExpandedForm::shouldReceive('amount')->andReturn('');
+ ExpandedForm::shouldReceive('date')->andReturn('');
+ ExpandedForm::shouldReceive('checkbox')->andReturn('');
+ ExpandedForm::shouldReceive('optionsList')->andReturn('');
+
+
+ $this->call('GET', '/piggy-banks/edit/' . $piggyBank->id);
+ $this->assertResponseOk();
+ }
+
+ public function testEditNullDate()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+ $piggyBank->targetdate = null;
+ $piggyBank->save();
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $collection = new Collection([$account]);
+
+ // mock!
+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
+ ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
+
+ // also cover the view now that we've touched ExpandedForm:
+ ExpandedForm::shouldReceive('text')->andReturn('');
+ ExpandedForm::shouldReceive('select')->andReturn('');
+ ExpandedForm::shouldReceive('amount')->andReturn('');
+ ExpandedForm::shouldReceive('date')->andReturn('');
+ ExpandedForm::shouldReceive('checkbox')->andReturn('');
+ ExpandedForm::shouldReceive('optionsList')->andReturn('');
+
+
+ $this->call('GET', '/piggy-banks/edit/' . $piggyBank->id);
+ $this->assertResponseOk();
+ }
+
+ 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');
+
+
+ $this->call('GET', '/piggy-banks');
+ $this->assertResponseOk();
+
+ }
+
+ public function testOrder()
+ {
+ $piggyBank1 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $piggyBank2 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+
+ // mock!
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('reset')->once();
+ $piggyBanks->shouldReceive('setOrder');
+ $array = [
+ $piggyBank1->id => 0,
+ $piggyBank2->id => 1,
+ ];
+
+ $this->call('POST', '/piggy-banks/sort', ['_token' => 'replaceMe', 'order' => $array]);
+ $this->assertResponseOk();
+ }
+
+ public function testPostAdd()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ // mock!
+ $accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $accounts->shouldReceive('leftOnAccount')->andReturn(20);
+ $piggyBanks->shouldReceive('createEvent')->once();
+
+ Amount::shouldReceive('format')->andReturn('something');
+
+ $this->call('POST', '/piggy-banks/add/' . $piggyBank->id, ['_token' => 'replaceMe']);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testPostAddOverdraw()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ // mock!
+ $accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $accounts->shouldReceive('leftOnAccount')->andReturn(20);
+ $piggyBanks->shouldReceive('createEvent')->once();
+
+ Amount::shouldReceive('format')->andReturn('something');
+
+ $this->call('POST', '/piggy-banks/add/' . $piggyBank->id, ['_token' => 'replaceMe', 'amount' => '10000']);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testPostRemove()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ // mock!
+ $accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $accounts->shouldReceive('leftOnAccount')->andReturn(20);
+ $piggyBanks->shouldReceive('createEvent')->once();
+
+ Amount::shouldReceive('format')->andReturn('something');
+ Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
+
+ $this->call('POST', '/piggy-banks/remove/' . $piggyBank->id, ['_token' => 'replaceMe']);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testPostRemoveOverdraw()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ // mock!
+ $accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $accounts->shouldReceive('leftOnAccount')->andReturn(20);
+ $piggyBanks->shouldReceive('createEvent')->once();
+
+ Amount::shouldReceive('format')->andReturn('something');
+ Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
+
+ $this->call('POST', '/piggy-banks/remove/' . $piggyBank->id, ['_token' => 'replaceMe', 'amount' => '10000']);
+ $this->assertResponseStatus(302);
+ }
+
+
+ public function testRemove()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ Amount::shouldReceive('format')->andReturn('something');
+
+ $this->call('GET', '/piggy-banks/remove/' . $piggyBank->id);
+ $this->assertResponseOk();
+ }
+
+ public function testShow()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('getEvents')->andReturn(new Collection);
+ Amount::shouldReceive('format')->andReturn('something');
+ Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
+ Amount::shouldReceive('getCurrencyCode')->andReturn('something');
+
+
+ $this->call('GET', '/piggy-banks/show/' . $piggyBank->id);
+ $this->assertResponseOk();
+ }
+
+ public function testStore()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ $piggyBankData = [
+ 'name' => 'Some name' . rand(1, 100),
+ 'account_id' => $piggyBank->account_id,
+ 'targetamount' => 100,
+ 'targetdate' => '',
+ 'reminder' => 'month',
+ '_token' => 'replaceMe'
+ ];
+
+ // mock!
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('store')->once()->andReturn($piggyBank);
+
+ $this->call('POST', '/piggy-banks/store', $piggyBankData);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testStoreCreateAnother()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ $piggyBankData = [
+ 'name' => 'Some name' . rand(1, 100),
+ 'account_id' => $piggyBank->account_id,
+ 'targetamount' => 100,
+ 'targetdate' => '',
+ 'reminder' => 'month',
+ 'create_another' => 1,
+ '_token' => 'replaceMe'
+ ];
+
+ // mock!
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('store')->once()->andReturn($piggyBank);
+
+ $this->call('POST', '/piggy-banks/store', $piggyBankData);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testUpdate()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ $piggyBankData = [
+ 'name' => 'Some name' . rand(1, 100),
+ 'account_id' => $piggyBank->account_id,
+ 'targetamount' => 200,
+ 'targetdate' => '',
+ 'reminder' => 'month',
+ '_token' => 'replaceMe'
+ ];
+
+ // mock!
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('update')->once()->andReturn($piggyBank);
+
+ $this->call('POST', '/piggy-banks/update/' . $piggyBank->id, $piggyBankData);
+ $this->assertResponseStatus(302);
+ }
+
+ public function testUpdateReturnToEdit()
+ {
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
+ $this->be($piggyBank->account->user);
+
+ $piggyBankData = [
+ 'name' => 'Some name' . rand(1, 100),
+ 'account_id' => $piggyBank->account_id,
+ 'targetamount' => 200,
+ 'targetdate' => '',
+ 'return_to_edit' => 1,
+ 'reminder' => 'month',
+ '_token' => 'replaceMe'
+ ];
+
+ // mock!
+ $piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
+ $piggyBanks->shouldReceive('update')->once()->andReturn($piggyBank);
+
+ $this->call('POST', '/piggy-banks/update/' . $piggyBank->id, $piggyBankData);
+ $this->assertResponseStatus(302);
+ }
+}
diff --git a/tests/controllers/PreferencesControllerTest.php b/tests/controllers/PreferencesControllerTest.php
new file mode 100644
index 0000000000..02f61910d6
--- /dev/null
+++ b/tests/controllers/PreferencesControllerTest.php
@@ -0,0 +1,84 @@
+be($user);
+
+
+ // mock:
+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+
+ // fake!
+ $repository->shouldReceive('getAccounts')->with(['Default account', 'Asset account'])->andReturn(new Collection);
+ Preferences::shouldReceive('get')->once()->withArgs(['viewRange', '1M'])->andReturn($pref);
+ Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($pref);
+ Preferences::shouldReceive('get')->once()->withArgs(['budgetMaximum', 1000])->andReturn($pref);
+ Preferences::shouldReceive('get')->once()->withArgs(['currencyPreference', 'EUR'])->andReturn($pref);
+ Amount::shouldReceive('format')->andReturn('xx');
+ Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection);
+ Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
+
+ $this->call('GET', '/preferences');
+ $this->assertResponseOk();
+ }
+
+ public function testPostIndex()
+ {
+ $user = FactoryMuffin::create('FireflyIII\User');
+ $this->be($user);
+
+ $data = [
+ 'frontPageAccounts' => [1, 2, 3],
+ '_token' => 'replaceMe',
+ 'viewRange' => '1M'
+ ];
+
+ Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]);
+ Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']);
+ Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]);
+
+
+ $this->call('POST', '/preferences', $data);
+ $this->assertResponseStatus(302);
+ }
+}
\ No newline at end of file
|