function AnnounceBlockTest::testAnnounceWithoutPermission
Same name in other branches
- 11.x core/modules/announcements_feed/tests/src/FunctionalJavascript/AnnounceBlockTest.php \Drupal\Tests\announcements_feed\FunctionalJavascript\AnnounceBlockTest::testAnnounceWithoutPermission()
Testing announce feed block visibility.
File
-
core/
modules/ announcements_feed/ tests/ src/ FunctionalJavascript/ AnnounceBlockTest.php, line 55
Class
- AnnounceBlockTest
- Test the announcement block test visibility.
Namespace
Drupal\Tests\announcements_feed\FunctionalJavascriptCode
public function testAnnounceWithoutPermission() : void {
// User with "access announcements" permission and anonymous session.
$account = $this->drupalCreateUser([
'access announcements',
]);
$anonymous_account = new AnonymousUserSession();
$this->drupalLogin($account);
$this->drupalGet('<front>');
$assert_session = $this->assertSession();
// Block should be visible for the user.
$assert_session->pageTextContains('Announcements Feed');
// Block is not accessible without permission.
$this->drupalLogout();
$assert_session->pageTextNotContains('Announcements Feed');
// Test access() method return type.
$this->assertTrue($this->announceBlock
->getPlugin()
->access($account));
$this->assertInstanceOf(AccessResultAllowed::class, $this->announceBlock
->getPlugin()
->access($account, TRUE));
$this->assertFalse($this->announceBlock
->getPlugin()
->access($anonymous_account));
$this->assertInstanceOf(AccessResultNeutral::class, $this->announceBlock
->getPlugin()
->access($anonymous_account, TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.