trait AssertBlockAppearsTrait

Same name in other branches
  1. 8.9.x core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php \Drupal\Tests\block\Functional\AssertBlockAppearsTrait
  2. 10 core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php \Drupal\Tests\block\Functional\AssertBlockAppearsTrait
  3. 11.x 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

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 12

Namespace

Drupal\Tests\block\Functional
View 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) {
        $this->assertSession()
            ->elementExists('xpath', "//div[@id = 'block-{$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) {
        $this->assertSession()
            ->elementNotExists('xpath', "//div[@id = 'block-{$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.
     *
     * @deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. There is no
     *   replacement.
     *
     * @see https://www.drupal.org/node/3293310
     */
    protected function findBlockInstance(Block $block) {
        @trigger_error(__METHOD__ . '() is deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3293310', E_USER_DEPRECATED);
        return $this->xpath('//div[@id = :id]', [
            ':id' => 'block-' . $block->id(),
        ]);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
AssertBlockAppearsTrait::assertBlockAppears protected function Checks to see whether a block appears on the page.
AssertBlockAppearsTrait::assertNoBlockAppears protected function Checks to see whether a block does not appears on the page.
AssertBlockAppearsTrait::findBlockInstance Deprecated protected function Find a block instance on the page.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.