function AreaTitleWebTest::testTitleText

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

Tests the title area handler.

File

core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php, line 40

Class

AreaTitleWebTest
Tests the title area handler with a web test.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testTitleText() {
    // Confirm that the view has the normal title before making the view return
    // no result.
    $this->drupalGet('test-area-title');
    $this->assertSession()
        ->titleEquals('test_title_header | Drupal');
    // Change the view to return no result.
    
    /** @var \Drupal\views\Entity\View $view */
    $view = View::load('test_area_title');
    $display =& $view->getDisplay('default');
    $display['display_options']['filters']['name'] = [
        'field' => 'name',
        'id' => 'name',
        'table' => 'views_test_data',
        'relationship' => 'none',
        'plugin_id' => 'string',
        // Add a value which does not exist. The dataset is defined in
        // \Drupal\views\Tests\ViewTestData::dataSet().
'value' => 'Euler',
    ];
    $view->save();
    $this->drupalGet('test-area-title');
    $this->assertSession()
        ->titleEquals('test_title_empty | Drupal');
    // Change the view to return a result instead.
    
    /** @var \Drupal\views\Entity\View $view */
    $view = View::load('test_area_title');
    $display =& $view->getDisplay('default');
    $display['display_options']['filters']['name'] = [
        'field' => 'name',
        'id' => 'name',
        'table' => 'views_test_data',
        'relationship' => 'none',
        'plugin_id' => 'string',
        // Change to a value which does exist. The dataset is defined in
        // \Drupal\views\Tests\ViewTestData::dataSet().
'value' => 'Ringo',
    ];
    $view->save();
    $this->drupalGet('test-area-title');
    $this->assertSession()
        ->titleEquals('test_title_header | Drupal');
}

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