1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverStripe\Forms\CurrencyField_Readonly; |
7
|
|
|
use SilverStripe\ORM\FieldType\DBCurrency; |
8
|
|
|
|
9
|
|
|
class CurrencyFieldReadonlyTest extends SapphireTest |
10
|
|
|
{ |
11
|
|
|
public function testPerformReadonlyTransformation() |
12
|
|
|
{ |
13
|
|
|
$field = new CurrencyField_Readonly('Test', '', '$5.00'); |
14
|
|
|
$result = $field->performReadonlyTransformation(); |
15
|
|
|
$this->assertInstanceOf(CurrencyField_Readonly::class, $result); |
16
|
|
|
$this->assertNotSame($result, $field, 'Should return a clone of the field'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testFieldWithValue() |
20
|
|
|
{ |
21
|
|
|
$field = new CurrencyField_Readonly('Test', '', '$5.00'); |
22
|
|
|
$result = $field->Field(); |
23
|
|
|
|
24
|
|
|
$this->assertContains('<input', $result, 'An input should be rendered'); |
25
|
|
|
$this->assertContains('readonly', $result, 'The input should be readonly'); |
26
|
|
|
$this->assertContains('$5.00', $result, 'The value should be rendered'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testFieldWithOutValue() |
30
|
|
|
{ |
31
|
|
|
DBCurrency::config()->update('currency_symbol', 'AUD'); |
32
|
|
|
$field = new CurrencyField_Readonly('Test', '', null); |
33
|
|
|
$result = $field->Field(); |
34
|
|
|
|
35
|
|
|
$this->assertContains('<input', $result, 'An input should be rendered'); |
36
|
|
|
$this->assertContains('readonly', $result, 'The input should be readonly'); |
37
|
|
|
$this->assertContains('AUD0.00', $result, 'The value should be rendered'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @todo: Update the expectation when intl for currencies is implemented |
42
|
|
|
*/ |
43
|
|
|
public function testFieldWithCustomisedCurrencySymbol() |
44
|
|
|
{ |
45
|
|
|
DBCurrency::config()->update('currency_symbol', '€'); |
46
|
|
|
$field = new CurrencyField_Readonly('Test', '', '€5.00'); |
47
|
|
|
$result = $field->Field(); |
48
|
|
|
|
49
|
|
|
$this->assertContains('<input', $result, 'An input should be rendered'); |
50
|
|
|
$this->assertContains('readonly', $result, 'The input should be readonly'); |
51
|
|
|
$this->assertContains('€5.00', $result, 'The value should be rendered'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|