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