mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-09 03:08:09 +00:00
Covered currency controller in tests.
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository;
|
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
|
||||||
*/
|
*/
|
||||||
class CurrencyController extends BaseController
|
class CurrencyController extends BaseController
|
||||||
@@ -46,6 +50,8 @@ class CurrencyController extends BaseController
|
|||||||
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
|
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
|
||||||
$currencyPreference->data = $currency->code;
|
$currencyPreference->data = $currency->code;
|
||||||
$currencyPreference->save();
|
$currencyPreference->save();
|
||||||
|
|
||||||
|
Session::flash('success', $currency->name.' is now the default currency.');
|
||||||
Cache::forget('FFCURRENCYSYMBOL');
|
Cache::forget('FFCURRENCYSYMBOL');
|
||||||
Cache::forget('FFCURRENCYCODE');
|
Cache::forget('FFCURRENCYCODE');
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ class TransactionCurrencySeeder extends Seeder
|
|||||||
{
|
{
|
||||||
DB::table('transaction_currencies')->delete();
|
DB::table('transaction_currencies')->delete();
|
||||||
|
|
||||||
TransactionCurrency::create(
|
TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '€']);
|
||||||
['code' => 'EUR']
|
TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,9 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
|||||||
public function store(array $data)
|
public function store(array $data)
|
||||||
{
|
{
|
||||||
$currency = new \TransactionCurrency($data);
|
$currency = new \TransactionCurrency($data);
|
||||||
|
\Log::debug('Is valid? ' . boolstr($currency->isValid()));
|
||||||
$currency->save();
|
$currency->save();
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
|||||||
$model->symbol = $data['symbol'];
|
$model->symbol = $data['symbol'];
|
||||||
$model->code = $data['code'];
|
$model->code = $data['code'];
|
||||||
$model->name = $data['name'];
|
$model->name = $data['name'];
|
||||||
|
\Log::debug('Is valid? ' . boolstr($model->isValid()));
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -67,11 +70,16 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
|||||||
{
|
{
|
||||||
$warnings = new MessageBag;
|
$warnings = new MessageBag;
|
||||||
$successes = new MessageBag;
|
$successes = new MessageBag;
|
||||||
|
\Log::debug('Now in TransactionCurrency::validate()');
|
||||||
|
|
||||||
$currency = new \TransactionCurrency($model);
|
$currency = new \TransactionCurrency($model);
|
||||||
$currency->isValid();
|
$currency->isValid();
|
||||||
$errors = $currency->getErrors();
|
$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'];
|
$fields = ['name', 'code', 'symbol'];
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if (!$errors->has($field)) {
|
if (!$errors->has($field)) {
|
||||||
|
|||||||
@@ -12,20 +12,10 @@ class TransactionCurrency extends Eloquent
|
|||||||
use SoftDeletingTrait, ValidatingTrait;
|
use SoftDeletingTrait, ValidatingTrait;
|
||||||
|
|
||||||
protected $fillable = ['name', 'symbol', 'code'];
|
protected $fillable = ['name', 'symbol', 'code'];
|
||||||
protected $rules
|
protected $rules = [
|
||||||
= [
|
'code' => 'required|alpha|between:3,3|min:3|max:3',
|
||||||
'creating' => [
|
'name' => 'required|between:3,48|min:3|max:48',
|
||||||
'code' => 'required|min:3|max:3|alpha|unique:transaction_currencies,code',
|
'symbol' => 'required|between:1,8|min:1|max:8',
|
||||||
'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',
|
|
||||||
],
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}
|
{{ 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="row">
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||||
<div class="panel panel-primary">
|
<div class="panel panel-primary">
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class BudgetControllerCest
|
|||||||
{
|
{
|
||||||
$I->wantTo('show all budgets');
|
$I->wantTo('show all budgets');
|
||||||
$I->amOnPage('/budgets');
|
$I->amOnPage('/budgets');
|
||||||
|
$I->see('Budgets');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +148,6 @@ class BudgetControllerCest
|
|||||||
$I->see('Create a new budget');
|
$I->see('Create a new budget');
|
||||||
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'validate_only']);
|
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'validate_only']);
|
||||||
$I->dontSeeRecord('budgets', ['name' => 'New budget.']);
|
$I->dontSeeRecord('budgets', ['name' => 'New budget.']);
|
||||||
resetToClean::clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,7 +160,6 @@ class BudgetControllerCest
|
|||||||
$I->see('Create a new budget');
|
$I->see('Create a new budget');
|
||||||
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'create_another']);
|
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'create_another']);
|
||||||
$I->seeRecord('budgets', ['name' => 'New budget.']);
|
$I->seeRecord('budgets', ['name' => 'New budget.']);
|
||||||
resetToClean::clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,10 +170,11 @@ class BudgetControllerCest
|
|||||||
$I->amOnPage('/budgets/create');
|
$I->amOnPage('/budgets/create');
|
||||||
$I->wantTo('make storing a new budget fail.');
|
$I->wantTo('make storing a new budget fail.');
|
||||||
$I->see('Create a new budget');
|
$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.']);
|
$I->dontSeeRecord('budgets', ['name' => 'New budget.']);
|
||||||
resetToClean::clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FunctionalTester $I
|
* @param FunctionalTester $I
|
||||||
*/
|
*/
|
||||||
|
|||||||
196
tests/functional/CurrencyControllerCest.php
Normal file
196
tests/functional/CurrencyControllerCest.php
Normal file
@@ -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' => 'thegrumpydictator@gmail.com', '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']);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user