diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 896fb80..8b303da 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -88,7 +88,7 @@ function testTextfieldWidgetsFormatted() { */ function testTextfieldWidgetsAllowedFormats() { - // Create one text formats. + // Create one text format. $this->drupalLogin($this->adminUser); $edit = array( 'format' => Unicode::strtolower($this->randomMachineName()), @@ -98,7 +98,7 @@ function testTextfieldWidgetsAllowedFormats() { filter_formats_reset(); $format1 = entity_load('filter_format', $edit['format']); - // Create a second text formats. + // Create a second text format. $edit = array( 'format' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomMachineName(), @@ -115,7 +115,7 @@ function testTextfieldWidgetsAllowedFormats() { $format2->getPermissionName(), )); - // Create a field with only the first format allowed. + // Create a field with multiple formats allowed. $field_name = Unicode::strtolower($this->randomMachineName()); $field_storage = entity_create('field_storage_config', array( 'field_name' => $field_name, @@ -123,12 +123,13 @@ function testTextfieldWidgetsAllowedFormats() { 'type' => 'text', )); $field_storage->save(); - entity_create('field_config', array( + $field = entity_create('field_config', array( 'field_storage' => $field_storage, 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label', - 'settings' => array('allowed_formats' => array($format1->id() => TRUE)), - ))->save(); + 'settings' => array('allowed_formats' => array($format1->id(), $format2->id())), + )); + $field->save(); entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'text_textfield', @@ -139,11 +140,18 @@ function testTextfieldWidgetsAllowedFormats() { ->save(); // Display the creation form. - // We shouldn't have the 'format' selector since only one format is allowed. $this->drupalLogin($this->webUser); $this->drupalGet('entity_test/add'); - $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed'); - $this->assertNoFieldByName("{$field_name}[0][format]", '', 'Format selector is not displayed'); + $this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed'); + $this->assertFieldByName("{$field_name}[0][format]", NULL, 'Format selector is displayed'); + + // Change field to allow only one format. + $field->setSetting('allowed_formats', array($format1->id())); + $field->save(); + // We shouldn't have the 'format' selector since only one format is allowed. + $this->drupalGet('entity_test/add'); + $this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed'); + $this->assertNoFieldByName("{$field_name}[0][format]", NULL, 'Format selector is not displayed'); } /** @@ -187,8 +195,8 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Display the creation form. Since the user only has access to one format, // no format selector will be displayed. $this->drupalGet('entity_test/add'); - $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed'); - $this->assertNoFieldByName("{$field_name}[0][format]", '', 'Format selector is not displayed'); + $this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed'); + $this->assertNoFieldByName("{$field_name}[0][format]", NULL, 'Format selector is not displayed'); // Submit with data that should be filtered. $value = '' . $this->randomMachineName() . '';