mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Add tests for DisabledTransformation, PrintableTransformation and PrintableTransformation_TabSet
This commit is contained in:
parent
449b2cf291
commit
bea4101e21
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
20
tests/php/Forms/DisabledTransformationTest.php
Normal file
20
tests/php/Forms/DisabledTransformationTest.php
Normal 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');
|
||||
}
|
||||
}
|
25
tests/php/Forms/PrintableTransformationTest.php
Normal file
25
tests/php/Forms/PrintableTransformationTest.php
Normal 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());
|
||||
}
|
||||
}
|
36
tests/php/Forms/PrintableTransformation_TabSetTest.php
Normal file
36
tests/php/Forms/PrintableTransformation_TabSetTest.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user