From 80885fc23111e1ebee9bc1540cabc30c7398555e Mon Sep 17 00:00:00 2001 From: Serge Latyntcev Date: Tue, 20 Nov 2018 14:04:12 +1300 Subject: [PATCH] ADD php test TreeMultiselectField::testEmptyChoiceReadonly --- tests/php/Forms/TreeMultiselectFieldTest.php | 33 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/php/Forms/TreeMultiselectFieldTest.php b/tests/php/Forms/TreeMultiselectFieldTest.php index cbb540c6d..ffff5491f 100644 --- a/tests/php/Forms/TreeMultiselectFieldTest.php +++ b/tests/php/Forms/TreeMultiselectFieldTest.php @@ -10,14 +10,43 @@ class TreeMultiselectFieldTest extends SapphireTest { 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" + + ('none') + +HTML + , + $html + ); + } + public function testReadonly() { $field = new TreeMultiselectField('TestTree', 'Test tree', File::class); + $asdf = $this->objFromFixture(File::class, 'asdf'); $subfolderfile1 = $this->objFromFixture(File::class, 'subfolderfile1'); + $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( <<<"HTML" @@ -25,7 +54,7 @@ class TreeMultiselectFieldTest extends SapphireTest HTML , - (string)$readonlyField->Field() + $html ); } }