View source
<?php
namespace Drupal\Tests\collapsiblock\FunctionalJavascript;
class CollapseActionTest extends CollapsiblockJavaScriptTestBase {
protected $collapsiblockTestBlock;
protected $collapsiblockTestBlockHtmlId;
protected $collapsiblockTestBlockTitleXpath;
protected $collapsiblockTestBlockContentXpath;
public function setUp() : void {
parent::setUp();
$this->collapsiblockTestBlock = $this
->drupalPlaceBlock('system_powered_by_block', [
'label_display' => TRUE,
]);
$this->collapsiblockTestBlockHtmlId = 'block-' . $this->collapsiblockTestBlock
->id();
$this->collapsiblockTestBlockTitleXpath = $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//h2', [
':blockId' => $this->collapsiblockTestBlockHtmlId,
]);
$this->collapsiblockTestBlockContentXpath = $this
->assertSession()
->buildXPathQuery('//*[@id=:blockId]//span', [
':blockId' => $this->collapsiblockTestBlockHtmlId,
]);
}
public function testCollapsibleAlwaysCollapsed() {
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 4, 'collapse_action');
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$beforeTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($beforeTitle);
$this
->assertTrue($beforeTitle
->isVisible());
$beforeContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($beforeContent);
$this
->assertFalse($beforeContent
->isVisible());
$this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath)
->click();
$afterTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($afterTitle);
$this
->assertTrue($afterTitle
->isVisible());
$afterContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($afterContent);
$this
->assertTrue($afterContent
->isVisible());
}
public function testCollapsibleAlwaysExpanded() {
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 5, 'collapse_action');
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$beforeTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($beforeTitle);
$this
->assertTrue($beforeTitle
->isVisible());
$beforeContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($beforeContent);
$this
->assertTrue($beforeContent
->isVisible());
$this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath)
->click();
$afterTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($afterTitle);
$this
->assertTrue($afterTitle
->isVisible());
$afterContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($afterContent);
$this
->assertFalse($afterContent
->isVisible());
}
public function testCollapsibleDefaultCollapsed() {
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 3, 'collapse_action');
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$beforeTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($beforeTitle);
$this
->assertTrue($beforeTitle
->isVisible());
$beforeContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($beforeContent);
$this
->assertFalse($beforeContent
->isVisible());
$this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath)
->click();
$afterTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($afterTitle);
$this
->assertTrue($afterTitle
->isVisible());
$afterContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($afterContent);
$this
->assertTrue($afterContent
->isVisible());
}
public function testCollapsibleDefaultExpanded() {
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 2, 'collapse_action');
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$beforeTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($beforeTitle);
$this
->assertTrue($beforeTitle
->isVisible());
$beforeContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($beforeContent);
$this
->assertTrue($beforeContent
->isVisible());
$this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath)
->click();
$afterTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($afterTitle);
$this
->assertTrue($afterTitle
->isVisible());
$afterContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($afterContent);
$this
->assertFalse($afterContent
->isVisible());
}
public function testNoAction() {
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 1, 'collapse_action');
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$beforeTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($beforeTitle);
$this
->assertTrue($beforeTitle
->isVisible());
$beforeContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($beforeContent);
$this
->assertTrue($beforeContent
->isVisible());
$this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath)
->click();
$afterTitle = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockTitleXpath);
$this
->assertNotNull($afterTitle);
$this
->assertTrue($afterTitle
->isVisible());
$afterContent = $this
->getSession()
->getPage()
->find('xpath', $this->collapsiblockTestBlockContentXpath);
$this
->assertNotNull($afterContent);
$this
->assertTrue($afterContent
->isVisible());
}
}