Issue #2270339 by YesCT, martin107: is a misleading variable name in TokenReplaceUnitTestBase.
parent
2ae7accf86
commit
a0f1611a0b
|
@ -52,7 +52,7 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||||
function testNodeTokenReplacement() {
|
function testNodeTokenReplacement() {
|
||||||
$url_options = array(
|
$url_options = array(
|
||||||
'absolute' => TRUE,
|
'absolute' => TRUE,
|
||||||
'language' => $this->languageInterface,
|
'language' => $this->interfaceLanguage,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a user and a node.
|
// Create a user and a node.
|
||||||
|
@ -82,14 +82,14 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||||
$tests['[node:author]'] = String::checkPlain($account->getUsername());
|
$tests['[node:author]'] = String::checkPlain($account->getUsername());
|
||||||
$tests['[node:author:uid]'] = $node->getOwnerId();
|
$tests['[node:author:uid]'] = $node->getOwnerId();
|
||||||
$tests['[node:author:name]'] = String::checkPlain($account->getUsername());
|
$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: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->languageInterface->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.
|
// Test to make sure that we generated something for each token.
|
||||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||||
$tests['[node:author:name]'] = $account->getUsername();
|
$tests['[node:author:name]'] = $account->getUsername();
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
|
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced for node without a summary.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||||
$tests['[node:summary]'] = $node->body->value;
|
$tests['[node:summary]'] = $node->body->value;
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced for node without a summary.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
foreach ($tests as $test) {
|
foreach ($tests as $test) {
|
||||||
$input = $test['prefix'] . '[site:name]' . $test['suffix'];
|
$input = $test['prefix'] . '[site:name]' . $test['suffix'];
|
||||||
$expected = $test['prefix'] . 'Drupal' . $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)));
|
$this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +66,12 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
|
|
||||||
// Replace with with the clear parameter, only the valid token should remain.
|
// Replace with with the clear parameter, only the valid token should remain.
|
||||||
$target = String::checkPlain(\Drupal::config('system.site')->get('name'));
|
$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.');
|
$this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
|
||||||
|
|
||||||
$target .= '[user:name]';
|
$target .= '[user:name]';
|
||||||
$target .= '[bogus:token]';
|
$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.');
|
$this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
$this->installSchema('system', 'url_alias');
|
$this->installSchema('system', 'url_alias');
|
||||||
$url_options = array(
|
$url_options = array(
|
||||||
'absolute' => TRUE,
|
'absolute' => TRUE,
|
||||||
'language' => $this->languageInterface,
|
'language' => $this->interfaceLanguage,
|
||||||
);
|
);
|
||||||
|
|
||||||
$slogan = '<blink>Slogan</blink>';
|
$slogan = '<blink>Slogan</blink>';
|
||||||
|
@ -111,7 +111,7 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
$tests['[site:slogan]'] = $config->get('slogan');
|
$tests['[site:slogan]'] = $config->get('slogan');
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,18 +146,18 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
|
||||||
// Generate and test tokens.
|
// Generate and test tokens.
|
||||||
$tests = array();
|
$tests = array();
|
||||||
$date_service = \Drupal::service('date');
|
$date_service = \Drupal::service('date');
|
||||||
$tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $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->languageInterface->id);
|
$tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->interfaceLanguage->id);
|
||||||
$tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->languageInterface->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->languageInterface->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->languageInterface->id);
|
$tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->id);
|
||||||
$tests['[date:raw]'] = Xss::filter($date);
|
$tests['[date:raw]'] = Xss::filter($date);
|
||||||
|
|
||||||
// Test to make sure that we generated something for each token.
|
// Test to make sure that we generated something for each token.
|
||||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||||
|
|
||||||
foreach ($tests as $input => $expected) {
|
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)));
|
$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
|
* @var \Drupal\Core\Language\Language
|
||||||
*/
|
*/
|
||||||
protected $languageInterface;
|
protected $interfaceLanguage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token service.
|
* Token service.
|
||||||
|
@ -41,7 +41,7 @@ abstract class TokenReplaceUnitTestBase extends EntityUnitTestBase {
|
||||||
// Install default system configuration.
|
// Install default system configuration.
|
||||||
$this->installConfig(array('system'));
|
$this->installConfig(array('system'));
|
||||||
|
|
||||||
$this->languageInterface = \Drupal::languageManager()->getCurrentLanguage();
|
$this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage();
|
||||||
$this->tokenService = \Drupal::token();
|
$this->tokenService = \Drupal::token();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue