2018-10-20 17:41:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\CurrencyField_Readonly;
|
|
|
|
use SilverStripe\ORM\FieldType\DBCurrency;
|
|
|
|
|
2018-11-10 13:55:11 +01:00
|
|
|
class CurrencyFieldReadonlyTest extends SapphireTest
|
2018-10-20 17:41:41 +02:00
|
|
|
{
|
|
|
|
public function testPerformReadonlyTransformation()
|
|
|
|
{
|
|
|
|
$field = new CurrencyField_Readonly('Test', '', '$5.00');
|
|
|
|
$result = $field->performReadonlyTransformation();
|
|
|
|
$this->assertInstanceOf(CurrencyField_Readonly::class, $result);
|
|
|
|
$this->assertNotSame($result, $field, 'Should return a clone of the field');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFieldWithValue()
|
|
|
|
{
|
|
|
|
$field = new CurrencyField_Readonly('Test', '', '$5.00');
|
|
|
|
$result = $field->Field();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<input', $result, 'An input should be rendered');
|
|
|
|
$this->assertStringContainsString('readonly', $result, 'The input should be readonly');
|
|
|
|
$this->assertStringContainsString('$5.00', $result, 'The value should be rendered');
|
2018-10-20 17:41:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFieldWithOutValue()
|
|
|
|
{
|
2022-11-15 06:20:54 +01:00
|
|
|
DBCurrency::config()->set('currency_symbol', 'AUD');
|
2018-10-20 17:41:41 +02:00
|
|
|
$field = new CurrencyField_Readonly('Test', '', null);
|
|
|
|
$result = $field->Field();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<input', $result, 'An input should be rendered');
|
|
|
|
$this->assertStringContainsString('readonly', $result, 'The input should be readonly');
|
|
|
|
$this->assertStringContainsString('AUD0.00', $result, 'The value should be rendered');
|
2018-10-20 17:41:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo: Update the expectation when intl for currencies is implemented
|
|
|
|
*/
|
|
|
|
public function testFieldWithCustomisedCurrencySymbol()
|
|
|
|
{
|
2022-11-15 06:20:54 +01:00
|
|
|
DBCurrency::config()->set('currency_symbol', '€');
|
2018-10-20 17:41:41 +02:00
|
|
|
$field = new CurrencyField_Readonly('Test', '', '€5.00');
|
|
|
|
$result = $field->Field();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<input', $result, 'An input should be rendered');
|
|
|
|
$this->assertStringContainsString('readonly', $result, 'The input should be readonly');
|
|
|
|
$this->assertStringContainsString('€5.00', $result, 'The value should be rendered');
|
2018-10-20 17:41:41 +02:00
|
|
|
}
|
|
|
|
}
|