function TokenTest::testGetInfo

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::testGetInfo()
  2. 8.9.x core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::testGetInfo()
  3. 10 core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::testGetInfo()

@covers ::getInfo

File

core/tests/Drupal/Tests/Core/Utility/TokenTest.php, line 110

Class

TokenTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21Token.php/class/Token/11.x" title="Drupal placeholder/token replacement system." class="local">\Drupal\Core\Utility\Token</a> @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGetInfo() : void {
    $token_info = [
        'types' => [
            'foo' => [
                'name' => $this->randomMachineName(),
            ],
        ],
    ];
    $this->language
        ->expects($this->atLeastOnce())
        ->method('getId')
        ->willReturn($this->randomMachineName());
    $this->languageManager
        ->expects($this->once())
        ->method('getCurrentLanguage')
        ->with(LanguageInterface::TYPE_CONTENT)
        ->willReturn($this->language);
    // The persistent cache must only be hit once, after which the info is
    // cached statically.
    $this->cache
        ->expects($this->once())
        ->method('get');
    $this->cache
        ->expects($this->once())
        ->method('set')
        ->with('token_info:' . $this->language
        ->getId(), $token_info);
    $this->moduleHandler
        ->expects($this->once())
        ->method('invokeAll')
        ->with('token_info')
        ->willReturn($token_info);
    $this->moduleHandler
        ->expects($this->once())
        ->method('alter')
        ->with('token_info', $token_info);
    // Get the information for the first time. The cache should be checked, the
    // hooks invoked, and the info should be set to the cache should.
    $this->token
        ->getInfo();
    // Get the information for the second time. The data must be returned from
    // the static cache, so the persistent cache must not be accessed and the
    // hooks must not be invoked.
    $this->token
        ->getInfo();
}

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