public function HideWeightFieldFunctionalTest::testReordering in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x tests/src/Functional/HideWeightFieldFunctionalTest.php \Drupal\Tests\entity_hierarchy\Functional\HideWeightFieldFunctionalTest::testReordering()
Tests ordered storage in nested set tables.
File
- tests/
src/ Functional/ HideWeightFieldFunctionalTest.php, line 52
Class
- HideWeightFieldFunctionalTest
- Defines a class for testing the ability to hide the weight field.
Namespace
Drupal\Tests\entity_hierarchy\FunctionalCode
public function testReordering() {
$this
->drupalLogin($this
->drupalCreateUser([], NULL, TRUE));
$this
->drupalGet('/entity_test/add');
$assert = $this
->assertSession();
$assert
->fieldExists('parents[0][weight]');
// Change the field to hide the weight field.
$field = FieldConfig::load("entity_test.entity_test.parents");
$this
->getEntityFormDisplay(self::ENTITY_TYPE, self::ENTITY_TYPE, 'default')
->setComponent(self::FIELD_NAME, [
'type' => 'entity_reference_hierarchy_autocomplete',
'weight' => 20,
'settings' => [
'hide_weight' => TRUE,
] + EntityReferenceHierarchyAutocomplete::defaultSettings(),
])
->save();
$field
->setSetting('hide_weight', TRUE);
$field
->save();
$this
->drupalGet('/entity_test/add');
$assert
->fieldNotExists('parents[0][weight]');
// Submit the form.
$name = $this
->randomMachineName();
$this
->submitForm([
'parents[0][target_id][target_id]' => sprintf('%s (%s)', $this->parent
->label(), $this->parent
->id()),
'name[0][value]' => $name,
], 'Save');
$saved = $this->container
->get('entity_type.manager')
->getStorage('entity_test')
->loadByProperties([
'name' => $name,
]);
$this
->assertCount(1, $saved);
}