diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index 717abcce703de7fa1b7b6126ecb248a5acdc8dc6..5e9e37a4b6414df0a59ea46cec7e2b0226cbbd6d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -52,7 +52,7 @@ public function setUp() { function testNodeTokenReplacement() { $url_options = array( 'absolute' => TRUE, - 'language' => $this->languageInterface, + 'language' => $this->interfaceLanguage, ); // Create a user and a node. @@ -82,14 +82,14 @@ function testNodeTokenReplacement() { $tests['[node:author]'] = String::checkPlain($account->getUsername()); $tests['[node:author:uid]'] = $node->getOwnerId(); $tests['[node:author:name]'] = String::checkPlain($account->getUsername()); - $tests['[node:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->languageInterface->id); - $tests['[node:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->languageInterface->id); + $tests['[node:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->interfaceLanguage->id); + $tests['[node:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->interfaceLanguage->id); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->languageInterface->id)); + $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->id)); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input))); } @@ -101,7 +101,7 @@ function testNodeTokenReplacement() { $tests['[node:author:name]'] = $account->getUsername(); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->languageInterface->id, 'sanitize' => FALSE)); + $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input))); } @@ -122,7 +122,7 @@ function testNodeTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->languageInterface)); + $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->interfaceLanguage)); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced for node without a summary.', array('%token' => $input))); } @@ -130,7 +130,7 @@ function testNodeTokenReplacement() { $tests['[node:summary]'] = $node->body->value; foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->languageInterface, 'sanitize' => FALSE)); + $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->interfaceLanguage, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced for node without a summary.', array('%token' => $input))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php index 623d99592e265ae7b6574759f94bdc4f0ff4e660..4ea7da1fac0120627e3688cba4e3418fdb9fd708 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php @@ -45,7 +45,7 @@ public function testSystemTokenRecognition() { foreach ($tests as $test) { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->languageInterface->id)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id)); $this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input))); } @@ -66,12 +66,12 @@ public function testClear() { // Replace with with the clear parameter, only the valid token should remain. $target = String::checkPlain(\Drupal::config('system.site')->get('name')); - $result = $this->tokenService->replace($source, array(), array('langcode' => $this->languageInterface->id, 'clear' => TRUE)); + $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->id, 'clear' => TRUE)); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); $target .= '[user:name]'; $target .= '[bogus:token]'; - $result = $this->tokenService->replace($source, array(), array('langcode' => $this->languageInterface->id)); + $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->id)); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); } @@ -83,7 +83,7 @@ public function testSystemSiteTokenReplacement() { $this->installSchema('system', 'url_alias'); $url_options = array( 'absolute' => TRUE, - 'language' => $this->languageInterface, + 'language' => $this->interfaceLanguage, ); $slogan = '<blink>Slogan</blink>'; @@ -111,7 +111,7 @@ public function testSystemSiteTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->languageInterface->id)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id)); $this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input))); } @@ -120,7 +120,7 @@ public function testSystemSiteTokenReplacement() { $tests['[site:slogan]'] = $config->get('slogan'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->languageInterface->id, 'sanitize' => FALSE)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input))); } @@ -146,18 +146,18 @@ public function testSystemDateTokenReplacement() { // Generate and test tokens. $tests = array(); $date_service = \Drupal::service('date'); - $tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $this->languageInterface->id); - $tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->languageInterface->id); - $tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->languageInterface->id); - $tests['[date:custom:m/j/Y]'] = $date_service->format($date, 'custom', 'm/j/Y', NULL, $this->languageInterface->id); - $tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->languageInterface->id); + $tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $this->interfaceLanguage->id); + $tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->interfaceLanguage->id); + $tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->interfaceLanguage->id); + $tests['[date:custom:m/j/Y]'] = $date_service->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->id); + $tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->id); $tests['[date:raw]'] = Xss::filter($date); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('date' => $date), array('langcode' => $this->languageInterface->id)); + $output = $this->tokenService->replace($input, array('date' => $date), array('langcode' => $this->interfaceLanguage->id)); $this->assertEqual($output, $expected, format_string('Date token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php index c13bd4c33e1db8d0eec2f300175a654eeda13afc..c68f2e1fc97e7fea32f030faa57d4edf2508127f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php @@ -20,7 +20,7 @@ abstract class TokenReplaceUnitTestBase extends EntityUnitTestBase { * * @var \Drupal\Core\Language\Language */ - protected $languageInterface; + protected $interfaceLanguage; /** * Token service. @@ -41,7 +41,7 @@ public function setUp() { // Install default system configuration. $this->installConfig(array('system')); - $this->languageInterface = \Drupal::languageManager()->getCurrentLanguage(); + $this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage(); $this->tokenService = \Drupal::token(); }