Files
monica/tests/Helper/MoneyHelperTest.php
T
Rocco PalladinoandRégis Freyd 158b5326fb Format monetary values with currency symbols consistently (#394)
Fix #332 

- Add a MoneyHelper class, with a unit test
- Alias MoneyHelper to be available in global namespace in templates
- Remove hardcoded '$' from translation files
- Modify templates to use MoneyHelper to format debt and gift amounts
- Fix Tests\TestCase constructor to accept arguments of original
implementation
2017-06-26 08:09:55 -04:00

44 lines
1.1 KiB
PHP

<?php
namespace Tests\Helper;
use App\Currency;
use App\User;
use App\Helpers\MoneyHelper;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MoneyHelperTest extends TestCase
{
use DatabaseTransactions;
public function testFormatReturnsAmountWithCurrencySymbol()
{
$currency = new Currency();
$currency->symbol = "€";
$this->assertEquals('€500', MoneyHelper::format(500, $currency));
}
public function testFormatUsesCurrencySettingIfDefined()
{
$currency = Currency::where('iso', 'GBP')->first();
$user = factory(User::class)->create([
'currency_id' => $currency->id
]);
$this->actingAs($user);
$this->assertEquals('£75', MoneyHelper::format(75));
}
public function testFormatReturnsAmountWithoutSymbolIfCurrencyIsUndefined()
{
$this->assertEquals('500', MoneyHelper::format(500));
}
public function testFormatReturnsZeroIfAmountIsNull()
{
$this->assertEquals('0', MoneyHelper::format(null));
}
}