Commit 2b0e042b authored by catch's avatar catch

Issue #2195623 by olli: Remove t() from default test assertions in WebTestBase class.

parent 2c7b99d0
......@@ -326,7 +326,7 @@ protected function drupalCreateContentType(array $values = array()) {
$status = $type->save();
menu_router_rebuild();
$this->assertEqual($status, SAVED_NEW, t('Created content type %type.', array('%type' => $type->id())));
$this->assertEqual($status, SAVED_NEW, String::format('Created content type %type.', array('%type' => $type->id())));
// Reset permissions so that permissions for this content type are
// available.
......@@ -582,10 +582,10 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL
}
$result = $role->save();
$this->assertIdentical($result, SAVED_NEW, t('Created role ID @rid with name @name.', array(
$this->assertIdentical($result, SAVED_NEW, String::format('Created role ID @rid with name @name.', array(
'@name' => var_export($role->label(), TRUE),
'@rid' => var_export($role->id(), TRUE),
)), t('Role'));
)), 'Role');
if ($result === SAVED_NEW) {
// Grant the specified permissions to the role, if any.
......@@ -594,10 +594,10 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL
$assigned_permissions = entity_load('user_role', $role->id())->permissions;
$missing_permissions = array_diff($permissions, $assigned_permissions);
if (!$missing_permissions) {
$this->pass(t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role'));
$this->pass(String::format('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), 'Role');
}
else {
$this->fail(t('Failed to create permissions: @perms', array('@perms' => implode(', ', $missing_permissions))), t('Role'));
$this->fail(String::format('Failed to create permissions: @perms', array('@perms' => implode(', ', $missing_permissions))), 'Role');
}
}
return $role->id();
......@@ -628,7 +628,7 @@ protected function checkPermissions(array $permissions, $reset = FALSE) {
$valid = TRUE;
foreach ($permissions as $permission) {
if (!in_array($permission, $available)) {
$this->fail(t('Invalid permission %permission.', array('%permission' => $permission)), t('Role'));
$this->fail(String::format('Invalid permission %permission.', array('%permission' => $permission)), 'Role');
$valid = FALSE;
}
}
......@@ -859,7 +859,7 @@ protected function setUp() {
if ($modules) {
$modules = array_unique($modules);
$success = \Drupal::moduleHandler()->install($modules, TRUE);
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
$this->assertTrue($success, String::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
$this->rebuildContainer();
}
......@@ -1348,14 +1348,14 @@ protected function parse() {
$htmlDom = new \DOMDocument();
@$htmlDom->loadHTML('<?xml encoding="UTF-8">' . $this->drupalGetContent());
if ($htmlDom) {
$this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
$this->pass(String::format('Valid HTML found on "@path"', array('@path' => $this->getUrl())), 'Browser');
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
$this->elements = simplexml_import_dom($htmlDom);
}
}
if (!$this->elements) {
$this->fail(t('Parsed page successfully.'), t('Browser'));
$this->fail('Parsed page successfully.', 'Browser');
}
return $this->elements;
......@@ -1603,7 +1603,7 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array(
}
// We have not found a form which contained all fields of $edit.
foreach ($edit as $name => $value) {
$this->fail(t('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
$this->fail(String::format('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
}
if (!$ajax && isset($submit)) {
$this->assertTrue($submit_matches, format_string('Found the @submit button', array('@submit' => $submit)));
......@@ -2286,7 +2286,7 @@ protected function getAllOptions(\SimpleXMLElement $element) {
*/
protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
$message = ($message ? $message : t('Link with label %label found.', array('%label' => $label)));
$message = ($message ? $message : String::format('Link with label %label found.', array('%label' => $label)));
return $this->assert(isset($links[$index]), $message, $group);
}
......@@ -2312,7 +2312,7 @@ protected function assertLink($label, $index = 0, $message = '', $group = 'Other
*/
protected function assertNoLink($label, $message = '', $group = 'Other') {
$links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
$message = ($message ? $message : t('Link with label %label not found.', array('%label' => $label)));
$message = ($message ? $message : String::format('Link with label %label not found.', array('%label' => $label)));
return $this->assert(empty($links), $message, $group);
}
......@@ -2338,7 +2338,7 @@ protected function assertNoLink($label, $message = '', $group = 'Other') {
*/
protected function assertLinkByHref($href, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[contains(@href, :href)]', array(':href' => $href));
$message = ($message ? $message : t('Link containing href %href found.', array('%href' => $href)));
$message = ($message ? $message : String::format('Link containing href %href found.', array('%href' => $href)));
return $this->assert(isset($links[$index]), $message, $group);
}
......@@ -2362,7 +2362,7 @@ protected function assertLinkByHref($href, $index = 0, $message = '', $group = '
*/
protected function assertNoLinkByHref($href, $message = '', $group = 'Other') {
$links = $this->xpath('//a[contains(@href, :href)]', array(':href' => $href));
$message = ($message ? $message : t('No link containing href %href found.', array('%href' => $href)));
$message = ($message ? $message : String::format('No link containing href %href found.', array('%href' => $href)));
return $this->assert(empty($links), $message, $group);
}
......@@ -2622,7 +2622,7 @@ protected function drupalSetSettings($settings) {
*/
protected function assertUrl($path, array $options = array(), $message = '', $group = 'Other') {
if (!$message) {
$message = t('Current URL is @url.', array(
$message = String::format('Current URL is @url.', array(
'@url' => var_export($this->container->get('url_generator')->generateFromPath($path, $options), TRUE),
));
}
......@@ -2656,7 +2656,7 @@ protected function assertUrl($path, array $options = array(), $message = '', $gr
*/
protected function assertRaw($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = t('Raw "@raw" found', array('@raw' => $raw));
$message = String::format('Raw "@raw" found', array('@raw' => $raw));
}
return $this->assert(strpos($this->drupalGetContent(), $raw) !== FALSE, $message, $group);
}
......@@ -2683,7 +2683,7 @@ protected function assertRaw($raw, $message = '', $group = 'Other') {
*/
protected function assertNoRaw($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = t('Raw "@raw" not found', array('@raw' => $raw));
$message = String::format('Raw "@raw" not found', array('@raw' => $raw));
}
return $this->assert(strpos($this->drupalGetContent(), $raw) === FALSE, $message, $group);
}
......@@ -2767,7 +2767,7 @@ protected function assertTextHelper($text, $message = '', $group, $not_exists) {
$this->plainTextContent = filter_xss($this->drupalGetContent(), array());
}
if (!$message) {
$message = !$not_exists ? t('"@text" found', array('@text' => $text)) : t('"@text" not found', array('@text' => $text));
$message = !$not_exists ? String::format('"@text" found', array('@text' => $text)) : String::format('"@text" not found', array('@text' => $text));
}
return $this->assert($not_exists == (strpos($this->plainTextContent, $text) === FALSE), $message, $group);
}
......@@ -2883,7 +2883,7 @@ protected function assertUniqueTextHelper($text, $message = '', $group, $be_uniq
*/
protected function assertPattern($pattern, $message = '', $group = 'Other') {
if (!$message) {
$message = t('Pattern "@pattern" found', array('@pattern' => $pattern));
$message = String::format('Pattern "@pattern" found', array('@pattern' => $pattern));
}
return $this->assert((bool) preg_match($pattern, $this->drupalGetContent()), $message, $group);
}
......@@ -2908,7 +2908,7 @@ protected function assertPattern($pattern, $message = '', $group = 'Other') {
*/
protected function assertNoPattern($pattern, $message = '', $group = 'Other') {
if (!$message) {
$message = t('Pattern "@pattern" not found', array('@pattern' => $pattern));
$message = String::format('Pattern "@pattern" not found', array('@pattern' => $pattern));
}
return $this->assert(!preg_match($pattern, $this->drupalGetContent()), $message, $group);
}
......@@ -2934,7 +2934,7 @@ protected function assertNoPattern($pattern, $message = '', $group = 'Other') {
protected function assertTitle($title, $message = '', $group = 'Other') {
$actual = (string) current($this->xpath('//title'));
if (!$message) {
$message = t('Page title @actual is equal to @expected.', array(
$message = String::format('Page title @actual is equal to @expected.', array(
'@actual' => var_export($actual, TRUE),
'@expected' => var_export($title, TRUE),
));
......@@ -2963,7 +2963,7 @@ protected function assertTitle($title, $message = '', $group = 'Other') {
protected function assertNoTitle($title, $message = '', $group = 'Other') {
$actual = (string) current($this->xpath('//title'));
if (!$message) {
$message = t('Page title @actual is not equal to @unexpected.', array(
$message = String::format('Page title @actual is not equal to @unexpected.', array(
'@actual' => var_export($actual, TRUE),
'@unexpected' => var_export($title, TRUE),
));
......@@ -3147,12 +3147,12 @@ protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '', $g
protected function assertFieldByName($name, $value = NULL, $message = NULL, $group = 'Browser') {
if (!isset($message)) {
if (!isset($value)) {
$message = t('Found field with name @name', array(
$message = String::format('Found field with name @name', array(
'@name' => var_export($name, TRUE),
));
}
else {
$message = t('Found field with name @name and value @value', array(
$message = String::format('Found field with name @name and value @value', array(
'@name' => var_export($name, TRUE),
'@value' => var_export($value, TRUE),
));
......@@ -3182,7 +3182,7 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL, $gro
* TRUE on pass, FALSE on fail.
*/
protected function assertNoFieldByName($name, $value = '', $message = '', $group = 'Browser') {
return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), $group);
return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : String::format('Did not find field by name @name', array('@name' => $name)), $group);
}
/**
......@@ -3206,7 +3206,7 @@ protected function assertNoFieldByName($name, $value = '', $message = '', $group
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldById($id, $value = '', $message = '', $group = 'Browser') {
return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), $group);
return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : String::format('Found field by id @id', array('@id' => $id)), $group);
}
/**
......@@ -3230,7 +3230,7 @@ protected function assertFieldById($id, $value = '', $message = '', $group = 'Br
* TRUE on pass, FALSE on fail.
*/
protected function assertNoFieldById($id, $value = '', $message = '', $group = 'Browser') {
return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), $group);
return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : String::format('Did not find field by id @id', array('@id' => $id)), $group);
}
/**
......@@ -3253,7 +3253,7 @@ protected function assertNoFieldById($id, $value = '', $message = '', $group = '
*/
protected function assertFieldChecked($id, $message = '', $group = 'Browser') {
$elements = $this->xpath('//input[@id=:id]', array(':id' => $id));
return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is checked.', array('@id' => $id)), $group);
return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : String::format('Checkbox field @id is checked.', array('@id' => $id)), $group);
}
/**
......@@ -3276,7 +3276,7 @@ protected function assertFieldChecked($id, $message = '', $group = 'Browser') {
*/
protected function assertNoFieldChecked($id, $message = '', $group = 'Browser') {
$elements = $this->xpath('//input[@id=:id]', array(':id' => $id));
return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is not checked.', array('@id' => $id)), $group);
return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : String::format('Checkbox field @id is not checked.', array('@id' => $id)), $group);
}
/**
......@@ -3301,7 +3301,7 @@ protected function assertNoFieldChecked($id, $message = '', $group = 'Browser')
*/
protected function assertOption($id, $option, $message = '', $group = 'Browser') {
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($options[0]), $message ? $message : t('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group);
return $this->assertTrue(isset($options[0]), $message ? $message : String::format('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group);
}
/**
......@@ -3327,7 +3327,7 @@ protected function assertOption($id, $option, $message = '', $group = 'Browser')
protected function assertNoOption($id, $option, $message = '', $group = 'Browser') {
$selects = $this->xpath('//select[@id=:id]', array(':id' => $id));
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), $group);
return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : String::format('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), $group);
}
/**
......@@ -3354,7 +3354,7 @@ protected function assertNoOption($id, $option, $message = '', $group = 'Browser
*/
protected function assertOptionSelected($id, $option, $message = '', $group = 'Browser') {
$elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), $group);
return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : String::format('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), $group);
}
/**
......@@ -3379,7 +3379,7 @@ protected function assertOptionSelected($id, $option, $message = '', $group = 'B
*/
protected function assertNoOptionSelected($id, $option, $message = '', $group = 'Browser') {
$elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is not selected.', array('@option' => $option, '@id' => $id)), $group);
return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message ? $message : String::format('Option @option for field @id is not selected.', array('@option' => $option, '@id' => $id)), $group);
}
/**
......@@ -3454,7 +3454,7 @@ protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to
foreach ($this->xpath('//*[@id]') as $element) {
$id = (string) $element['id'];
if (isset($seen_ids[$id]) && !in_array($id, $ids_to_skip)) {
$this->fail(t('The HTML ID %id is unique.', array('%id' => $id)), $group);
$this->fail(String::format('The HTML ID %id is unique.', array('%id' => $id)), $group);
$status = FALSE;
}
$seen_ids[$id] = TRUE;
......@@ -3500,7 +3500,7 @@ protected function constructFieldXpath($attribute, $value) {
protected function assertResponse($code, $message = '', $group = 'Browser') {
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
return $this->assertTrue($match, $message ? $message : String::format('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
}
/**
......@@ -3525,7 +3525,7 @@ protected function assertResponse($code, $message = '', $group = 'Browser') {
protected function assertNoResponse($code, $message = '', $group = 'Browser') {
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertFalse($match, $message ? $message : t('HTTP response not expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
return $this->assertFalse($match, $message ? $message : String::format('HTTP response not expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
}
/**
......@@ -3639,7 +3639,7 @@ protected function verboseEmail($count = 1) {
$mails = $this->drupalGetMails();
for ($i = count($mails) -1; $i >= count($mails) - $count && $i >= 0; $i--) {
$mail = $mails[$i];
$this->verbose(t('Email:') . '<pre>' . print_r($mail, TRUE) . '</pre>');
$this->verbose('Email:<pre>' . print_r($mail, TRUE) . '</pre>');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment