public function ComponentFormTest::testCompoundProperties in Module Builder 8.3
Tests the handling of compound properties.
File
- tests/
src/ Functional/ ComponentFormTest.php, line 170
Class
- ComponentFormTest
- Tests the component edit form.
Namespace
Drupal\Tests\module_builder\FunctionalCode
public function testCompoundProperties() {
$web_assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('/admin/config/development/test_component/manage/my_component/misc');
$page
->pressButton('Add a Compound empty item');
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][0][one]',
]);
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][0][two]',
]);
$page
->pressButton('Add another Compound empty item');
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][1][one]',
]);
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][1][two]',
]);
$page
->pressButton('Remove last item');
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][0][one]',
]);
$web_assert
->elementExists('named_exact', [
'id_or_name',
'module[compound_empty][0][two]',
]);
$web_assert
->elementNotExists('named_exact', [
'id_or_name',
'module[compound_empty][1][one]',
]);
$web_assert
->elementNotExists('named_exact', [
'id_or_name',
'module[compound_empty][1][two]',
]);
// Fill in the one compound item and submit the form.
$page
->fillField('module[compound_empty][0][one]', 'value one');
$page
->fillField('module[compound_empty][0][two]', 'value two');
$page
->pressButton('Save');
$this->testComponentStorage
->resetCache();
$component = $this->testComponentStorage
->load('my_component');
$this
->assertEquals('value one', $component->data['compound_empty'][0]['one']);
$this
->assertEquals('value two', $component->data['compound_empty'][0]['two']);
$this
->assertArrayNotHasKey(1, $component->data['compound_empty']);
// Remove the item we saved, and save again: it should be removed from the
// module.
$page
->pressButton('Remove last item');
$page
->pressButton('Save');
// ARRRRRGH. See same problem above.
$configs = $this->container
->get('config.factory')
->loadMultiple([
'module_builder_test_component_type.test_component.my_component',
]);
$config = reset($configs);
$read = $config
->getStorage()
->read('module_builder_test_component_type.test_component.my_component');
// $component = new \Drupal\module_builder_test_component_type\Entity\($read, $this->entityTypeId);
$entity_class = $this->entityTypeManager
->getDefinition('test_component')
->getClass();
$component = new $entity_class($read, 'test_component');
$this
->assertArrayNotHasKey('compound_empty', $component->data);
}