Test consider field sequences.
public function testConsiderFieldSequences() {
$this
->createNodeType('article1', 'Article 1', TRUE, FALSE);
for ($i = 0; $i <= 5; $i++) {
// Create a field.
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_' . $i,
'entity_type' => 'node',
'type' => 'text',
'cardinality' => mt_rand(1, 5),
'translatable' => TRUE,
));
$field_storage
->save();
// Create an instance of the previously created field.
$field = FieldConfig::create(array(
'field_name' => 'field_' . $i,
'entity_type' => 'node',
'bundle' => 'article1',
'label' => 'Field' . $i,
'description' => $this
->randomString(30),
'widget' => array(
'type' => 'text',
'label' => $this
->randomString(10),
),
));
$field
->save();
$this->field_names['node']['article1'][] = 'field_' . $i;
}
$node = $this
->createTranslatableNode('article1', 'en');
\Drupal::service('entity_display.repository')
->getFormDisplay('node', 'article1', 'default')
->setComponent('body', array(
'type' => 'text_textarea_with_summary',
'weight' => 0,
))
->setComponent('title', array(
'type' => 'string_textfield',
'weight' => 1,
))
->setComponent('field_1', array(
'type' => 'string_textfield',
'weight' => 2,
))
->setComponent('field_2', array(
'type' => 'string_textfield',
'weight' => 5,
))
->setComponent('field_0', array(
'type' => 'string_textfield',
'weight' => 6,
))
->setComponent('field_4', array(
'type' => 'string_textfield',
'weight' => 7,
))
->save();
$job = $this
->createJob('en', 'de');
$job->translator = $this->default_translator
->id();
$job
->addItem('content', $node
->getEntityTypeId(), $node
->id());
$job
->save();
$job
->requestTranslation();
// Visit job item review page.
$this
->drupalGet(URL::fromRoute('entity.tmgmt_job_item.canonical', [
'tmgmt_job_item' => $node
->id(),
]));
$review_elements = $this
->xpath('//*[@id="edit-review"]/div');
$ids = [];
foreach ($review_elements as $review_element) {
$ids[] = $review_element
->getAttribute('id');
}
// Check are fields showing on page in desired order. Field 3 and 5 have
// no weight set and are expected to be ordered alphabetically, at the end.
$this
->assertEquals('tmgmt-ui-element-body-wrapper', $ids[0]);
$this
->assertEquals('tmgmt-ui-element-title-wrapper', $ids[1]);
$this
->assertEquals('tmgmt-ui-element-field-1-wrapper', $ids[2]);
$this
->assertEquals('tmgmt-ui-element-field-2-wrapper', $ids[3]);
$this
->assertEquals('tmgmt-ui-element-field-0-wrapper', $ids[4]);
$this
->assertEquals('tmgmt-ui-element-field-4-wrapper', $ids[5]);
$this
->assertEquals('tmgmt-ui-element-field-3-wrapper', $ids[6]);
$this
->assertEquals('tmgmt-ui-element-field-5-wrapper', $ids[7]);
}