View source
<?php
namespace Drupal\Tests\collapsiblock\FunctionalJavascript;
class JsLibraryTest extends CollapsiblockJavaScriptTestBase {
public function testJsDoesEnhanceConfiguredBlocks() {
$testBlock = $this
->drupalPlaceBlock('system_powered_by_block', [
'label_display' => TRUE,
]);
$this
->setCollapsiblockBlockInstanceSetting($testBlock, 2, 'collapse_action');
$testBlockHtmlId = 'block-' . $testBlock
->id();
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$this
->assertSession()
->elementExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]', [
':blockId' => $testBlockHtmlId,
]));
$this
->assertSession()
->waitForElement('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//div[starts-with(@id, :innerWrapperIdStart)]', [
':blockId' => $testBlockHtmlId,
':innerWrapperIdStart' => 'collapsiblock-wrapper-',
]));
$this
->assertSession()
->waitForElement('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//a[starts-with(@href, :collapseLinkHrefStart)]', [
':blockId' => $testBlockHtmlId,
':collapseLinkHrefStart' => '#collapse-',
]));
$this
->getSession()
->getSelectorsHandler();
$this
->assertSession();
}
public function testBlockWithoutBlockTitlePartiallyAffected() {
$testBlock = $this
->drupalPlaceBlock('system_powered_by_block', [
'label_display' => FALSE,
]);
$this
->setCollapsiblockBlockInstanceSetting($testBlock, 2, 'collapse_action');
$testBlockHtmlId = 'block-' . $testBlock
->id();
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$this
->assertSession()
->elementExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]', [
':blockId' => $testBlockHtmlId,
]));
$this
->assertSession()
->elementExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//div[starts-with(@id, :innerWrapperIdStart)]', [
':blockId' => $testBlockHtmlId,
':innerWrapperIdStart' => 'collapsiblock-wrapper-',
]));
$this
->assertSession()
->elementNotExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//a[starts-with(@href, :collapseLinkHrefStart)]', [
':blockId' => $testBlockHtmlId,
':collapseLinkHrefStart' => '#collapse-',
]));
}
public function testJsDoesNotEnhanceNoActionBlock() {
$testBlock = $this
->drupalPlaceBlock('system_powered_by_block', [
'label_display' => TRUE,
]);
$this
->setCollapsiblockBlockInstanceSetting($testBlock, 1, 'collapse_action');
$testBlockHtmlId = 'block-' . $testBlock
->id();
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$this
->assertSession()
->elementExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]', [
':blockId' => $testBlockHtmlId,
]));
$this
->assertSession()
->elementNotExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//div[starts-with(@id, :innerWrapperIdStart)]', [
':blockId' => $testBlockHtmlId,
':innerWrapperIdStart' => 'collapsiblock-wrapper-',
]));
$this
->assertSession()
->elementNotExists('xpath', $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//a[starts-with(@href, :collapseLinkHrefStart)]', [
':blockId' => $testBlockHtmlId,
':collapseLinkHrefStart' => '#collapse-',
]));
}
}