class AnnounceBlockTest
Same name and namespace in other branches
- 11.x core/modules/announcements_feed/tests/src/FunctionalJavascript/AnnounceBlockTest.php \Drupal\Tests\announcements_feed\FunctionalJavascript\AnnounceBlockTest
Test the announcement block test visibility.
@group announcements_feed
Hierarchy
- class \Drupal\Tests\announcements_feed\FunctionalJavascript\AnnounceBlockTest
Expanded class hierarchy of AnnounceBlockTest
File
-
core/
modules/ announcements_feed/ tests/ src/ FunctionalJavascript/ AnnounceBlockTest.php, line 19
Namespace
Drupal\Tests\announcements_feed\FunctionalJavascriptView source
class AnnounceBlockTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'announcements_feed',
'block',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* The announce block instance.
*
* @var \Drupal\block\BlockInterface
*/
protected BlockInterface $announceBlock;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
AnnounceTestHttpClientMiddleware::setAnnounceTestEndpoint('/announce-feed-json/community-feeds');
$this->announceBlock = $this->placeBlock('announce_block', [
'label' => 'Announcements Feed',
]);
}
/**
* Testing announce feed block visibility.
*/
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));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
AnnounceBlockTest::$announceBlock | protected | property | The announce block instance. |
AnnounceBlockTest::$defaultTheme | protected | property | The theme to install as the default for testing. |
AnnounceBlockTest::$modules | protected static | property | Modules to install. |
AnnounceBlockTest::setUp | protected | function | |
AnnounceBlockTest::testAnnounceWithoutPermission | public | function | Testing announce feed block visibility. |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.