public function JsLibraryTest::testJsDoesNotEnhanceNoActionBlock in Collapsiblock 4.x
Same name and namespace in other branches
- 3.x tests/src/FunctionalJavascript/JsLibraryTest.php \Drupal\Tests\collapsiblock\FunctionalJavascript\JsLibraryTest::testJsDoesNotEnhanceNoActionBlock()
Test JS does not modify block HTML w/ Block collapse behavior == "None".
File
- tests/
src/ FunctionalJavascript/ JsLibraryTest.php, line 91
Class
- JsLibraryTest
- Test the JS library operates on blocks with collapsiblock instance settings.
Namespace
Drupal\Tests\collapsiblock\FunctionalJavascriptCode
public function testJsDoesNotEnhanceNoActionBlock() {
// Set up a block to test with, with a Block collapse behavior of "None",
// which we know will NOT result in a client-side DOM transformation.
$testBlock = $this
->drupalPlaceBlock('system_powered_by_block', [
'label_display' => TRUE,
]);
$this
->setCollapsiblockBlockInstanceSetting($testBlock, 1, '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 does not contain a 'collapsiblock-wrapper-' element
// inside it (indicating that it did not undergo a client-side DOM
// transformation).
$this
->assertSession()
->elementNotExists('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-',
]));
}