You are here

public function LinkHtmlTest::doFlagNode in Flag 8.4

Flag a node and check flag text.

1 call to LinkHtmlTest::doFlagNode()
LinkHtmlTest::testHtmlLink in tests/src/Functional/LinkHtmlTest.php
Tests use of HTML in the flag and unflag links.

File

tests/src/Functional/LinkHtmlTest.php, line 54

Class

LinkHtmlTest
Tests use of HTML in the flag and unflag links.

Namespace

Drupal\Tests\flag\Functional

Code

public function doFlagNode() {
  $node = $this
    ->drupalCreateNode([
    'type' => $this->nodeType,
  ]);
  $node_id = $node
    ->id();
  $flag_id = $this->flag
    ->id();

  // Grant the flag permissions to the authenticated role, so that both
  // users have the same roles and share the render cache. ???? TODO
  $this
    ->grantFlagPermissions($this->flag);

  // Create and login a new user.
  $user_1 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user_1);

  // Click the flag link.
  $this
    ->drupalGet('node/' . $node_id);

  // Find the marked-up flag short text in the raw HTML.
  $this
    ->assertRaw(Xss::filterAdmin($this->flag
    ->getShortText('flag')));

  // Xss::filter() is used to strip all HTML tags from the short text
  // because clickLink() looks for text as it appears in the brower, and that
  // does not include the unescaped HTML tags. Note that the stripped tags
  // could either be at the ends (we added the italics tags above) OR they
  // could be in the middle as a result of a randomly-generated valid tag
  // in the flag text.
  $this
    ->clickLink(Html::decodeEntities(Xss::filter($this->flag
    ->getShortText('flag'), [])));

  // Check that the node is flagged.
  $this
    ->drupalGet('node/' . $node_id);
  $this
    ->assertRaw(Xss::filterAdmin($this->flag
    ->getShortText('unflag')));

  // Unflag the node.
  $this
    ->drupalGet('node/' . $node_id);
  $this
    ->clickLink(Html::decodeEntities(Xss::filter($this->flag
    ->getShortText('unflag'), [])));

  // Check that the node is no longer flagged.
  $this
    ->drupalGet('node/' . $node_id);
  $this
    ->assertRaw(Xss::filterAdmin($this->flag
    ->getShortText('flag')));
}