function TitleResolverTest::testStaticTitleWithNullAndArrayValueParameter

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testStaticTitleWithNullAndArrayValueParameter()
  2. 11.x core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testStaticTitleWithNullAndArrayValueParameter()

Tests a static title with a non-scalar value parameter.

See also

\Drupal\Core\Controller\TitleResolver::getTitle()

File

core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php, line 124

Class

TitleResolverTest
@coversDefaultClass \Drupal\Core\Controller\TitleResolver @group Controller

Namespace

Drupal\Tests\Core\Controller

Code

public function testStaticTitleWithNullAndArrayValueParameter() {
    $raw_variables = new ParameterBag([
        'test1' => NULL,
        'test2' => [
            'foo' => 'bar',
        ],
        'test3' => 'value',
    ]);
    $request = new Request();
    $request->attributes
        ->set('_raw_variables', $raw_variables);
    $route = new Route('/test-route', [
        '_title' => 'static title %test1 @test1 %test2 @test2 %test3 @test3',
    ]);
    $translatable_markup = $this->titleResolver
        ->getTitle($request, $route);
    $arguments = $translatable_markup->getArguments();
    $this->assertNotContains('@test1', $arguments);
    $this->assertNotContains('%test1', $arguments);
    $this->assertNotContains('@test2', $arguments);
    $this->assertNotContains('%test2', $arguments);
    $this->assertSame('value', $translatable_markup->getArguments()['@test3']);
    $this->assertSame('value', $translatable_markup->getArguments()['%test3']);
}

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