function EntityDisplayModeTest::testAlphabeticalDisplaySettings
Same name and namespace in other branches
- 11.x core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php \Drupal\Tests\field_ui\Functional\EntityDisplayModeTest::testAlphabeticalDisplaySettings()
- 10 core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php \Drupal\Tests\field_ui\Functional\EntityDisplayModeTest::testAlphabeticalDisplaySettings()
- 9 core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php \Drupal\Tests\field_ui\Functional\EntityDisplayModeTest::testAlphabeticalDisplaySettings()
- 8.9.x core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php \Drupal\Tests\field_ui\Functional\EntityDisplayModeTest::testAlphabeticalDisplaySettings()
Tests if view modes appear in alphabetical order by visible name.
The machine name should not be used for sorting.
See also
https://www.drupal.org/node/2858569
File
-
core/
modules/ field_ui/ tests/ src/ Functional/ EntityDisplayModeTest.php, line 168
Class
- EntityDisplayModeTest
- Tests the entity display modes UI.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public function testAlphabeticalDisplaySettings() : void {
$this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'administer content types',
'administer display modes',
'administer nodes',
'administer node fields',
'administer node display',
'administer node form display',
'view the administration theme',
]));
// Enable "Full content" view mode for testing.
$display = \Drupal::entityTypeManager()->getStorage('entity_view_display')
->create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'full',
'status' => TRUE,
]);
$display->save();
$this->drupalGet('admin/structure/types/manage/article/display');
// Verify that the order of view modes is alphabetical by visible label.
// Since the default view modes all have machine names which coincide with
// the English labels, they should appear in alphabetical order, by default
// if viewing the site in English and if no changes have been made. We will
// verify this first.
$enabled_text = $this->getSession()
->getPage()
->find('css', '#enabled-display-modes-wrapper')
->getText();
$start = strpos($enabled_text, 'Display mode') ?: 0;
$pos = $start;
$enabled_list = [
'Full content',
'Teaser',
];
foreach ($enabled_list as $name) {
$new_pos = strpos($enabled_text, $name, $start);
$this->assertGreaterThan($pos, $new_pos, "View mode '{$name}' should appear after the previous one in alphabetical order in enabled table. Previous position: {$pos}, current position: {$new_pos}");
$pos = $new_pos;
}
$disabled_text = $this->getSession()
->getPage()
->find('css', '#disabled-display-modes-wrapper')
->getText();
$start = strpos($disabled_text, 'Display mode') ?: 0;
$pos = $start;
$disabled_list = [
'RSS',
'Search index',
'Search result',
];
foreach ($disabled_list as $name) {
$new_pos = strpos($disabled_text, $name, $start);
$this->assertGreaterThan($pos, $new_pos, "View mode '{$name}' should appear after the previous one in alphabetical order in disabled table. Previous position: {$pos}, current position: {$new_pos}");
$pos = $new_pos;
}
// Now that we have verified the original display order, we can change the
// label for one of the view modes. If we rename "Teaser" to "Breezier", it
// should appear as the first of the listed view modes:
// Set new values and enable test plugins.
$edit = [
'label' => 'Breezier',
];
$this->drupalGet('admin/structure/display-modes/view/manage/node.teaser');
$this->submitForm($edit, 'Save');
$this->assertSession()
->pageTextContains('Saved the Breezier view mode.');
// Re-open the display settings for the article content type and verify
// that changing "Teaser" to "Breezier" makes it appear before "Full
// content".
$this->drupalGet('admin/structure/types/manage/article/display');
$enabled_text = $this->getSession()
->getPage()
->find('css', '#enabled-display-modes-wrapper')
->getText();
$start = strpos($enabled_text, 'Display mode') ?: 0;
$pos = $start;
$enabled_list = [
'Breezier',
'Full content',
];
foreach ($enabled_list as $name) {
$new_pos = strpos($enabled_text, $name, $start);
$this->assertGreaterThan($pos, $new_pos, "View mode '{$name}' should appear after the previous one in alphabetical order in enabled table. Previous position: {$pos}, current position: {$new_pos}");
$pos = $new_pos;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.