public function FlagCountExtensionTest::testUi in Flag 8.4
Browser tests for flag count.
File
- tests/
src/ FunctionalJavascript/ FlagCountExtensionTest.php, line 49
Class
- FlagCountExtensionTest
- Browser tests for the flag.twig.count service.
Namespace
Drupal\Tests\flag\FunctionalJavascriptCode
public function testUi() {
// Generate a unique title so we can find it on the page easily.
$title = $this
->randomMachineName();
// Add a single article.
$article = $this
->drupalCreateNode([
'type' => 'article',
'title' => $title,
]);
$auth_user = $this
->drupalCreateUser([
'flag bookmark',
'unflag bookmark',
]);
$assert_session = $this
->assertSession();
$this
->drupalLogin($auth_user);
// Check the link to bookmark exist.
$this
->drupalGet('node/1');
// Check that the bookmark count is equal to zero.
$element0 = $assert_session
->waitForElementVisible('css', '.flag-bookmark span:contains("[0]")');
$this
->assertNotNull($element0);
$this
->clickLink('Bookmark this');
// Check that after clicking the link bookmark count is equal to one.
$element1 = $assert_session
->waitForElementVisible('css', '.flag-bookmark span:contains("[1]")');
$this
->assertNotNull($element1);
// Observe a change in the frontpage link title.
$bookmark_link = $assert_session
->waitForLink('Remove bookmark');
$this
->assertNotNull($bookmark_link, 'Remove bookmark is availble on the page.');
// Check the view is shown correctly.
$this
->drupalGet('bookmarks');
$assert_session
->pageTextContains($article
->getTitle());
}