mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Add tests for DefaultFormFactory
This commit is contained in:
parent
fd50ce6295
commit
449b2cf291
@ -30,6 +30,7 @@ class DefaultFormFactory implements FormFactory
|
||||
* @param string $name
|
||||
* @param array $context
|
||||
* @return Form
|
||||
* @throws InvalidArgumentException When required context is missing
|
||||
*/
|
||||
public function getForm(RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = [])
|
||||
{
|
||||
|
38
tests/php/Forms/DefaultFormFactoryTest.php
Normal file
38
tests/php/Forms/DefaultFormFactoryTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\DefaultFormFactory;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
class DefaultFormFactoryTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /Missing required context/
|
||||
*/
|
||||
public function testGetFormThrowsExceptionOnMissingContext()
|
||||
{
|
||||
$factory = new DefaultFormFactory();
|
||||
$factory->getForm();
|
||||
}
|
||||
|
||||
public function testGetForm()
|
||||
{
|
||||
$record = new DataObject();
|
||||
$record->Title = 'Test';
|
||||
|
||||
$factory = new DefaultFormFactory();
|
||||
$form = $factory->getForm(null, null, ['Record' => $record]);
|
||||
|
||||
$this->assertSame($record, $form->getRecord());
|
||||
}
|
||||
|
||||
public function testGetRequiredContext()
|
||||
{
|
||||
$factory = new DefaultFormFactory();
|
||||
$this->assertContains('Record', $factory->getRequiredContext());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user