Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / block / tests / src / Functional / AssertBlockAppearsTrait.php
1 <?php
2
3 namespace Drupal\Tests\block\Functional;
4
5 use Drupal\block\Entity\Block;
6 use Drupal\Component\Render\FormattableMarkup;
7
8 /**
9  * Provides test assertions for testing block appearance.
10  *
11  * Can be used by test classes that extend \Drupal\Tests\BrowserTestBase.
12  */
13 trait AssertBlockAppearsTrait {
14
15   /**
16    * Checks to see whether a block appears on the page.
17    *
18    * @param \Drupal\block\Entity\Block $block
19    *   The block entity to find on the page.
20    */
21   protected function assertBlockAppears(Block $block) {
22     $result = $this->findBlockInstance($block);
23     $this->assertTrue(!empty($result), new FormattableMarkup('The block @id appears on the page', ['@id' => $block->id()]));
24   }
25
26   /**
27    * Checks to see whether a block does not appears on the page.
28    *
29    * @param \Drupal\block\Entity\Block $block
30    *   The block entity to find on the page.
31    */
32   protected function assertNoBlockAppears(Block $block) {
33     $result = $this->findBlockInstance($block);
34     $this->assertFalse(!empty($result), new FormattableMarkup('The block @id does not appear on the page', ['@id' => $block->id()]));
35   }
36
37   /**
38    * Find a block instance on the page.
39    *
40    * @param \Drupal\block\Entity\Block $block
41    *   The block entity to find on the page.
42    *
43    * @return array
44    *   The result from the xpath query.
45    */
46   protected function findBlockInstance(Block $block) {
47     return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]);
48   }
49
50 }