Add tests for DisabledTransformation, PrintableTransformation and PrintableTransformation_TabSet

This commit is contained in:
Robbie Averill 2018-10-20 19:49:21 +02:00
parent 449b2cf291
commit bea4101e21
5 changed files with 84 additions and 4 deletions

View File

@ -19,9 +19,9 @@ class PrintableTransformation_TabSet extends TabSet
public function FieldHolder($properties = array())
{
// This gives us support for sub-tabs.
$tag = ($this->tabSet) ? "h2>" : "h1>";
$tag = $this->getTabSet() ? 'h2>' : 'h1>';
$retVal = '';
foreach ($this->children as $tab) {
foreach ($this->getChildren() as $tab) {
$retVal .= "<$tag" . $tab->Title() . "</$tag\n";
$retVal .= $tab->FieldHolder();
}

View File

@ -106,9 +106,8 @@ class TabSet extends CompositeField
{
if ($this->tabSet) {
return $this->tabSet->ID() . '_' . $this->id . '_set';
} else {
return $this->id;
}
return $this->id;
}
/**

View File

@ -0,0 +1,20 @@
<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\DisabledTransformation;
use SilverStripe\Forms\TextField;
class DisabledTransformationTest extends SapphireTest
{
public function testTransform()
{
$field = new TextField('Test');
$transformation = new DisabledTransformation();
$newField = $transformation->transform($field);
$this->assertTrue($newField->isDisabled(), 'Transformation failed to transform field to be disabled');
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\PrintableTransformation;
use SilverStripe\Forms\PrintableTransformation_TabSet;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
class PrintableTransformationTest extends SapphireTest
{
public function testTransformTabSet()
{
$tab1 = new Tab('Main');
$tab2 = new Tab('Settings');
$tabSet = new TabSet('Root', 'Root', $tab1, $tab2);
$transformation = new PrintableTransformation();
$result = $transformation->transformTabSet($tabSet);
$this->assertInstanceOf(PrintableTransformation_TabSet::class, $result);
$this->assertSame('Root', $result->Title());
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\PrintableTransformation_TabSet;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
class PrintableTransformation_TabSetTest extends SapphireTest
{
public function testFieldHolder()
{
$tabs = [
new Tab('Main'),
new Tab('Secondary'),
$optionsTabSet = new TabSet(
'Options',
'Options',
new Tab('Colours'),
new Tab('Options')
),
];
$transformationTabSet = new PrintableTransformation_TabSet($tabs);
$result = $transformationTabSet->FieldHolder();
$this->assertContains('<h1>Main</h1>', $result);
$this->assertContains('<h1>Secondary</h1>', $result);
$transformationTabSet->setTabSet($optionsTabSet);
$result = $transformationTabSet->FieldHolder();
$this->assertContains('<h2>Options</h2>', $result);
}
}