public function FlagContextualLinksTest::testFlagLinks in Flag 8.4
Verify the behaviour and rendering of Flag links.
@runInSeparateProcess
File
- tests/
src/ FunctionalJavascript/ FlagContextualLinksTest.php, line 173
Class
- FlagContextualLinksTest
- Test the contextual links with Reload link type.
Namespace
Drupal\Tests\flag\FunctionalJavascriptCode
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.
$this
->drupalLogin($this->alice);
// Open node view page that renders Full view mode.
$this
->drupalGet('node/' . $node
->id());
// 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';
// 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, new FormattableMarkup('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';
$contextual_edit2 = $assert_session
->waitForElementVisible('css', 'div[data-contextual-id="' . $unflag_contextual_links_id . '"] button');
$this
->assertNotNull($contextual_edit2, new FormattableMarkup('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.
$this
->drupalLogin($this->bob);
// Open node view page that renders Full view mode.
$this
->drupalGet('node/' . $node
->id());
// Expect the contextual links identifier for this node to contain flag_keys
// metadata related to the flag action.
$contextual_edit3 = $assert_session
->waitForElementVisible('css', 'div[data-contextual-id="' . $flag_contextual_links_id . '"] button');
$this
->assertNotNull($contextual_edit3, new FormattableMarkup('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);
}