diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index 24ab81e..e81eed6 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -344,8 +344,9 @@ public function getInfo() { $this->tokenInfo = $cache->data; } else { + $this->tokenInfo = array(); /** @var \Drupal\Core\Token\TokenTypeInterface $token_type */ - foreach ($this->tokenTypes as $token_type) { + foreach ($this->getTokenTypes() as $token_type) { $this->tokenInfo += $token_type->getTokenInfo(); } $this->tokenInfo += $this->moduleHandler->invokeAll('token_info'); diff --git a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php index 3736f0b..9873543 100644 --- a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php @@ -45,6 +45,14 @@ class TokenTest extends UnitTestCase { */ protected $token; + + /** + * The token type manager. + * + * @var \Drupal\Core\Token\TokenTypeManager + */ + protected $tokenTypeManager; + /** * {@inheritdoc} */ @@ -55,7 +63,11 @@ protected function setUp() { $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); - $this->token = new Token($this->moduleHandler, $this->cache, $this->languageManager); + $this->tokenTypeManager = $this->getMockBuilder('\Drupal\Core\Token\TokenTypeManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->token = new Token($this->moduleHandler, $this->cache, $this->languageManager, $this->tokenTypeManager); } /** @@ -94,6 +106,10 @@ public function testGetInfo() { ->method('alter') ->with('token_info', $token_info); + $this->tokenTypeManager->expects($this->once()) + ->method('getDefinitions') + ->will($this->returnValue(array())); + // 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();