You are here

public function ViewsAccordionTest::testViewsAccordion in Views Accordion 8

Same name in this branch
  1. 8 tests/src/Functional/ViewsAccordionTest.php \Drupal\Tests\views_accordion\Functional\ViewsAccordionTest::testViewsAccordion()
  2. 8 tests/src/FunctionalJavascript/ViewsAccordionTest.php \Drupal\Tests\views_accordion\FunctionalJavascript\ViewsAccordionTest::testViewsAccordion()
Same name and namespace in other branches
  1. 2.0.x tests/src/FunctionalJavascript/ViewsAccordionTest.php \Drupal\Tests\views_accordion\FunctionalJavascript\ViewsAccordionTest::testViewsAccordion()

Tests Views Accordion functionality.

File

tests/src/FunctionalJavascript/ViewsAccordionTest.php, line 62

Class

ViewsAccordionTest
Tests the JavaScript functionality of the Views Accordion module.

Namespace

Drupal\Tests\views_accordion\FunctionalJavascript

Code

public function testViewsAccordion() {
  $this
    ->drupalGet('views-accordion-test');
  $driver = $this
    ->getSession()
    ->getDriver();

  // Assert our JS settings are available.
  $settings = $this
    ->getDrupalSettings();
  $this
    ->assertArrayHasKey('views_accordion', $settings, 'Views accordion JS settings avaialable');

  // Assert that the first row is visible but not the second.
  $driver
    ->isVisible($this
    ->cssSelectToXpath('#ui-id-2'));
  $this
    ->assertFalse($driver
    ->isVisible($this
    ->cssSelectToXpath('#ui-id-4')), 'Row two is collapsed');

  // Assert that clicking the first row does not close it.
  $this
    ->click('#ui-id-1');
  $driver
    ->isVisible($this
    ->cssSelectToXpath('#ui-id-2'));

  // Assert the header icons are displayed in the correct place.
  $driver
    ->isVisible($this
    ->cssSelectToXpath('#ui-id-1 span.ui-icon-triangle-1-s'));
  $driver
    ->isVisible($this
    ->cssSelectToXpath('#ui-id-3 span.ui-icon-triangle-1-e'));

  // Test the grouping functionality.
  $this
    ->drupalGet('views-accordion-test-grouping');

  // Assert the first header is the first user name.
  $this
    ->assertEquals($this->user1
    ->getAccountName(), $driver
    ->getText($this
    ->cssSelectToXpath('#ui-id-1')));
  $first_group_xpath = $this
    ->cssSelectToXpath('#ui-id-2');
  $driver
    ->isVisible($first_group_xpath);

  // Assert correct nodes are in the first group.
  $first_group_content = $driver
    ->getText($first_group_xpath);
  $this
    ->assertContains($this->nodes[0]
    ->getTitle(), $first_group_content, 'First node is on first accordion group');
  $this
    ->assertContains($this->nodes[1]
    ->getTitle(), $first_group_content, 'Second node is on first accordion group');
  $this
    ->assertNotContains($this->nodes[2]
    ->getTitle(), $first_group_content, 'Third node is not on first accordion group');
  $this
    ->assertNotContains($this->nodes[3]
    ->getTitle(), $first_group_content, 'Fourth node is not on first accordion group');

  // Assert the second accordion header is the second user name.
  $this
    ->assertEquals($this->user2
    ->getAccountName(), $driver
    ->getText($this
    ->cssSelectToXpath('#ui-id-3')));
  $second_group_xpath = $this
    ->cssSelectToXpath('#ui-id-4');
  $this
    ->assertFalse($driver
    ->isVisible($second_group_xpath), 'Second accordion group is collapsed');
  $this
    ->click('#ui-id-3');
  $driver
    ->isVisible($second_group_xpath);

  // Assert correct nodes are in the second group.
  $second_group_content = $driver
    ->getText($second_group_xpath);
  $this
    ->assertNotContains($this->nodes[0]
    ->getTitle(), $second_group_content, 'First node is not on second accordion group');
  $this
    ->assertNotContains($this->nodes[1]
    ->getTitle(), $second_group_content, 'Second node is not on second accordion group');
  $this
    ->assertContains($this->nodes[2]
    ->getTitle(), $second_group_content, 'Third node is on second accordion group');
  $this
    ->assertContains($this->nodes[3]
    ->getTitle(), $second_group_content, 'Fourth node is on second accordion group');
}