Chris@0: randomString(); Chris@0: $initial_edit = [ Chris@0: 'new_storage_type' => $field_type, Chris@0: 'label' => $label, Chris@0: 'field_name' => $field_name, Chris@0: ]; Chris@0: Chris@0: // Allow the caller to set a NULL path in case they navigated to the right Chris@0: // page before calling this method. Chris@0: if ($bundle_path !== NULL) { Chris@0: $bundle_path = "$bundle_path/fields/add-field"; Chris@0: } Chris@0: Chris@0: // First step: 'Add field' page. Chris@0: $this->drupalPostForm($bundle_path, $initial_edit, t('Save and continue')); Chris@0: $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', ['%label' => $label]), 'Storage settings page was displayed.'); Chris@0: // Test Breadcrumbs. Chris@0: $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.'); Chris@0: Chris@0: // Second step: 'Storage settings' form. Chris@0: $this->drupalPostForm(NULL, $storage_edit, t('Save field settings')); Chris@0: $this->assertRaw(t('Updated field %label field settings.', ['%label' => $label]), 'Redirected to field settings page.'); Chris@0: Chris@0: // Third step: 'Field settings' form. Chris@0: $this->drupalPostForm(NULL, $field_edit, t('Save settings')); Chris@0: $this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.'); Chris@0: Chris@0: // Check that the field appears in the overview form. Chris@0: $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds an existing field through the Field UI. Chris@0: * Chris@0: * @param string $bundle_path Chris@0: * Admin path of the bundle that the field is to be attached to. Chris@0: * @param string $existing_storage_name Chris@0: * The name of the existing field storage for which we want to add a new Chris@0: * field. Chris@0: * @param string $label Chris@0: * (optional) The label of the new field. Defaults to a random string. Chris@0: * @param array $field_edit Chris@0: * (optional) $edit parameter for drupalPostForm() on the second step Chris@0: * ('Field settings' form). Chris@0: */ Chris@0: public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = []) { Chris@0: $label = $label ?: $this->randomString(); Chris@0: $initial_edit = [ Chris@0: 'existing_storage_name' => $existing_storage_name, Chris@0: 'existing_storage_label' => $label, Chris@0: ]; Chris@0: Chris@0: // First step: 'Re-use existing field' on the 'Add field' page. Chris@0: $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue')); Chris@0: // Set the main content to only the content region because the label can Chris@0: // contain HTML which will be auto-escaped by Twig. Chris@0: $main_content = $this->cssSelect('.region-content'); Chris@0: $this->setRawContent(reset($main_content)->asXml()); Chris@0: $this->assertRaw('field-config-edit-form', 'The field config edit form is present.'); Chris@0: $this->assertNoRaw('<', 'The page does not have double escaped HTML tags.'); Chris@0: Chris@0: // Second step: 'Field settings' form. Chris@0: $this->drupalPostForm(NULL, $field_edit, t('Save settings')); Chris@0: $this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.'); Chris@0: Chris@0: // Check that the field appears in the overview form. Chris@0: $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Deletes a field through the Field UI. Chris@0: * Chris@0: * @param string $bundle_path Chris@0: * Admin path of the bundle that the field is to be deleted from. Chris@0: * @param string $field_name Chris@0: * The name of the field. Chris@0: * @param string $label Chris@0: * The label of the field. Chris@0: * @param string $bundle_label Chris@0: * The label of the bundle. Chris@0: */ Chris@0: public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) { Chris@0: // Display confirmation form. Chris@0: $this->drupalGet("$bundle_path/fields/$field_name/delete"); Chris@0: $this->assertRaw(t('Are you sure you want to delete the field %label', ['%label' => $label]), 'Delete confirmation was found.'); Chris@0: Chris@0: // Test Breadcrumbs. Chris@0: $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the field delete page.'); Chris@0: Chris@0: // Submit confirmation form. Chris@0: $this->drupalPostForm(NULL, [], t('Delete')); Chris@0: $this->assertRaw(t('The field %label has been deleted from the %type content type.', ['%label' => $label, '%type' => $bundle_label]), 'Delete message was found.'); Chris@0: Chris@0: // Check that the field does not appear in the overview form. Chris@0: $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, 'Field does not appear in the overview page.'); Chris@0: } Chris@0: Chris@0: }