Merge pull request #8247 from hchokshi/pulls/4/dbcurrency-scaffold-currency-field

Change DBCurrency scaffolded form field to CurrencyField (fixes #8246)
This commit is contained in:
Daniel Hensby 2018-07-10 11:24:27 +01:00 committed by GitHub
commit 6e00d90783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}