Change DBCurrency scaffolded form field to CurrencyField (fixes #8246)

Add test ensuring DBCurrency scaffolds CurrencyField
This commit is contained in:
Harsh Chokshi 2018-07-06 11:59:28 +12:00
parent e4d1cf8818
commit 6af736a9e1
2 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,8 @@
namespace SilverStripe\ORM\FieldType;
use SilverStripe\Forms\CurrencyField;
/**
* Represents a decimal field containing a currency amount.
* The currency class only supports single currencies. For multi-currency support, use {@link Money}
@ -67,4 +69,15 @@ class DBCurrency extends DBDecimal
return $this;
}
/**
* @param string $title
* @param array $params
*
* @return CurrencyField
*/
public function scaffoldFormField($title = null, $params = null)
{
return CurrencyField::create($this->getName(), $title);
}
}

View File

@ -2,6 +2,7 @@
namespace SilverStripe\ORM\Tests;
use SilverStripe\Forms\CurrencyField;
use SilverStripe\ORM\FieldType\DBCurrency;
use SilverStripe\Dev\SapphireTest;
@ -41,4 +42,13 @@ class DBCurrencyTest extends SapphireTest
$this->assertEquals($niceValues[1], $c->Whole());
}
}
public function testScaffoldedField()
{
// Test DBCurrency scaffolds a CurrencyField
$currencyDbField = DBCurrency::create('Currency');
$scaffoldedField = $currencyDbField->scaffoldFormField();
$this->assertInstanceOf(CurrencyField::class, $scaffoldedField);
}
}