summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-10-01 15:54:31 (GMT)
committerAlex Pott2018-10-01 15:54:31 (GMT)
commit58746b51593f4205b251fc8f6523c95abc5d3583 (patch)
treeb798e87f817b04422b2b8ee0d4d026474f515b67
parent996c3f9109508652277fd53f29dfc16289ddb4c3 (diff)
Issue #2794347 by nuez, Jo Fitzgerald, jmuzz, Lendude, boaloysius, klausi, jibran: Convert web tests to browser tests for field_ui module
-rw-r--r--core/modules/comment/tests/src/Functional/CommentNonNodeTest.php2
-rw-r--r--core/modules/contact/tests/src/Functional/ContactSitewideTest.php2
-rw-r--r--core/modules/field_ui/tests/src/Functional/FieldUIDeleteTest.php (renamed from core/modules/field_ui/src/Tests/FieldUIDeleteTest.php)7
-rw-r--r--core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php (renamed from core/modules/field_ui/src/Tests/ManageFieldsTest.php)27
-rw-r--r--core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php125
-rw-r--r--core/modules/link/tests/src/Functional/LinkFieldUITest.php2
6 files changed, 144 insertions, 21 deletions
diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
index 27c0964..ae94da1 100644
--- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
@@ -10,9 +10,9 @@ use Drupal\comment\Tests\CommentTestTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\user\RoleInterface;
/**
diff --git a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
index 2c881b0..1002d5a 100644
--- a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
+++ b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
@@ -5,9 +5,9 @@ namespace Drupal\Tests\contact\Functional;
use Drupal\contact\Entity\ContactForm;
use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Test\AssertMailTrait;
-use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\user\RoleInterface;
/**
diff --git a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php b/core/modules/field_ui/tests/src/Functional/FieldUIDeleteTest.php
index 631d336..5236905 100644
--- a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php
+++ b/core/modules/field_ui/tests/src/Functional/FieldUIDeleteTest.php
@@ -1,10 +1,11 @@
<?php
-namespace Drupal\field_ui\Tests;
+namespace Drupal\Tests\field_ui\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestData;
@@ -13,7 +14,7 @@ use Drupal\views\Tests\ViewTestData;
*
* @group field_ui
*/
-class FieldUIDeleteTest extends WebTestBase {
+class FieldUIDeleteTest extends BrowserTestBase {
use FieldUiTestTrait;
diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
index 9e1a9a0..3e31c81 100644
--- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php
+++ b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
@@ -1,22 +1,23 @@
<?php
-namespace Drupal\field_ui\Tests;
+namespace Drupal\Tests\field_ui\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
+use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
+use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
/**
* Tests the Field UI "Manage fields" screen.
*
* @group field_ui
*/
-class ManageFieldsTest extends WebTestBase {
+class ManageFieldsFunctionalTest extends BrowserTestBase {
use FieldUiTestTrait;
use EntityReferenceTestTrait;
@@ -153,17 +154,17 @@ class ManageFieldsTest extends WebTestBase {
$url = base_path() . "admin/structure/types/manage/$type/fields/node.$type.body";
foreach ($operation_links as $link) {
- switch ($link['title']) {
+ switch ($link->getAttribute('title')) {
case 'Edit field settings.':
- $this->assertIdentical($url, (string) $link['href']);
+ $this->assertIdentical($url, $link->getAttribute('href'));
$number_of_links_found++;
break;
case 'Edit storage settings.':
- $this->assertIdentical("$url/storage", (string) $link['href']);
+ $this->assertIdentical("$url/storage", $link->getAttribute('href'));
$number_of_links_found++;
break;
case 'Delete field.':
- $this->assertIdentical("$url/delete", (string) $link['href']);
+ $this->assertIdentical("$url/delete", $link->getAttribute('href'));
$number_of_links_found++;
break;
}
@@ -449,7 +450,7 @@ class ManageFieldsTest extends WebTestBase {
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
- $this->assertEqual($field->getDefaultValueLiteral(), NULL, 'The default value was correctly saved.');
+ $this->assertEqual($field->getDefaultValueLiteral(), [], 'The default value was correctly saved.');
// Check that the default value can be empty when the field is marked as
// required and can store unlimited values.
@@ -467,7 +468,7 @@ class ManageFieldsTest extends WebTestBase {
$this->drupalPostForm(NULL, [], t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
- $this->assertEqual($field->getDefaultValueLiteral(), NULL, 'The default value was correctly saved.');
+ $this->assertEqual($field->getDefaultValueLiteral(), [], 'The default value was correctly saved.');
// Check that the default widget is used when the field is hidden.
entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
@@ -564,11 +565,7 @@ class ManageFieldsTest extends WebTestBase {
// Check that the links for edit and delete are not present.
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
$locked = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
- $this->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');
- $edit_link = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
- $this->assertFalse(in_array('edit', $edit_link), 'Edit option for locked field is not present the UI');
- $delete_link = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
- $this->assertFalse(in_array('delete', $delete_link), 'Delete option for locked field is not present the UI');
+ $this->assertSame('Locked', $locked[0]->getHtml(), 'Field is marked as Locked in the UI');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
$this->assertResponse(403);
}
@@ -720,7 +717,7 @@ class ManageFieldsTest extends WebTestBase {
public function fieldListAdminPage() {
$this->drupalGet('admin/reports/fields');
$this->assertText($this->fieldName, 'Field name is displayed in field list.');
- $this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->contentType . '/fields'), 'Link to content type using field is displayed in field list.');
+ $this->assertLinkByHref('admin/structure/types/manage/' . $this->contentType . '/fields');
}
/**
diff --git a/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php b/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
new file mode 100644
index 0000000..52e75cf
--- /dev/null
+++ b/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
@@ -0,0 +1,125 @@
+<?php
+
+namespace Drupal\Tests\field_ui\Traits;
+
+/**
+ * Provides common functionality for the Field UI test classes.
+ */
+trait FieldUiTestTrait {
+
+ /**
+ * Creates a new field through the Field UI.
+ *
+ * @param string $bundle_path
+ * Admin path of the bundle that the new field is to be attached to.
+ * @param string $field_name
+ * The field name of the new field storage.
+ * @param string $label
+ * (optional) The label of the new field. Defaults to a random string.
+ * @param string $field_type
+ * (optional) The field type of the new field storage. Defaults to
+ * 'test_field'.
+ * @param array $storage_edit
+ * (optional) $edit parameter for drupalPostForm() on the second step
+ * ('Storage settings' form).
+ * @param array $field_edit
+ * (optional) $edit parameter for drupalPostForm() on the third step ('Field
+ * settings' form).
+ */
+ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = [], array $field_edit = []) {
+ $label = $label ?: $this->randomString();
+ $initial_edit = [
+ 'new_storage_type' => $field_type,
+ 'label' => $label,
+ 'field_name' => $field_name,
+ ];
+
+ // Allow the caller to set a NULL path in case they navigated to the right
+ // page before calling this method.
+ if ($bundle_path !== NULL) {
+ $bundle_path = "$bundle_path/fields/add-field";
+ }
+
+ // First step: 'Add field' page.
+ $this->drupalPostForm($bundle_path, $initial_edit, t('Save and continue'));
+ $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', ['%label' => $label]), 'Storage settings page was displayed.');
+ // Test Breadcrumbs.
+ $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.');
+
+ // Second step: 'Storage settings' form.
+ $this->drupalPostForm(NULL, $storage_edit, t('Save field settings'));
+ $this->assertRaw(t('Updated field %label field settings.', ['%label' => $label]), 'Redirected to field settings page.');
+
+ // Third step: 'Field settings' form.
+ $this->drupalPostForm(NULL, $field_edit, t('Save settings'));
+ $this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.');
+
+ // Check that the field appears in the overview form.
+ $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
+ }
+
+ /**
+ * Adds an existing field through the Field UI.
+ *
+ * @param string $bundle_path
+ * Admin path of the bundle that the field is to be attached to.
+ * @param string $existing_storage_name
+ * The name of the existing field storage for which we want to add a new
+ * field.
+ * @param string $label
+ * (optional) The label of the new field. Defaults to a random string.
+ * @param array $field_edit
+ * (optional) $edit parameter for drupalPostForm() on the second step
+ * ('Field settings' form).
+ */
+ public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = []) {
+ $label = $label ?: $this->randomString();
+ $initial_edit = [
+ 'existing_storage_name' => $existing_storage_name,
+ 'existing_storage_label' => $label,
+ ];
+
+ // First step: 'Re-use existing field' on the 'Add field' page.
+ $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue'));
+ // Set the main content to only the content region because the label can
+ // contain HTML which will be auto-escaped by Twig.
+ $this->assertRaw('field-config-edit-form', 'The field config edit form is present.');
+ $this->assertNoRaw('&amp;lt;', 'The page does not have double escaped HTML tags.');
+
+ // Second step: 'Field settings' form.
+ $this->drupalPostForm(NULL, $field_edit, t('Save settings'));
+ $this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.');
+
+ // Check that the field appears in the overview form.
+ $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
+ }
+
+ /**
+ * Deletes a field through the Field UI.
+ *
+ * @param string $bundle_path
+ * Admin path of the bundle that the field is to be deleted from.
+ * @param string $field_name
+ * The name of the field.
+ * @param string $label
+ * The label of the field.
+ * @param string $bundle_label
+ * The label of the bundle.
+ */
+ public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
+ // Display confirmation form.
+ $this->drupalGet("$bundle_path/fields/$field_name/delete");
+ $this->assertRaw(t('Are you sure you want to delete the field %label', ['%label' => $label]), 'Delete confirmation was found.');
+
+ // Test Breadcrumbs.
+ $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the field delete page.');
+
+ // Submit confirmation form.
+ $this->drupalPostForm(NULL, [], t('Delete'));
+ $this->assertRaw(t('The field %label has been deleted from the %type content type.', ['%label' => $label, '%type' => $bundle_label]), 'Delete message was found.');
+
+ // Check that the field does not appear in the overview form.
+ $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, 'Field does not appear in the overview page.');
+ }
+
+}
diff --git a/core/modules/link/tests/src/Functional/LinkFieldUITest.php b/core/modules/link/tests/src/Functional/LinkFieldUITest.php
index bd2433f..5be9e21 100644
--- a/core/modules/link/tests/src/Functional/LinkFieldUITest.php
+++ b/core/modules/link/tests/src/Functional/LinkFieldUITest.php
@@ -6,9 +6,9 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\link\LinkItemInterface;
use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
/**
* Tests link field UI functionality.