You are here

public function CollapseActionTest::testCollapsibleDefaultCollapsed in Collapsiblock 3.x

Same name and namespace in other branches
  1. 4.x tests/src/FunctionalJavascript/CollapseActionTest.php \Drupal\Tests\collapsiblock\FunctionalJavascript\CollapseActionTest::testCollapsibleDefaultCollapsed()

Test the "Collapsible, collapsed by default" Block Collapse Behavior.

File

tests/src/FunctionalJavascript/CollapseActionTest.php, line 125

Class

CollapseActionTest
Test that collapse actions work as-intended.

Namespace

Drupal\Tests\collapsiblock\FunctionalJavascript

Code

public function testCollapsibleDefaultCollapsed() {

  // Set the collapse action.
  $this
    ->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 3, 'collapse_action');

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

  // Check that initially, the block title is visible but the contents are not
  // visible.
  $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());

  // Click on the block title.
  $this
    ->getSession()
    ->getPage()
    ->find('xpath', $this->collapsiblockTestBlockTitleXpath)
    ->click();

  // Check that the block title and contents are visible after the 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());
}