Skip to content
Snippets Groups Projects
Commit a0f1611a authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2270339 by YesCT, martin107: is a misleading variable name in TokenReplaceUnitTestBase.

parent 2ae7accf
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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)));
}
}
......
......@@ -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)));
}
}
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment