diff --git a/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php b/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php index 962ed2989fb0551a226e7335b1c3acbfea107da2..3d77da7e88dd0f42be391cee244f9ccca7e875fc 100644 --- a/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php +++ b/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php @@ -79,8 +79,8 @@ class ComplexSimpleWidgetTest extends InlineEntityFormTestBase { ->press(); $this->assertNotEmpty($assert_session->waitForElement('xpath', $outer_title_field_xpath)); } - $outer_title = $this->randomMachineName(8); - $inner_title = $this->randomMachineName(8); + $outer_title = $this->randomMachineName(); + $inner_title = $this->randomMachineName(); $assert_session->elementExists('xpath', $outer_title_field_xpath)->setValue($outer_title); // Simple widget is required so should always show up. No need for // add submit. @@ -97,7 +97,7 @@ class ComplexSimpleWidgetTest extends InlineEntityFormTestBase { $this->assertNoNodeByTitle($outer_title, 'Outer node was not created when widget submitted.'); $this->assertNoNodeByTitle($inner_title, 'Inner node was not created when widget submitted.'); - $host_title = $this->randomMachineName(8); + $host_title = $this->randomMachineName(); $assert_session->elementExists('xpath', $first_title_field_xpath)->setValue($host_title); $page->pressButton('Save'); $assert_session->pageTextContains("$host_title has been created."); diff --git a/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php b/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php index 452b5fa46b2e8a7ca4d011f92d9d92c446a71403..1ec4b168ddb7f7541324f387a33b40077cdc043a 100644 --- a/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php +++ b/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests\inline_entity_form\FunctionalJavascript; -use Drupal\Core\Entity\Display\EntityDisplayInterface; - /** * IEF complex entity reference revisions tests. * diff --git a/tests/src/FunctionalJavascript/ComplexWidgetTest.php b/tests/src/FunctionalJavascript/ComplexWidgetTest.php index 8a38315bfae7b73ff3c2a960863f0ecd3c371ed9..ea7d3537f10656246471348d98394d56646b6214 100644 --- a/tests/src/FunctionalJavascript/ComplexWidgetTest.php +++ b/tests/src/FunctionalJavascript/ComplexWidgetTest.php @@ -330,13 +330,13 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $this->updateSetting('allow_existing', TRUE); // Create three ief_reference_type entities. - $referenceNodes = $this->createReferenceContent(3); + $referenceNodes = $this->createReferenceContent(); $this->drupalCreateNode([ 'type' => 'ief_test_complex', 'title' => 'Some title', 'multi' => array_values($referenceNodes), ]); - /** @var \Drupal\node\NodeInterface $parent_node */ + $parent_node = $this->drupalGetNodeByTitle('Some title'); // Edit the second entity. @@ -391,7 +391,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $this->drupalGet('node/' . $parent_node->id() . '/edit'); $assert_session->elementsCount('css', 'tr.ief-row-entity', 2); $assert_session->elementExists('xpath', '(//input[@value="Remove"])[2]')->press(); - $this->assertNotEmpty($confirm_checkbox = $assert_session->waitForElement('xpath', $first_delete_checkbox_xpath)); + $this->assertNotEmpty($assert_session->waitForElement('xpath', $first_delete_checkbox_xpath)); $assert_session->pageTextContains('Are you sure you want to remove Some reference 3?'); $assert_session->elementExists('xpath', '(//input[@value="Remove"])[2]')->press(); $this->waitForRowRemovedByTitle('Some reference 3'); @@ -423,7 +423,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $this->updateSetting('allow_existing', TRUE); // Create three ief_reference_type entities. - $referenceNodes = $this->createReferenceContent(3); + $referenceNodes = $this->createReferenceContent(); // Create a node for every bundle available. $bundle_nodes = $this->createNodeForEveryBundle(); @@ -474,7 +474,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { // Check if all remaining nodes from all bundles are referenced. $assert_session->elementsCount('css', 'fieldset[data-drupal-selector="edit-all-bundles"] tr.ief-row-entity', 12); - foreach ($bundle_nodes as $id => $title) { + foreach ($bundle_nodes as $title) { $this->assertRowByTitle($title); } } @@ -569,7 +569,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { 'title' => 'Some title', 'multi' => array_values($referenceNodes), ]); - /** @var \Drupal\node\NodeInterface $parent_node */ + $parent_node = $this->drupalGetNodeByTitle('Some title'); $this->drupalGet('node/' . $parent_node->id() . '/edit'); @@ -739,7 +739,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { * @param mixed $value * The value to set. */ - protected function updateSetting($name, $value) { + protected function updateSetting(string $name, $value) { /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */ $display = $this->entityFormDisplayStorage->load('node.ief_test_complex.default'); $component = $display->getComponent('multi'); @@ -775,7 +775,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { * @param bool $required * Whether the fields are required. */ - protected function setupNestedComplexForm($required) { + protected function setupNestedComplexForm(bool $required) { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); /** @var \Drupal\Core\Field\FieldConfigInterface $ief_test_nested1 */ @@ -821,7 +821,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { * @param string $expected_error * The error message that is expected to be shown. */ - protected function checkExistingValidationExpectation($existing_node_text, $expected_error) { + protected function checkExistingValidationExpectation(string $existing_node_text, string $expected_error) { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->openMultiExistingForm(); @@ -945,10 +945,8 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $top_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 1); $nested_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 2); $double_nested_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 3); - $second_edit_button_xpath = $this->getXpathForButtonWithValue('Edit', 2); - $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->setupNestedComplexForm($required); @@ -986,7 +984,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $this->elementWithXpath($this->buttonXpath('Update node 2'))->press(); $this->waitForXpathRemoved($this->buttonXpath('Update node 2')); - // Repeat. Add node 2a and 2a_3 + // Repeat. Add node 2a and 2a_3. $this->elementWithXpath($this->buttonXpath('Add new node 2'))->press(); $this->waitForXpath($this->buttonXpath('Create node 2')); if (!$required) { @@ -1036,6 +1034,7 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { * * @param string $xpath * The XPath. + * * @return \Behat\Mink\Element\NodeElement * The element. */ @@ -1044,12 +1043,15 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { } /** - * Wait, assert, and return an element via XPath. On fail, save output and throw. + * Wait, assert, and return an element via XPath. + * + * On fail, save output and throw. * * @param string $xpath * The XPath. * @param int $timeout * The timeout in milliseconds. + * * @return \Behat\Mink\Element\NodeElement * The element. */ @@ -1063,20 +1065,23 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { } /** - * Wait and assert removal of an element via XPath. On fail, save output and throw. + * Wait and assert removal of an element via XPath. + * + * On fail, save output and throw. * * @param string $xpath * The XPath. * @param int $timeout * The timeout in milliseconds. + * * @return bool - * Returna always true (else throws). + * Returns always true (else throws). */ public function waitForXpathRemoved(string $xpath, int $timeout = 10000): bool { $removed = $this->assertSession()->waitForElementRemoved('xpath', $xpath, $timeout); if (!$removed) { $this->htmlOutput(); - $this->assert($removed); + $this->assertTrue($removed); } return $removed; } @@ -1085,9 +1090,10 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { * Get xpath for a button. * * @param string $label - * The button's label. + * The button's label. * @param int $index * The button's index, defaults to 1. + * * @return string * The XPath. */ diff --git a/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php b/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php index d4681dab7cae1f440fa309646e455d2bfbe6afe7..ddc505e64f093ea6acd202bb16b34b2d3b7f1dc1 100644 --- a/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php +++ b/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php @@ -65,7 +65,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @return string * The name of the button. */ - protected function getButtonName($xpath) { + protected function getButtonName(string $xpath) { $retval = ''; /** @var \SimpleXMLElement[] $elements */ if ($elements = $this->xpath($xpath)) { @@ -87,7 +87,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $message * Message to display. */ - protected function assertNoNodeByTitle($title, $message = '') { + protected function assertNoNodeByTitle(string $title, $message = '') { if (!$message) { $message = "No node with title: $title"; } @@ -106,7 +106,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $message * Message to display. */ - protected function assertNodeByTitle($title, $content_type = NULL, $message = '') { + protected function assertNodeByTitle(string $title, $content_type = NULL, $message = '') { if (!$message) { $message = "Node with title found: $title"; } @@ -127,7 +127,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $bundle * (optional) The bundle this entity should have. */ - protected function assertEntityByLabel($label, $entity_type_id = 'node', $bundle = NULL) { + protected function assertEntityByLabel(string $label, $entity_type_id = 'node', $bundle = NULL) { $entity_type_manager = \Drupal::entityTypeManager(); $entity_type = $entity_type_manager->getDefinition($entity_type_id); $label_key = $entity_type->getKey('label'); @@ -155,7 +155,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $prefix * The config prefix. */ - protected function checkFormDisplayFields($form_display, $prefix) { + protected function checkFormDisplayFields(string $form_display, string $prefix) { $assert_session = $this->assertSession(); $form_display_fields = [ 'node.ief_test_custom.default' => [ @@ -194,7 +194,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { $assert_session->fieldExists($prefix . $expected_field); } foreach ($fields['unexpected'] as $unexpected_field) { - $assert_session->fieldNotExists($prefix . $unexpected_field, NULL); + $assert_session->fieldNotExists($prefix . $unexpected_field); } } @@ -204,7 +204,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $title * The title of the row for which to wait. */ - protected function waitForRowByTitle($title) { + protected function waitForRowByTitle(string $title) { $this->assertNotEmpty($this->assertSession()->waitForElement('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); } @@ -214,7 +214,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $title * The title of the row for which to wait. */ - protected function waitForRowRemovedByTitle($title) { + protected function waitForRowRemovedByTitle(string $title) { $this->assertNotEmpty($this->assertSession()->waitForElementRemoved('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); } @@ -227,7 +227,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @return \Behat\Mink\Element\NodeElement * The <td> element containing the label for the IEF row. */ - protected function assertRowByTitle($title) { + protected function assertRowByTitle(string $title) { $this->assertNotEmpty($element = $this->assertSession()->elementExists('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); return $element; } @@ -238,7 +238,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @param string $title * The title of the row to check. */ - protected function assertNoRowByTitle($title) { + protected function assertNoRowByTitle(string $title) { $this->assertSession()->elementNotExists('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]'); } @@ -255,8 +255,8 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @return string * The xpath selector for the input to select. */ - protected function getXpathForNthInputByLabelText($label, $index) { - return "(//*[@id=string((//label[.='{$label}']/@for)[{$index}])])"; + protected function getXpathForNthInputByLabelText(string $label, int $index) { + return "(//*[@id=string((//label[.='$label']/@for)[$index])])"; } /** @@ -274,7 +274,7 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * * Note: index starts at 1. * - * @param string @value + * @param string $value * The text on the button to select. * @param int $index * The index of the button to select. @@ -282,8 +282,8 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @return string * The xpath selector for the button to select. */ - protected function getXpathForButtonWithValue($value, $index) { - return "(//input[@type='submit' and @value='{$value}'])[{$index}]"; + protected function getXpathForButtonWithValue(string $value, int $index) { + return "(//input[@type='submit' and @value='$value'])[$index]"; } /** @@ -297,8 +297,8 @@ abstract class InlineEntityFormTestBase extends WebDriverTestBase { * @return string * The xpath selector for the fieldset label to select. */ - protected function getXpathForFieldsetLabel($label, $index) { - return "(//fieldset/legend/span[.='{$label}'])[{$index}]"; + protected function getXpathForFieldsetLabel(string $label, int $index) { + return "(//fieldset/legend/span[.='{$label}'])[$index]"; } } diff --git a/tests/src/FunctionalJavascript/SimpleWidgetTest.php b/tests/src/FunctionalJavascript/SimpleWidgetTest.php index ad32775918499c42a7667a7bb82734a4c2b6e07a..69d83975a0b7708cab69c1d4a4f60b949cb9031d 100644 --- a/tests/src/FunctionalJavascript/SimpleWidgetTest.php +++ b/tests/src/FunctionalJavascript/SimpleWidgetTest.php @@ -239,7 +239,7 @@ class SimpleWidgetTest extends InlineEntityFormTestBase { * @param int $cardinality * The field cardinality with which to check. */ - protected function checkEditAccess(NodeInterface $host_node, $number_of_items, $cardinality) { + protected function checkEditAccess(NodeInterface $host_node, int $number_of_items, int $cardinality) { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); $other_user = $this->createUser([