ADD php test TreeMultiselectField::testEmptyChoiceReadonly

This commit is contained in:
Serge Latyntcev 2018-11-20 14:04:12 +13:00
parent 15aaf9db9f
commit 80885fc231

View File

@ -10,14 +10,43 @@ class TreeMultiselectFieldTest extends SapphireTest
{ {
protected static $fixture_file = 'TreeDropdownFieldTest.yml'; protected static $fixture_file = 'TreeDropdownFieldTest.yml';
public function testEmptyChoiceReadonly()
{
$field = new TreeMultiselectField('TestTree', 'Test tree', File::class);
$asdf = $this->objFromFixture(File::class, 'asdf');
$subfolderfile1 = $this->objFromFixture(File::class, 'subfolderfile1');
$schemaStateDefaults = $field->getSchemaStateDefaults();
$this->assertArraySubset(['id' => 'TestTree', 'name' => 'TestTree', 'value' => 'unchanged'], $schemaStateDefaults, $strict = true);
$html = $field->performReadonlyTransformation()->Field();
$this->assertEquals(
<<<"HTML"
<span id="TestTree_ReadonlyValue" class="readonly">
<i>('none')</i>
</span><input type="hidden" name="TestTree" class="hidden" id="TestTree" />
HTML
,
$html
);
}
public function testReadonly() public function testReadonly()
{ {
$field = new TreeMultiselectField('TestTree', 'Test tree', File::class); $field = new TreeMultiselectField('TestTree', 'Test tree', File::class);
$asdf = $this->objFromFixture(File::class, 'asdf'); $asdf = $this->objFromFixture(File::class, 'asdf');
$subfolderfile1 = $this->objFromFixture(File::class, 'subfolderfile1'); $subfolderfile1 = $this->objFromFixture(File::class, 'subfolderfile1');
$field->setValue(implode(',', [$asdf->ID, $subfolderfile1->ID])); $field->setValue(implode(',', [$asdf->ID, $subfolderfile1->ID]));
$readonlyField = $field->performReadonlyTransformation(); $schemaStateDefaults = $field->getSchemaStateDefaults();
$this->assertArraySubset(['id' => 'TestTree', 'name' => 'TestTree', 'value' => [$asdf->ID, $subfolderfile1->ID]], $schemaStateDefaults, $strict = true);
$html = (string)$field->performReadonlyTransformation()->Field();
$this->assertEquals( $this->assertEquals(
<<<"HTML" <<<"HTML"
<span id="TestTree_ReadonlyValue" class="readonly"> <span id="TestTree_ReadonlyValue" class="readonly">
@ -25,7 +54,7 @@ class TreeMultiselectFieldTest extends SapphireTest
</span><input type="hidden" name="TestTree" value="{$asdf->ID},{$subfolderfile1->ID}" class="hidden" id="TestTree" /> </span><input type="hidden" name="TestTree" value="{$asdf->ID},{$subfolderfile1->ID}" class="hidden" id="TestTree" />
HTML HTML
, ,
(string)$readonlyField->Field() $html
); );
} }
} }