2018-10-20 19:47:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\DefaultFormFactory;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
|
|
|
class DefaultFormFactoryTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testGetFormThrowsExceptionOnMissingContext()
|
|
|
|
{
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessageMatches('/Missing required context/');
|
2018-10-20 19:47:11 +02:00
|
|
|
$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());
|
|
|
|
}
|
|
|
|
}
|