trait AssertBlockAppearsTrait in Drupal 8
Same name and namespace in other branches
- 9 core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php \Drupal\Tests\block\Functional\AssertBlockAppearsTrait
- 10 core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php \Drupal\Tests\block\Functional\AssertBlockAppearsTrait
Provides test assertions for testing block appearance.
Can be used by test classes that extend \Drupal\Tests\BrowserTestBase.
Hierarchy
- trait \Drupal\Tests\block\Functional\AssertBlockAppearsTrait
2 files declare their use of AssertBlockAppearsTrait
- DisplayBlockTest.php in core/
modules/ block/ tests/ src/ Functional/ Views/ DisplayBlockTest.php - ShortcutLinksTest.php in core/
modules/ shortcut/ tests/ src/ Functional/ ShortcutLinksTest.php
File
- core/
modules/ block/ tests/ src/ Functional/ AssertBlockAppearsTrait.php, line 13
Namespace
Drupal\Tests\block\FunctionalView source
trait AssertBlockAppearsTrait {
/**
* Checks to see whether a block appears on the page.
*
* @param \Drupal\block\Entity\Block $block
* The block entity to find on the page.
*/
protected function assertBlockAppears(Block $block) {
$result = $this
->findBlockInstance($block);
$this
->assertTrue(!empty($result), new FormattableMarkup('The block @id appears on the page', [
'@id' => $block
->id(),
]));
}
/**
* Checks to see whether a block does not appears on the page.
*
* @param \Drupal\block\Entity\Block $block
* The block entity to find on the page.
*/
protected function assertNoBlockAppears(Block $block) {
$result = $this
->findBlockInstance($block);
$this
->assertFalse(!empty($result), new FormattableMarkup('The block @id does not appear on the page', [
'@id' => $block
->id(),
]));
}
/**
* Find a block instance on the page.
*
* @param \Drupal\block\Entity\Block $block
* The block entity to find on the page.
*
* @return array
* The result from the xpath query.
*/
protected function findBlockInstance(Block $block) {
return $this
->xpath('//div[@id = :id]', [
':id' => 'block-' . $block
->id(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertBlockAppearsTrait:: |
protected | function | Checks to see whether a block appears on the page. | |
AssertBlockAppearsTrait:: |
protected | function | Checks to see whether a block does not appears on the page. | |
AssertBlockAppearsTrait:: |
protected | function | Find a block instance on the page. |