You are here

public function JsLibraryTest::testBlockWithoutBlockTitlePartiallyAffected in Collapsiblock 4.x

Same name and namespace in other branches
  1. 3.x tests/src/FunctionalJavascript/JsLibraryTest.php \Drupal\Tests\collapsiblock\FunctionalJavascript\JsLibraryTest::testBlockWithoutBlockTitlePartiallyAffected()

Test JS only partially modifies a block without a title.

File

tests/src/FunctionalJavascript/JsLibraryTest.php, line 54

Class

JsLibraryTest
Test the JS library operates on blocks with collapsiblock instance settings.

Namespace

Drupal\Tests\collapsiblock\FunctionalJavascript

Code

public function testBlockWithoutBlockTitlePartiallyAffected() {

  // Set up a block to test with, WITHOUT a label, with a Block collapse
  // behavior which we know will result in a client-side DOM transformation.
  $testBlock = $this
    ->drupalPlaceBlock('system_powered_by_block', [
    'label_display' => FALSE,
  ]);
  $this
    ->setCollapsiblockBlockInstanceSetting($testBlock, 2, 'collapse_action');
  $testBlockHtmlId = 'block-' . $testBlock
    ->id();

  // Load a page that the block will be displayed on.
  $this
    ->drupalLogin($this
    ->getCollapsiblockUnprivilegedUser());
  $this
    ->drupalGet('<front>');

  // Check that the block is on the page.
  $this
    ->assertSession()
    ->elementExists('xpath', $this
    ->assertSession()
    ->buildXPathQuery('//*[@id=:blockId]', [
    ':blockId' => $testBlockHtmlId,
  ]));

  // Check that the block contains a 'collapsiblock-wrapper-' element inside
  // it (indicating that it did undergo a client-side DOM transformation).
  $this
    ->assertSession()
    ->elementExists('xpath', $this
    ->assertSession()
    ->buildXPathQuery('//*[@id=:blockId]//div[starts-with(@id, :innerWrapperIdStart)]', [
    ':blockId' => $testBlockHtmlId,
    ':innerWrapperIdStart' => 'collapsiblock-wrapper-',
  ]));

  // Check that the block does not contain a #collapse- link inside it
  // (indicating that it did not undergo a client-side DOM transformation).
  $this
    ->assertSession()
    ->elementNotExists('xpath', $this
    ->assertSession()
    ->buildXPathQuery('//*[@id=:blockId]//a[starts-with(@href, :collapseLinkHrefStart)]', [
    ':blockId' => $testBlockHtmlId,
    ':collapseLinkHrefStart' => '#collapse-',
  ]));
}