public function JsLibraryTest::testJsDoesEnhanceConfiguredBlocks in Collapsiblock 4.x
Same name and namespace in other branches
- 3.x tests/src/FunctionalJavascript/JsLibraryTest.php \Drupal\Tests\collapsiblock\FunctionalJavascript\JsLibraryTest::testJsDoesEnhanceConfiguredBlocks()
Test JS modifies block HTML w/ Block collapse behavior !== "None".
File
- tests/
src/ FunctionalJavascript/ JsLibraryTest.php, line 15
Class
- JsLibraryTest
- Test the JS library operates on blocks with collapsiblock instance settings.
Namespace
Drupal\Tests\collapsiblock\FunctionalJavascriptCode
public function testJsDoesEnhanceConfiguredBlocks() {
// Set up a block to test with, with 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' => TRUE,
]);
$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 JS adds a 'collapsiblock-wrapper-' element inside the
// block.
$this
->assertSession()
->waitForElement('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//div[starts-with(@id, :innerWrapperIdStart)]', [
':blockId' => $testBlockHtmlId,
':innerWrapperIdStart' => 'collapsiblock-wrapper-',
]));
// Check that the JS adds a #collapse- link inside the block.
$this
->assertSession()
->waitForElement('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//a[starts-with(@href, :collapseLinkHrefStart)]', [
':blockId' => $testBlockHtmlId,
':collapseLinkHrefStart' => '#collapse-',
]));
$this
->getSession()
->getSelectorsHandler();
$this
->assertSession();
}