Chris@17: drupalCreateContentType(['type' => 'article']); Chris@17: $this->drupalLogin($this->drupalCreateUser([ Chris@17: 'create article content', Chris@17: 'edit own article content', Chris@17: ])); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Test the behavior of a field module after being disabled and re-enabled. Chris@17: * Chris@17: * @see field_system_info_alter() Chris@17: */ Chris@17: public function testReEnabledField() { Chris@17: Chris@17: // Add a telephone field to the article content type. Chris@17: $field_storage = FieldStorageConfig::create([ Chris@17: 'field_name' => 'field_telephone', Chris@17: 'entity_type' => 'node', Chris@17: 'type' => 'telephone', Chris@17: ]); Chris@17: $field_storage->save(); Chris@17: FieldConfig::create([ Chris@17: 'field_storage' => $field_storage, Chris@17: 'bundle' => 'article', Chris@17: 'label' => 'Telephone Number', Chris@17: ])->save(); Chris@17: Chris@17: entity_get_form_display('node', 'article', 'default') Chris@17: ->setComponent('field_telephone', [ Chris@17: 'type' => 'telephone_default', Chris@17: 'settings' => [ Chris@17: 'placeholder' => '123-456-7890', Chris@17: ], Chris@17: ]) Chris@17: ->save(); Chris@17: Chris@17: entity_get_display('node', 'article', 'default') Chris@17: ->setComponent('field_telephone', [ Chris@17: 'type' => 'telephone_link', Chris@17: 'weight' => 1, Chris@17: ]) Chris@17: ->save(); Chris@17: Chris@17: // Display the article node form and verify the telephone widget is present. Chris@17: $this->drupalGet('node/add/article'); Chris@17: $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.'); Chris@17: Chris@17: // Submit an article node with a telephone field so data exist for the Chris@17: // field. Chris@17: $edit = [ Chris@17: 'title[0][value]' => $this->randomMachineName(), Chris@17: 'field_telephone[0][value]' => "123456789", Chris@17: ]; Chris@17: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@17: $this->assertRaw(''); Chris@17: Chris@17: // Test that the module can't be uninstalled from the UI while there is data Chris@17: // for its fields. Chris@17: $admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules']); Chris@17: $this->drupalLogin($admin_user); Chris@17: $this->drupalGet('admin/modules/uninstall'); Chris@17: $this->assertText("The Telephone number field type is used in the following field: node.field_telephone"); Chris@17: Chris@17: // Add another telephone field to a different entity type in order to test Chris@17: // the message for the case when multiple fields are blocking the Chris@17: // uninstallation of a module. Chris@17: $field_storage2 = entity_create('field_storage_config', [ Chris@17: 'field_name' => 'field_telephone_2', Chris@17: 'entity_type' => 'user', Chris@17: 'type' => 'telephone', Chris@17: ]); Chris@17: $field_storage2->save(); Chris@17: FieldConfig::create([ Chris@17: 'field_storage' => $field_storage2, Chris@17: 'bundle' => 'user', Chris@17: 'label' => 'User Telephone Number', Chris@17: ])->save(); Chris@17: Chris@17: $this->drupalGet('admin/modules/uninstall'); Chris@17: $this->assertText("The Telephone number field type is used in the following fields: node.field_telephone, user.field_telephone_2"); Chris@17: Chris@17: // Delete both fields. Chris@17: $field_storage->delete(); Chris@17: $field_storage2->delete(); Chris@17: Chris@17: $this->drupalGet('admin/modules/uninstall'); Chris@17: $this->assertText('Fields pending deletion'); Chris@17: $this->cronRun(); Chris@17: $this->assertNoText("The Telephone number field type is used in the following field: node.field_telephone"); Chris@17: $this->assertNoText('Fields pending deletion'); Chris@17: } Chris@17: Chris@17: }