3 namespace Drupal\Tests\field\FunctionalJavascript\Boolean;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
10 * Tests the Boolean field formatter settings.
14 class BooleanFormatterSettingsTest extends WebDriverTestBase {
21 public static $modules = ['field', 'field_ui', 'text', 'node', 'user'];
24 * The name of the entity bundle that is created in the test.
31 * The name of the Boolean field to use for testing.
40 protected function setUp() {
43 // Create a content type. Use Node because it has Field UI pages that work.
44 $type_name = mb_strtolower($this->randomMachineName(8)) . '_test';
45 $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
46 $this->bundle = $type->id();
48 $admin_user = $this->drupalCreateUser([
50 'administer content types',
51 'administer node fields',
52 'administer node display',
56 $this->drupalLogin($admin_user);
58 $this->fieldName = mb_strtolower($this->randomMachineName(8));
60 $field_storage = FieldStorageConfig::create([
61 'field_name' => $this->fieldName,
62 'entity_type' => 'node',
65 $field_storage->save();
67 $instance = FieldConfig::create([
68 'field_storage' => $field_storage,
69 'bundle' => $this->bundle,
70 'label' => $this->randomMachineName(),
74 $display = entity_get_display('node', $this->bundle, 'default')
75 ->setComponent($this->fieldName, [
83 * Tests the formatter settings page for the Boolean formatter.
85 public function testBooleanFormatterSettings() {
86 // List the options we expect to see on the settings form. Omit the one
87 // with the Unicode check/x characters, which does not appear to work
88 // well in WebTestBase.
98 // For several different values of the field settings, test that the
99 // options, including default, are shown correctly.
106 $assert_session = $this->assertSession();
107 foreach ($settings as $values) {
108 // Set up the field settings.
109 $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
110 $this->drupalPostForm(NULL, [
111 'settings[on_label]' => $values[0],
112 'settings[off_label]' => $values[1],
113 ], t('Save settings'));
115 // Open the Manage Display page and trigger the field settings form.
116 $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
117 $this->getSession()->getPage()->pressButton($this->fieldName . '_settings_edit');
118 $assert_session->waitForElement('css', '.ajax-new-content');
120 // Test that the settings options are present in the correct format.
121 foreach ($options as $string) {
122 $assert_session->pageTextContains($string);
124 $assert_session->pageTextContains(t('Field settings (@on_label / @off_label)', ['@on_label' => $values[0], '@off_label' => $values[1]]));