Skip to content
Snippets Groups Projects

fix failing tests for Drupal >= 10.2

Files
3
@@ -97,58 +97,109 @@ class ViewModeSwitchFieldUITest extends ViewModeSwitchTestBase {
}
/**
* Tests the view mode switch field settings forms.
* Tests the view mode switch field settings form.
*/
public function testFieldSettingsForms(): void {
public function testFieldSettingsForm(): void {
$this->drupalLogin($this->adminUser);
$assert = $this->assertSession();
$type_path = 'entity_test/structure/entity_test';
// Test view mode switch field storage settings form.
$this->drupalGet($type_path . '/fields/entity_test.entity_test.' . $this->field->getName() . '/storage');
// Test that field cardinality is not configurable.
$assert->fieldNotExists('cardinality_number');
// Test origin view modes.
$assert->fieldExists('settings[origin_view_modes][default]');
$assert->checkboxNotChecked('settings[origin_view_modes][default]');
$assert->fieldExists('settings[origin_view_modes][full]');
$assert->checkboxNotChecked('settings[origin_view_modes][full]');
$assert->fieldExists('settings[origin_view_modes][origin1]');
$assert->checkboxChecked('settings[origin_view_modes][origin1]');
$assert->fieldExists('settings[origin_view_modes][origin2]');
$assert->checkboxNotChecked('settings[origin_view_modes][origin2]');
$assert->fieldExists('settings[origin_view_modes][switch1]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch1]');
$assert->fieldExists('settings[origin_view_modes][switch2]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch2]');
$assert->fieldExists('settings[origin_view_modes][switch3]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch3]');
$assert->fieldExists('settings[origin_view_modes][switch4]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch4]');
$assert->fieldExists('settings[origin_view_modes][test]');
$assert->checkboxChecked('settings[origin_view_modes][test]');
// Test view mode switch field settings form.
$this->drupalGet($type_path . '/fields/entity_test.entity_test.' . $this->field->getName());
// Test allowed view modes.
$assert->fieldExists('settings[allowed_view_modes][full]');
$assert->checkboxNotChecked('settings[allowed_view_modes][full]');
$assert->fieldExists('settings[allowed_view_modes][origin2]');
$assert->checkboxNotChecked('settings[allowed_view_modes][origin2]');
$assert->fieldExists('settings[allowed_view_modes][switch1]');
$assert->checkboxChecked('settings[allowed_view_modes][switch1]');
$assert->fieldExists('settings[allowed_view_modes][switch2]');
$assert->checkboxChecked('settings[allowed_view_modes][switch2]');
$assert->fieldExists('settings[allowed_view_modes][switch3]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch3]');
$assert->fieldExists('settings[allowed_view_modes][switch4]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch4]');
// Test no allowed view mode options exist for 'default' and configured
// origin view modes.
$assert->fieldNotExists('settings[allowed_view_modes][default]');
$assert->fieldNotExists('settings[allowed_view_modes][origin1]');
$assert->fieldNotExists('settings[allowed_view_modes][test]');
// Tests for Drupal >= 10.2. due to restructured field settings form.
// @see https://www.drupal.org/node/3386675
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
// Test view mode switch field settings form.
$this->drupalGet($type_path . '/fields/entity_test.entity_test.' . $this->field->getName());
// Test that field cardinality is not configurable.
$assert->fieldNotExists('cardinality_number');
// Test origin view modes.
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][default]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][default]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][full]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][full]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][origin1]');
$assert->checkboxChecked('field_storage[subform][settings][origin_view_modes][origin1]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][origin2]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][origin2]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][switch1]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][switch1]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][switch2]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][switch2]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][switch3]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][switch3]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][switch4]');
$assert->checkboxNotChecked('field_storage[subform][settings][origin_view_modes][switch4]');
$assert->fieldExists('field_storage[subform][settings][origin_view_modes][test]');
$assert->checkboxChecked('field_storage[subform][settings][origin_view_modes][test]');
// Test allowed view modes.
$assert->fieldExists('settings[allowed_view_modes][full]');
$assert->checkboxNotChecked('settings[allowed_view_modes][full]');
$assert->fieldExists('settings[allowed_view_modes][origin2]');
$assert->checkboxNotChecked('settings[allowed_view_modes][origin2]');
$assert->fieldExists('settings[allowed_view_modes][switch1]');
$assert->checkboxChecked('settings[allowed_view_modes][switch1]');
$assert->fieldExists('settings[allowed_view_modes][switch2]');
$assert->checkboxChecked('settings[allowed_view_modes][switch2]');
$assert->fieldExists('settings[allowed_view_modes][switch3]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch3]');
$assert->fieldExists('settings[allowed_view_modes][switch4]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch4]');
// Test no allowed view mode options exist for 'default' and configured
// origin view modes.
$assert->fieldNotExists('settings[allowed_view_modes][default]');
$assert->fieldNotExists('settings[allowed_view_modes][origin1]');
$assert->fieldNotExists('settings[allowed_view_modes][test]');
}
// @todo Remove tests for Drupal < 10.2 when module requires Drupal >= 10.2.
// Tests for Drupal < 10.2.
else {
// Test view mode switch field storage settings form.
$this->drupalGet($type_path . '/fields/entity_test.entity_test.' . $this->field->getName() . '/storage');
// Test that field cardinality is not configurable.
$assert->fieldNotExists('cardinality_number');
// Test origin view modes.
$assert->fieldExists('settings[origin_view_modes][default]');
$assert->checkboxNotChecked('settings[origin_view_modes][default]');
$assert->fieldExists('settings[origin_view_modes][full]');
$assert->checkboxNotChecked('settings[origin_view_modes][full]');
$assert->fieldExists('settings[origin_view_modes][origin1]');
$assert->checkboxChecked('settings[origin_view_modes][origin1]');
$assert->fieldExists('settings[origin_view_modes][origin2]');
$assert->checkboxNotChecked('settings[origin_view_modes][origin2]');
$assert->fieldExists('settings[origin_view_modes][switch1]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch1]');
$assert->fieldExists('settings[origin_view_modes][switch2]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch2]');
$assert->fieldExists('settings[origin_view_modes][switch3]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch3]');
$assert->fieldExists('settings[origin_view_modes][switch4]');
$assert->checkboxNotChecked('settings[origin_view_modes][switch4]');
$assert->fieldExists('settings[origin_view_modes][test]');
$assert->checkboxChecked('settings[origin_view_modes][test]');
// Test view mode switch field settings form.
$this->drupalGet($type_path . '/fields/entity_test.entity_test.' . $this->field->getName());
// Test allowed view modes.
$assert->fieldExists('settings[allowed_view_modes][full]');
$assert->checkboxNotChecked('settings[allowed_view_modes][full]');
$assert->fieldExists('settings[allowed_view_modes][origin2]');
$assert->checkboxNotChecked('settings[allowed_view_modes][origin2]');
$assert->fieldExists('settings[allowed_view_modes][switch1]');
$assert->checkboxChecked('settings[allowed_view_modes][switch1]');
$assert->fieldExists('settings[allowed_view_modes][switch2]');
$assert->checkboxChecked('settings[allowed_view_modes][switch2]');
$assert->fieldExists('settings[allowed_view_modes][switch3]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch3]');
$assert->fieldExists('settings[allowed_view_modes][switch4]');
$assert->checkboxNotChecked('settings[allowed_view_modes][switch4]');
// Test no allowed view mode options exist for 'default' and configured
// origin view modes.
$assert->fieldNotExists('settings[allowed_view_modes][default]');
$assert->fieldNotExists('settings[allowed_view_modes][origin1]');
$assert->fieldNotExists('settings[allowed_view_modes][test]');
}
}
/**
Loading