Mercurial > hg > isophonics-drupal-site
annotate core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Tests\block\Functional; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\block\Entity\Block; |
Chris@0 | 6 use Drupal\Component\Render\FormattableMarkup; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Provides test assertions for testing block appearance. |
Chris@0 | 10 * |
Chris@0 | 11 * Can be used by test classes that extend \Drupal\Tests\BrowserTestBase. |
Chris@0 | 12 */ |
Chris@0 | 13 trait AssertBlockAppearsTrait { |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * Checks to see whether a block appears on the page. |
Chris@0 | 17 * |
Chris@0 | 18 * @param \Drupal\block\Entity\Block $block |
Chris@0 | 19 * The block entity to find on the page. |
Chris@0 | 20 */ |
Chris@0 | 21 protected function assertBlockAppears(Block $block) { |
Chris@0 | 22 $result = $this->findBlockInstance($block); |
Chris@0 | 23 $this->assertTrue(!empty($result), new FormattableMarkup('The block @id appears on the page', ['@id' => $block->id()])); |
Chris@0 | 24 } |
Chris@0 | 25 |
Chris@0 | 26 /** |
Chris@0 | 27 * Checks to see whether a block does not appears on the page. |
Chris@0 | 28 * |
Chris@0 | 29 * @param \Drupal\block\Entity\Block $block |
Chris@0 | 30 * The block entity to find on the page. |
Chris@0 | 31 */ |
Chris@0 | 32 protected function assertNoBlockAppears(Block $block) { |
Chris@0 | 33 $result = $this->findBlockInstance($block); |
Chris@0 | 34 $this->assertFalse(!empty($result), new FormattableMarkup('The block @id does not appear on the page', ['@id' => $block->id()])); |
Chris@0 | 35 } |
Chris@0 | 36 |
Chris@0 | 37 /** |
Chris@0 | 38 * Find a block instance on the page. |
Chris@0 | 39 * |
Chris@0 | 40 * @param \Drupal\block\Entity\Block $block |
Chris@0 | 41 * The block entity to find on the page. |
Chris@0 | 42 * |
Chris@0 | 43 * @return array |
Chris@0 | 44 * The result from the xpath query. |
Chris@0 | 45 */ |
Chris@0 | 46 protected function findBlockInstance(Block $block) { |
Chris@0 | 47 return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); |
Chris@0 | 48 } |
Chris@0 | 49 |
Chris@0 | 50 } |