Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Covered currency controller in tests.
James Coleeae96cd2af94
diff --git a/app/controllers/CurrencyController.php b/app/controllers/CurrencyController.phpindex f8381e2600..bc2ae575ea 100644--- a/app/controllers/CurrencyController.php+++ b/app/controllers/CurrencyController.php@@ -2,6 +2,10 @@use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository;/**+ *+ * @SuppressWarnings("CamelCase") // I'm fine with this.+ * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.+ ** Class CurrencyController*/class CurrencyController extends BaseController@@ -46,6 +50,8 @@ class CurrencyController extends BaseController$currencyPreference = $preferences->get('currencyPreference', 'EUR');$currencyPreference->data = $currency->code;$currencyPreference->save();++ Session::flash('success', $currency->name.' is now the default currency.');Cache::forget('FFCURRENCYSYMBOL');Cache::forget('FFCURRENCYCODE');@@ -139,7 +145,7 @@ class CurrencyController extends BaseControllerpublic function update(TransactionCurrency $currency){- $data = Input::except('_token');+ $data = Input::except('_token');// always validate:$messages = $this->_repository->validate($data);diff --git a/app/database/seeds/TransactionCurrencySeeder.php b/app/database/seeds/TransactionCurrencySeeder.phpindex 46a08f74fb..20f50e9f60 100644--- a/app/database/seeds/TransactionCurrencySeeder.php+++ b/app/database/seeds/TransactionCurrencySeeder.php@@ -10,9 +10,8 @@ class TransactionCurrencySeeder extends Seeder{DB::table('transaction_currencies')->delete();- TransactionCurrency::create(- ['code' => 'EUR']- );+ TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '€']);+ TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']);}}\ No newline at end of filediff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.phpindex 2e3648604f..887f792656 100644--- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php+++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php@@ -35,7 +35,9 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabaspublic function store(array $data){$currency = new \TransactionCurrency($data);+ \Log::debug('Is valid? ' . boolstr($currency->isValid()));$currency->save();+return $currency;}@@ -48,8 +50,9 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabaspublic function update(Eloquent $model, array $data){$model->symbol = $data['symbol'];- $model->code = $data['code'];- $model->name = $data['name'];+ $model->code = $data['code'];+ $model->name = $data['name'];+ \Log::debug('Is valid? ' . boolstr($model->isValid()));$model->save();return true;@@ -67,11 +70,16 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas{$warnings = new MessageBag;$successes = new MessageBag;+ \Log::debug('Now in TransactionCurrency::validate()');$currency = new \TransactionCurrency($model);$currency->isValid();$errors = $currency->getErrors();+ \Log::debug('Data: ' . json_encode($model));+ \Log::debug('Error-content: ' . json_encode($errors->all()));+ \Log::debug('Error count is: ' . $errors->count());+$fields = ['name', 'code', 'symbol'];foreach ($fields as $field) {if (!$errors->has($field)) {diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.phpindex 4a15900633..8f55b14be6 100644--- a/app/models/TransactionCurrency.php+++ b/app/models/TransactionCurrency.php@@ -12,20 +12,10 @@ class TransactionCurrency extends Eloquentuse SoftDeletingTrait, ValidatingTrait;protected $fillable = ['name', 'symbol', 'code'];- protected $rules- = [- 'creating' => [- 'code' => 'required|min:3|max:3|alpha|unique:transaction_currencies,code',- 'name' => 'required|min:3|max:48|unique:transaction_currencies,name',- 'symbol' => 'required|min:1|max:8|unique:transaction_currencies,symbol',- ],-- 'updating' => [- 'code' => 'required|min:3|max:3|alpha',- 'name' => 'required|min:3|max:48',- 'symbol' => 'required|min:1|max:8',- ],-+ protected $rules = [+ 'code' => 'required|alpha|between:3,3|min:3|max:3',+ 'name' => 'required|between:3,48|min:3|max:48',+ 'symbol' => 'required|between:1,8|min:1|max:8',];/**diff --git a/app/views/currency/edit.blade.php b/app/views/currency/edit.blade.phpindex 56792058a7..f9482210b4 100644--- a/app/views/currency/edit.blade.php+++ b/app/views/currency/edit.blade.php@@ -1,7 +1,7 @@@extends('layouts.default')@section('content'){{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}-{{Form::model($currency, ['class' => 'form-horizontal','id' => 'store','url' => route('currency.update',$currency->id)])}}+{{Form::model($currency, ['class' => 'form-horizontal','id' => 'update','url' => route('currency.update',$currency->id)])}}<div class="row"><div class="col-lg-6 col-md-6 col-sm-12"><div class="panel panel-primary">diff --git a/tests/functional/BudgetControllerCest.php b/tests/functional/BudgetControllerCest.phpindex 13051fe5b6..2789345917 100644--- a/tests/functional/BudgetControllerCest.php+++ b/tests/functional/BudgetControllerCest.php@@ -89,6 +89,7 @@ class BudgetControllerCest{$I->wantTo('show all budgets');$I->amOnPage('/budgets');+ $I->see('Budgets');}/**@@ -147,7 +148,6 @@ class BudgetControllerCest$I->see('Create a new budget');$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'validate_only']);$I->dontSeeRecord('budgets', ['name' => 'New budget.']);- resetToClean::clean();}/**@@ -160,7 +160,6 @@ class BudgetControllerCest$I->see('Create a new budget');$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'create_another']);$I->seeRecord('budgets', ['name' => 'New budget.']);- resetToClean::clean();}/**@@ -171,10 +170,11 @@ class BudgetControllerCest$I->amOnPage('/budgets/create');$I->wantTo('make storing a new budget fail.');$I->see('Create a new budget');- $I->submitForm('#store', ['name' => null, 'post_submit_action' => 'validate_only']);+ $I->submitForm('#store', ['name' => null, 'post_submit_action' => 'store']);$I->dontSeeRecord('budgets', ['name' => 'New budget.']);- resetToClean::clean();}++/*** @param FunctionalTester $I*/diff --git a/tests/functional/CurrencyControllerCest.php b/tests/functional/CurrencyControllerCest.phpnew file mode 100644index 0000000000..78798ab407--- /dev/null+++ b/tests/functional/CurrencyControllerCest.php@@ -0,0 +1,196 @@+<?php++/**+ * Class CurrencyControllerCest+ */+class CurrencyControllerCest+{+ /**+ * @param FunctionalTester $I+ */+ public function _after(FunctionalTester $I)+ {+ }++ /**+ * @param FunctionalTester $I+ */+ public function _before(FunctionalTester $I)+ {+ $I->amLoggedAs(['email' => '[email protected]', 'password' => 'james']);+ }+++ /**+ * @param FunctionalTester $I+ */+ public function create(FunctionalTester $I)+ {+ $I->wantTo('create a currency');+ $I->amOnRoute('currency.create');+ $I->see('Create a new currency');+ }++ /**+ * @param FunctionalTester $I+ */+ public function delete(FunctionalTester $I)+ {+ $I->wantTo('delete a currency');+ $I->amOnPage('/currency/delete/2');+ $I->see('Delete currency "US Dollar"');+ }++ /**+ * @param FunctionalTester $I+ */+ public function destroy(FunctionalTester $I)+ {+ $I->wantTo('destroy a currency');+ $I->amOnPage('/currency/delete/2');+ $I->see('Delete currency "US Dollar"');+ $I->submitForm('#destroy', []);+ $I->see('Currency "US Dollar" deleted');+ }++ public function defaultCurrency(FunctionalTester $I)+ {+ $I->wantTo('make US Dollar the default currency');+ $I->amOnPage('/currency/default/2');+ $I->see('US Dollar is now the default currency.');+ }++ /**+ * @param FunctionalTester $I+ */+ public function destroyFail(FunctionalTester $I)+ {+ $I->wantTo('destroy a currency currently in use');+ $I->amOnPage('/currency/delete/1');+ $I->see('Cannot delete Euro because there are still transactions attached to it.');+ }++ /**+ * @param FunctionalTester $I+ */+ public function edit(FunctionalTester $I)+ {+ $I->wantTo('edit a currency');+ $I->amOnPage('/currency/edit/2');+ $I->see('Edit currency "US Dollar"');+ }++ /**+ * @param FunctionalTester $I+ */+ public function index(FunctionalTester $I)+ {+ $I->wantTo('show all currencies');+ $I->amOnPage('/currency');+ $I->see('fa-usd');+ }++ /**+ * @param FunctionalTester $I+ */+ public function store(FunctionalTester $I)+ {+ $I->amOnPage('/currency/create');+ $I->wantTo('store a new currency');+ $I->see('Create a new currency');+ $I->submitForm('#store', ['name' => 'New currency.', 'symbol' => 'C', 'code' => 'CXX', 'post_submit_action' => 'store']);+ $I->seeRecord('transaction_currencies', ['name' => 'New currency.']);+ }++ /**+ * @param FunctionalTester $I+ */+ public function storeAndCreateAnother(FunctionalTester $I)+ {+ $I->amOnPage('/currency/create');+ $I->wantTo('store a new currency and create another');+ $I->see('Create a new currency');+ $I->submitForm('#store', ['name' => 'Store and create another.', 'symbol' => 'C', 'code' => 'CXX', 'post_submit_action' => 'create_another']);+ $I->seeRecord('transaction_currencies', ['name' => 'Store and create another.']);+ }++ /**+ * @param FunctionalTester $I+ */+ public function storeFail(FunctionalTester $I)+ {+ $I->amOnPage('/currency/create');+ $I->wantTo('make storing a new currency fail.');+ $I->see('Create a new currency');+ $I->submitForm('#store', ['name' => 'Store and fail', 'symbol' => null, 'code' => '123', 'post_submit_action' => 'store']);+ $I->dontSeeRecord('transaction_currencies', ['name' => 'Store and fail']);+ }++ /**+ * @param FunctionalTester $I+ */+ public function storeValidateOnly(FunctionalTester $I)+ {+ $I->amOnPage('/currency/create');+ $I->wantTo('validate a new currency');+ $I->see('Create a new currency');+ $I->submitForm('#store', ['name' => 'Store validate only.', 'symbol' => 'C', 'code' => 'CXX', 'post_submit_action' => 'validate_only']);+ $I->dontSeeRecord('transaction_currencies', ['name' => 'Store validate only.']);+ }++ /**+ * @param FunctionalTester $I+ */+ public function update(FunctionalTester $I)+ {+ $I->wantTo('update a currency');+ $I->amOnPage('/currency/edit/2');+ $I->see('Edit currency "US Dollar"');+ $I->submitForm('#update', ['name' => 'Successful update', 'symbol' => '$', 'code' => 'USD', 'post_submit_action' => 'update']);+ $I->seeRecord('transaction_currencies', ['name' => 'Successful update']);+ resetToClean::clean();++ }++ /**+ * @param FunctionalTester $I+ */+ public function failUpdate(FunctionalTester $I)+ {+ $I->wantTo('update a currency and fail');+ $I->amOnPage('/currency/edit/2');+ $I->see('Edit currency "US Dollar"');+ $I->submitForm('#update', ['name' => 'Failed update', 'code' => '123', 'post_submit_action' => 'update']);+ $I->dontSeeRecord('transaction_currencies', ['name' => 'Failed update']);++ }++ /**+ * @param FunctionalTester $I+ */+ public function validateUpdateOnly(FunctionalTester $I)+ {+ $I->wantTo('update a currency and validate only');+ $I->amOnPage('/currency/edit/2');+ $I->see('Edit currency "US Dollar"');+ $I->submitForm('#update', ['name' => 'Update Validate Only', 'post_submit_action' => 'validate_only']);+ $I->dontSeeRecord('transaction_currencies', ['name' => 'Update Validate Only']);+ $I->seeRecord('transaction_currencies', ['name' => 'US Dollar']);++ }++ /**+ * @param FunctionalTester $I+ */+ public function updateAndReturn(FunctionalTester $I)+ {+ $I->wantTo('update a currency and return to form');+ $I->amOnPage('/currency/edit/2');+ $I->see('Edit currency "US Dollar"');+ $I->submitForm(+ '#update', ['name' => 'US DollarXXX', 'symbol' => '$', 'code' => 'USD', 'post_submit_action' => 'return_to_edit']+ );+ $I->seeRecord('transaction_currencies', ['name' => 'US DollarXXX']);++ }+}\ No newline at end of file