diff --git a/tests/src/FunctionalJavascript/FlagContextualLinksTest.php b/tests/src/FunctionalJavascript/FlagContextualLinksTest.php index 918125d..a4861e7 100755 --- a/tests/src/FunctionalJavascript/FlagContextualLinksTest.php +++ b/tests/src/FunctionalJavascript/FlagContextualLinksTest.php @@ -119,7 +119,7 @@ class FlagContextualLinksTest extends JavascriptTestBase { 'access contextual links', 'access content', 'access toolbar', - ]); + ]); // Create a second regular user who will be flagging content. $this->bob = $this->drupalCreateUser([ @@ -129,7 +129,7 @@ class FlagContextualLinksTest extends JavascriptTestBase { 'access contextual links', 'access content', 'access toolbar', - ]); + ]); $this->drupalLogin($this->adminUser); @@ -169,6 +169,9 @@ class FlagContextualLinksTest extends JavascriptTestBase { * @runInSeparateProcess */ public function testFlagLinks() { + $assert_session = $this->assertSession(); + + // Create an article, to which our contextual link will be attached. $node = $this->drupalCreateNode(['type' => $this->nodeType]); // Login as normal user. @@ -177,32 +180,41 @@ class FlagContextualLinksTest extends JavascriptTestBase { // Open node view page that renders Full view mode. $this->drupalGet('node/' . $node->id()); - $assert_session = $this->assertSession(); + // Click on the edit button to become active. + $main_contextual_button = $assert_session + ->waitForElementVisible('css', 'button:contains("Edit")'); + + $this->assertNotNull($main_contextual_button); + $main_contextual_button->click(); // Expect the contextual links identifer for this node to contain flag_keys // metadata related to the flag action. $flag_contextual_links_id = 'node:node=' . $node->id() . ':changed=' . $node->getChangedTime() . '&flag_keys=' . $this->flag->id() . '-flag&langcode=en'; - // Verify the link is as expecected. - $flag_link = $assert_session - ->waitForElement('css', 'div[data-contextual-id="' . $flag_contextual_links_id . '"] ul.contextual-links li.flag-test-label-123 a'); - $this->assertNotNull($flag_link, format_string('Contextual link placeholder with id @id exists (flag).', ['@id' => $flag_contextual_links_id])); - $this->assertLinkMatches($flag_link, $this->flag, $node, 'flag'); - - // Simulate clicking on the flag contextual link. - // - // Zumba\GastonJS\Browser does not support the handling of JSON response - // objects so instead of clicking we programatically change the state of the - // flag and reload the page. - $this->flagService->flag($this->flag, $node, $this->alice); - $this->getSession()->reload(); - - // Verify the contextual links are updated to contain unflag links. + // Wait for the article contextual link button to appear. + $contextual_edit = $assert_session + ->waitForElementVisible('css', 'div[data-contextual-id="' . $flag_contextual_links_id . '"] button'); + $this->assertNotNull($contextual_edit, format_string('Contextual link placeholder with id @id exists (flag).', ['@id' => $flag_contextual_links_id])); + + $contextual_edit->click(); + + // The contextual link dialog will appear .. containing a flag link. + $flag_link1 = $assert_session->waitForLink($this->flag->getShortText('flag')); + $this->assertNotNull($flag_link1); + + $flag_link1->click(); + + // Verify the contextual links data are updated to contain unflag links. $unflag_contextual_links_id = 'node:node=' . $node->id() . ':changed=' . $node->getChangedTime() . '&flag_keys=' . $this->flag->id() . '-unflag&langcode=en'; - $unflag_link = $assert_session - ->waitForELement('css', 'div[data-contextual-id="' . $unflag_contextual_links_id . '"] ul.contextual-links li.flag-test-label-123 a'); - $this->assertNotNull($unflag_link, format_string('Contextual link placeholder with id @id exists (unflag).', ['@id' => $unflag_contextual_links_id])); - $this->assertLinkMatches($unflag_link, $this->flag, $node, 'unflag'); + $contextual_edit2 = $assert_session + ->waitForElementVisible('css', 'div[data-contextual-id="' . $unflag_contextual_links_id . '"] button'); + $this->assertNotNull($contextual_edit2 , format_string('Contextual link placeholder with id @id exists (unflag).', ['@id' => $unflag_contextual_links_id])); + + $contextual_edit2->click(); + + // The contextual link dialog will appear .. containing a unflag link. + $unflag_link1 = $assert_session->waitForLink($this->flag->getShortText('unflag')); + $this->assertNotNull($unflag_link1); // Login as alternate regular user. // to verify that the cache context displayed to bob is different. @@ -213,34 +225,14 @@ class FlagContextualLinksTest extends JavascriptTestBase { // Expect the contextual links identifier for this node to contain flag_keys // metadata related to the flag action. - $flag_link2 = $assert_session - ->waitForElement('css', 'div[data-contextual-id="' . $flag_contextual_links_id . '"] ul.contextual-links li.flag-test-label-123 a'); - $this->assertNotNull($flag_link2, format_string('Contextual link placeholder with id @id exists.', ['@id' => $flag_contextual_links_id])); - $this->assertLinkMatches($flag_link2, $this->flag, $node, 'flag'); - } - - /** - * Returns a flag action contextual link in the form of a URL. - * - * A contextual identifier is needed to fully specify the final markup. - * - * @param Behat\Mink\Element\ElementInterface $link - * The HTML elements wrapper holding the contextual links. - * @param \Drupal\flag\FlagInterface $flag - * The flag associated with the contextual link. - * @param Drupal\node\NodeInterface $node - * The node associated with the contextual link. - */ - protected function assertLinkMatches(ElementInterface $link, FlagInterface $flag, NodeInterface $node, $action) { - // Extract href from the page. - $href = $link->getAttribute('href'); - - $flag_url = Url::fromRoute("flag.action_link_{$action}", [ - 'flag' => $flag->id(), - 'entity_id' => $node->id(), - ]); - - $this->assertEquals($href, $flag_url->toString(), 'A link was displayed macthing the given Flag and node pair.'); + $contextual_edit3 = $assert_session + ->waitForElementVisible('css', 'div[data-contextual-id="' . $flag_contextual_links_id . '"] button'); + $this->assertNotNull($contextual_edit3, format_string('Contextual link placeholder with id @id exists.', ['@id' => $flag_contextual_links_id])); + $contextual_edit3->click(); + + // The contextual link dialog will appear .. containing a flag link. + $flag_link2 = $assert_session->waitForLink($this->flag->getShortText('flag')); + $this->assertNotNull($flag_link2); } }