mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 00:41:34 -06:00
With a little luck this will cover a lot.
This commit is contained in:
parent
0be5b27d34
commit
596cd09489
@ -35,15 +35,8 @@ class Amount
|
||||
*/
|
||||
public function getCurrencySymbol()
|
||||
{
|
||||
if (defined('FFCURRENCYSYMBOL')) {
|
||||
return FFCURRENCYSYMBOL; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||
|
||||
define('FFCURRENCYSYMBOL', $currency->symbol);
|
||||
|
||||
return $currency->symbol;
|
||||
}
|
||||
|
||||
@ -148,18 +141,12 @@ class Amount
|
||||
*/
|
||||
public function getCurrencyCode()
|
||||
{
|
||||
if (defined('FFCURRENCYCODE')) {
|
||||
return FFCURRENCYCODE; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
||||
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
||||
|
||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||
if ($currency) {
|
||||
|
||||
define('FFCURRENCYCODE', $currency->code);
|
||||
|
||||
return $currency->code;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use Eloquent;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Input;
|
||||
use RuntimeException;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
@ -109,10 +110,17 @@ class ExpandedForm
|
||||
$preFilled = Session::get('preFilled');
|
||||
$value = isset($preFilled[$name]) && is_null($value) ? $preFilled[$name] : $value;
|
||||
}
|
||||
if (!is_null(Input::old($name))) {
|
||||
$value = Input::old($name);
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
if (!is_null(Input::old($name))) {
|
||||
$value = Input::old($name);
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
// don't care about session errors.
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -249,24 +257,6 @@ class ExpandedForm
|
||||
return $selectList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function month($name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$html = View::make('form.month', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param array $list
|
||||
@ -274,7 +264,6 @@ class ExpandedForm
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @internal param null $value
|
||||
*/
|
||||
public function multiRadio($name, array $list = [], $selected = null, array $options = [])
|
||||
{
|
||||
@ -297,7 +286,16 @@ class ExpandedForm
|
||||
*/
|
||||
public function optionsList($type, $name)
|
||||
{
|
||||
$previousValue = Input::old('post_submit_action');
|
||||
$previousValue = null;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$previousValue = Input::old('post_submit_action');
|
||||
} catch (RuntimeException $e) {
|
||||
// don't care
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$previousValue = is_null($previousValue) ? 'store' : $previousValue;
|
||||
$html = View::make('form.options', compact('type', 'name', 'previousValue'))->render();
|
||||
|
||||
|
@ -10,4 +10,10 @@
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
padding: 0px
|
||||
}
|
||||
}
|
||||
.medium {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
a.panel-link {color:#fff;text-decoration: none;}
|
||||
a.panel-link:hover {color:#fff;text-decoration: none;}
|
@ -233,6 +233,7 @@ return [
|
||||
'balanceFor' => 'Balance for :name',
|
||||
|
||||
// piggy banks:
|
||||
'piggy_bank' => 'Piggy bank',
|
||||
'new_piggy_bank' => 'Create new piggy bank',
|
||||
'account_status' => 'Account status',
|
||||
'left_for_piggy_banks' => 'Left for piggy banks',
|
||||
|
@ -170,7 +170,7 @@ return [
|
||||
'Withdrawal' => 'Uitgave',
|
||||
'Deposit' => 'Inkomsten',
|
||||
'Transfer' => 'Overschrijving',
|
||||
'bill' => 'Contracten',
|
||||
'bill' => 'Contract',
|
||||
'yes' => 'Ja',
|
||||
'no' => 'Nee',
|
||||
'amount' => 'Bedrag',
|
||||
@ -242,6 +242,7 @@ return [
|
||||
'balanceFor' => 'Saldo op :name',
|
||||
|
||||
// piggy banks:
|
||||
'piggy_bank' => 'Spaarpotje',
|
||||
'new_piggy_bank' => 'Nieuw spaarpotje',
|
||||
'account_status' => 'Rekeningoverzicht',
|
||||
'left_for_piggy_banks' => 'Over voor spaarpotjes',
|
||||
|
@ -25,6 +25,8 @@ class AmountSupportTest extends TestCase
|
||||
$this->object = new Amount;
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
202
tests/support/ExpandedFormTest.php
Normal file
202
tests/support/ExpandedFormTest.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
use FireflyIII\Support\ExpandedForm;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class ExpandedFormTest
|
||||
*/
|
||||
class ExpandedFormTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ExpandedForm
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->object = new ExpandedForm;
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::amount
|
||||
* @covers FireflyIII\Support\ExpandedForm::label
|
||||
* @covers FireflyIII\Support\ExpandedForm::expandOptionArray
|
||||
* @covers FireflyIII\Support\ExpandedForm::getHolderClasses
|
||||
* @covers FireflyIII\Support\ExpandedForm::fillFieldValue
|
||||
*/
|
||||
public function testAmount()
|
||||
{
|
||||
$result = $this->object->amount('abcde', '12.23', ['label' => 'Some Label']);
|
||||
|
||||
$this->assertTrue(str_contains($result, '23'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::balance
|
||||
* @covers FireflyIII\Support\ExpandedForm::label
|
||||
*/
|
||||
public function testBalance()
|
||||
{
|
||||
$result = $this->object->balance('abcde', '12.23', []);
|
||||
|
||||
$this->assertTrue(str_contains($result, '23'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::checkbox
|
||||
* @covers FireflyIII\Support\ExpandedForm::getHolderClasses
|
||||
*/
|
||||
public function testCheckbox()
|
||||
{
|
||||
// add error to session for this thing:
|
||||
$errors = new MessageBag;
|
||||
$errors->add('abcde', 'Some error here.');
|
||||
$this->session(['errors' => $errors]);
|
||||
|
||||
$result = $this->object->checkbox('abcde', 1, true);
|
||||
|
||||
|
||||
$this->assertTrue(str_contains($result, 'checked="checked"'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::date
|
||||
* @covers FireflyIII\Support\ExpandedForm::fillFieldValue
|
||||
*/
|
||||
public function testDate()
|
||||
{
|
||||
$preFilled = [
|
||||
'abcde' => '1998-01-01'
|
||||
];
|
||||
$this->session(['preFilled' => $preFilled]);
|
||||
|
||||
$result = $this->object->date('abcde');
|
||||
|
||||
$this->assertTrue(str_contains($result, '1998'));
|
||||
$this->assertTrue(str_contains($result, 'type="date"'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::integer
|
||||
*/
|
||||
public function testInteger()
|
||||
{
|
||||
$result = $this->object->integer('abcde', 12345);
|
||||
|
||||
$this->assertTrue(str_contains($result, '12345'));
|
||||
$this->assertTrue(str_contains($result, 'type="number"'));
|
||||
$this->assertTrue(str_contains($result, 'step="1"'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::location
|
||||
*/
|
||||
public function testLocation()
|
||||
{
|
||||
$result = $this->object->location('abcde');
|
||||
|
||||
$this->assertTrue(str_contains($result, 'id="clearLocation"'));
|
||||
$this->assertTrue(str_contains($result, 'id="map-canvas"'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::makeSelectList
|
||||
*/
|
||||
public function testMakeSelectList()
|
||||
{
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push(FactoryMuffin::create('FireflyIII\Models\Account'));
|
||||
}
|
||||
$result = $this->object->makeSelectList($collection, true);
|
||||
|
||||
$this->assertCount(6, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::multiRadio
|
||||
*/
|
||||
public function testMultiRadio()
|
||||
{
|
||||
$list = [
|
||||
'some' => 'BlaBla',
|
||||
'other' => 'ThisIsCool'
|
||||
];
|
||||
|
||||
$result = $this->object->multiRadio('abcde', $list);
|
||||
|
||||
$this->assertTrue(str_contains($result, 'ThisIsCool'));
|
||||
$this->assertTrue(str_contains($result, 'other'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::optionsList
|
||||
*/
|
||||
public function testOptionsList()
|
||||
{
|
||||
$result = $this->object->optionsList('update', 'MotorCycle');
|
||||
$this->assertTrue(str_contains($result, 'MotorCycle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::select
|
||||
*/
|
||||
public function testSelect()
|
||||
{
|
||||
$list = [
|
||||
'some' => 'BlaBla',
|
||||
'other' => 'ThisIsCool'
|
||||
];
|
||||
|
||||
$result = $this->object->select('abcde', $list);
|
||||
$this->assertTrue(str_contains($result, 'ThisIsCool'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::tags
|
||||
*/
|
||||
public function testTags()
|
||||
{
|
||||
$result = $this->object->tags('abcde', 'some,tags');
|
||||
$this->assertTrue(str_contains($result, 'data-role="tagsinput"'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::text
|
||||
*/
|
||||
public function testText()
|
||||
{
|
||||
$result = $this->object->text('abcde', 'MotorBike!');
|
||||
$this->assertTrue(str_contains($result, 'MotorBike!'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Support\ExpandedForm::textarea
|
||||
*/
|
||||
public function testTextarea()
|
||||
{
|
||||
$result = $this->object->textarea('abcde', 'Pillow fight!');
|
||||
$this->assertTrue(str_contains($result, 'Pillow fight!'));
|
||||
$this->assertTrue(str_contains($result, 'abcde_holder'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user