public function PageTitleTest::testRoutingTitle in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/System/PageTitleTest.php \Drupal\system\Tests\System\PageTitleTest::testRoutingTitle()
Tests the page title of render arrays.
See also
\Drupal\test_page_test\Controller\Test
File
- core/
modules/ system/ src/ Tests/ System/ PageTitleTest.php, line 105 - Contains \Drupal\system\Tests\System\PageTitleTest.
Class
- PageTitleTest
- Tests HTML output escaping of page title, site name, and slogan.
Namespace
Drupal\system\Tests\SystemCode
public function testRoutingTitle() {
// Test the '#title' render array attribute.
$this
->drupalGet('test-render-title');
$this
->assertTitle('Foo | Drupal');
$result = $this
->xpath('//h1[@class="page-title"]');
$this
->assertEqual('Foo', (string) $result[0]);
// Test forms
$this
->drupalGet('form-test/object-builder');
$this
->assertTitle('Test dynamic title | Drupal');
$result = $this
->xpath('//h1[@class="page-title"]');
$this
->assertEqual('Test dynamic title', (string) $result[0]);
// Set some custom translated strings.
$this
->addCustomTranslations('en', array(
'' => array(
'Static title' => 'Static title translated',
),
));
$this
->writeCustomTranslations();
// Ensure that the title got translated.
$this
->drupalGet('test-page-static-title');
$this
->assertTitle('Static title translated | Drupal');
$result = $this
->xpath('//h1[@class="page-title"]');
$this
->assertEqual('Static title translated', (string) $result[0]);
// Test the dynamic '_title_callback' route option.
$this
->drupalGet('test-page-dynamic-title');
$this
->assertTitle('Dynamic title | Drupal');
$result = $this
->xpath('//h1[@class="page-title"]');
$this
->assertEqual('Dynamic title', (string) $result[0]);
// Ensure that titles are cacheable and are escaped normally if the
// controller does not escape them.
$this
->drupalGet('test-page-cached-controller');
$this
->assertTitle('Cached title | Drupal');
$this
->assertRaw(Html::escape('<span>Cached title</span>') . '</h1>');
$this
->drupalGet('test-page-cached-controller');
$this
->assertTitle('Cached title | Drupal');
$this
->assertRaw(Html::escape('<span>Cached title</span>') . '</h1>');
}