function StyleSummaryTest::testSummaryView

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php \Drupal\Tests\views\Functional\Plugin\StyleSummaryTest::testSummaryView()
  2. 10 core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php \Drupal\Tests\views\Functional\Plugin\StyleSummaryTest::testSummaryView()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php \Drupal\Tests\views\Functional\Plugin\StyleSummaryTest::testSummaryView()

Tests a summary view.

File

core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php, line 59

Class

StyleSummaryTest
Tests the summary style plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testSummaryView() {
    $this->drupalGet('test-summary');
    // Ensure styles are properly added for summary views.
    $this->assertSession()
        ->responseContains('stable9/css/views/views.module.css');
    $summary_list = $this->cssSelect('ul.views-summary li');
    $this->assertCount(4, $summary_list);
    foreach ($summary_list as $summary_list_item) {
        $this->assertEquals('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
    }
    $summary_links = $this->cssSelect('ul.views-summary a');
    $this->assertCount(4, $summary_links);
    foreach ($summary_links as $index => $summary_link) {
        $this->assertEquals('type' . $index, trim($summary_link->getText()));
    }
    $this->clickLink('type1');
    $entries = $this->cssSelect('div.view-content div.views-row');
    $this->assertCount(2, $entries);
    // Add a base path to the summary settings.
    $edit = [
        'options[summary][options][default_summary][base_path]' => 'test-summary',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    // Test that the links still work.
    $this->drupalGet('test-summary');
    $this->clickLink('type1');
    $entries = $this->cssSelect('div.view-content div.views-row');
    $this->assertCount(2, $entries);
    // Change the summary display to an unformatted list displaying 3 items.
    $edit = [
        'options[summary][format]' => 'unformatted_summary',
        'options[summary][options][unformatted_summary][override]' => '1',
        'options[summary][options][unformatted_summary][items_per_page]' => '3',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
    $this->drupalGet('test-summary');
    $summary_list = $this->cssSelect('.views-summary-unformatted');
    $this->assertCount(3, $summary_list);
    foreach ($summary_list as $summary_list_item) {
        $this->assertEquals('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
    }
    $summary_links = $this->cssSelect('.views-summary-unformatted a');
    $this->assertCount(3, $summary_links);
    foreach ($summary_links as $index => $summary_link) {
        $this->assertEquals('type' . $index, trim($summary_link->getText()));
    }
    $this->clickLink('type1');
    $entries = $this->cssSelect('div.view-content div.views-row');
    $this->assertCount(2, $entries);
    // Add a base path to the summary settings.
    $edit = [
        'options[summary][options][unformatted_summary][base_path]' => 'test-summary',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    // Test that the links still work.
    $this->drupalGet('test-summary');
    $this->clickLink('type1');
    $entries = $this->cssSelect('div.view-content div.views-row');
    $this->assertCount(2, $entries);
    // Set base_path to an unknown path and test that the links lead to the
    // front page.
    $edit = [
        'options[summary][options][unformatted_summary][base_path]' => 'unknown-path',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    $this->drupalGet('test-summary');
    $this->assertSession()
        ->linkByHrefExists('/');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.