2016-12-16 05:34:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\Tests\FormFactoryTest\TestController;
|
|
|
|
use SilverStripe\Forms\Tests\FormFactoryTest\TestObject;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\FormAction;
|
|
|
|
use SilverStripe\Forms\HiddenField;
|
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Forms\TextField;
|
2017-03-21 04:22:23 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
class FormFactoryTest extends SapphireTest
|
|
|
|
{
|
2017-03-24 12:17:26 +01:00
|
|
|
protected static $extra_dataobjects = [
|
2016-12-16 05:34:21 +01:00
|
|
|
TestObject::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
protected static $fixture_file = 'FormFactoryTest.yml';
|
|
|
|
|
2017-03-24 12:17:26 +01:00
|
|
|
protected static function getExtraDataObjects()
|
2017-03-21 04:22:23 +01:00
|
|
|
{
|
|
|
|
// Prevent setup breaking if versioned module absent
|
|
|
|
if (class_exists(Versioned::class)) {
|
|
|
|
return parent::getExtraDataObjects();
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Note: Soft support for versioned module optionality
|
|
|
|
if (!class_exists(Versioned::class)) {
|
|
|
|
$this->markTestSkipped('FormFactoryTest requires the Versioned extension');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Test versioned form
|
|
|
|
*/
|
|
|
|
public function testVersionedForm()
|
|
|
|
{
|
|
|
|
$controller = new TestController();
|
|
|
|
$form = $controller->Form();
|
|
|
|
|
|
|
|
// Check formfields
|
|
|
|
$this->assertInstanceOf(TextField::class, $form->Fields()->fieldByName('Title'));
|
|
|
|
$this->assertInstanceOf(HiddenField::class, $form->Fields()->fieldByName('ID'));
|
|
|
|
$this->assertInstanceOf(HiddenField::class, $form->Fields()->fieldByName('SecurityID'));
|
|
|
|
|
|
|
|
|
|
|
|
// Check preview link
|
2017-03-21 04:22:23 +01:00
|
|
|
/** @var LiteralField $previewLink */
|
2016-12-16 05:34:21 +01:00
|
|
|
$previewLink = $form->Fields()->fieldByName('PreviewLink');
|
|
|
|
$this->assertInstanceOf(LiteralField::class, $previewLink);
|
|
|
|
$this->assertEquals(
|
|
|
|
'<a href="FormFactoryTest_TestController/preview/" rel="external" target="_blank">Preview</a>',
|
|
|
|
$previewLink->getContent()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check actions
|
|
|
|
$this->assertInstanceOf(FormAction::class, $form->Actions()->fieldByName('action_save'));
|
|
|
|
$this->assertInstanceOf(FormAction::class, $form->Actions()->fieldByName('action_publish'));
|
|
|
|
$this->assertTrue($controller->hasAction('publish'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removing versioning from an object should result in a simpler form
|
|
|
|
*/
|
|
|
|
public function testBasicForm()
|
|
|
|
{
|
|
|
|
TestObject::remove_extension(Versioned::class);
|
|
|
|
$controller = new TestController();
|
|
|
|
$form = $controller->Form();
|
|
|
|
|
|
|
|
// Check formfields
|
|
|
|
$this->assertInstanceOf(TextField::class, $form->Fields()->fieldByName('Title'));
|
|
|
|
$this->assertNull($form->Fields()->fieldByName('PreviewLink'));
|
|
|
|
|
|
|
|
// Check actions
|
|
|
|
$this->assertInstanceOf(FormAction::class, $form->Actions()->fieldByName('action_save'));
|
|
|
|
$this->assertNull($form->Actions()->fieldByName('action_publish'));
|
|
|
|
}
|
|
|
|
}
|