diff --git a/core/modules/action/src/Tests/BulkFormTest.php b/core/modules/action/src/Tests/BulkFormTest.php
index 944ed47..88892c4 100644
--- a/core/modules/action/src/Tests/BulkFormTest.php
+++ b/core/modules/action/src/Tests/BulkFormTest.php
@@ -77,7 +77,7 @@ public function testBulkForm() {
foreach ($nodes as $node) {
$changed_node = $node_storage->load($node->id());
- $this->assertTrue($changed_node->isSticky(), "Node {$node->id()} got marked as sticky.");
+ $this->assertTrue($changed_node->isSticky(), format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
}
$this->assertText('Make content sticky was applied to 10 items.');
diff --git a/core/modules/aggregator/src/Tests/AggregatorAdminTest.php b/core/modules/aggregator/src/Tests/AggregatorAdminTest.php
index 0a2404f..edc594b 100644
--- a/core/modules/aggregator/src/Tests/AggregatorAdminTest.php
+++ b/core/modules/aggregator/src/Tests/AggregatorAdminTest.php
@@ -40,7 +40,7 @@ public function testSettingsPage() {
$this->assertText(t('The configuration options have been saved.'));
foreach ($edit as $name => $value) {
- $this->assertFieldByName($name, $value, '"' . $name . '" has correct default value.');
+ $this->assertFieldByName($name, $value, format_string('"@name" has correct default value.', array('@name' => $name)));
}
// Check for our test processor settings form.
diff --git a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
index 77e4411..63a7e97 100644
--- a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
+++ b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
@@ -7,6 +7,8 @@
namespace Drupal\aggregator\Tests;
+use Drupal\Component\Utility\SafeMarkup;
+
/**
* Tests display of aggregator items on the page.
*
@@ -64,7 +66,7 @@ public function testBlockLinks() {
// Find the expected read_more link.
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
- $this->assert(isset($links[0]), "Link to href $href found.");
+ $this->assert(isset($links[0]), format_string('Link to href %href found.', array('%href' => $href)));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
@@ -116,7 +118,7 @@ public function testFeedPage() {
// Find the expected read_more link on the sources page.
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
- $this->assertTrue(isset($links[0]), "Link to href $href found.");
+ $this->assertTrue(isset($links[0]), SafeMarkup::format('Link to href %href found.', array('%href' => $href)));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
diff --git a/core/modules/aggregator/src/Tests/FeedParserTest.php b/core/modules/aggregator/src/Tests/FeedParserTest.php
index 1e4fbd4..f507302 100644
--- a/core/modules/aggregator/src/Tests/FeedParserTest.php
+++ b/core/modules/aggregator/src/Tests/FeedParserTest.php
@@ -34,7 +34,7 @@ public function testRSS091Sample() {
$feed = $this->createFeed($this->getRSS091Sample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
- $this->assertResponse(200, "Feed {$feed->label()} exists.");
+ $this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
$this->assertText('First example feed item title');
$this->assertLinkByHref('http://example.com/example-turns-one');
$this->assertText('First example feed item description.');
@@ -57,7 +57,7 @@ public function testAtomSample() {
$feed = $this->createFeed($this->getAtomSample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
- $this->assertResponse(200, "Feed {$feed->label()} exists.");
+ $this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
$this->assertText('Atom-Powered Robots Run Amok');
$this->assertLinkByHref('http://example.org/2003/12/13/atom03');
$this->assertText('Some text.');
@@ -80,7 +80,7 @@ public function testHtmlEntitiesSample() {
$feed = $this->createFeed($this->getHtmlEntitiesSample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
- $this->assertResponse(200, "Feed {$feed->label()} exists.");
+ $this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
$this->assertRaw("Quote" Amp&");
}
diff --git a/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php b/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
index f1ecde3..2a7c9f3 100644
--- a/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
+++ b/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
@@ -40,7 +40,7 @@ public function testUpdateFeedItem() {
$this->assertResponse(200);
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
- $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title[0][value]'])), "The feed {$edit['title[0][value]']} has been added."));
+ $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title[0][value]'])), format_string('The feed @name has been added.', array('@name' => $edit['title[0][value]'])));
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url[0][value]']))->fetchField();
$feed = Feed::load($fid);
@@ -62,7 +62,7 @@ public function testUpdateFeedItem() {
$feed->refreshItems();
$after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
- $this->assertTrue($before === $after, "Publish timestamp of feed item was not updated ($before === $after)");
+ $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', array('@before' => $before, '@after' => $after)));
// Make sure updating items works even after uninstalling a module
// that provides the selected plugins.
diff --git a/core/modules/aggregator/src/Tests/UpdateFeedTest.php b/core/modules/aggregator/src/Tests/UpdateFeedTest.php
index 019d938..c660756 100644
--- a/core/modules/aggregator/src/Tests/UpdateFeedTest.php
+++ b/core/modules/aggregator/src/Tests/UpdateFeedTest.php
@@ -29,7 +29,7 @@ public function testUpdateFeed() {
$edit[$same_field] = $feed->{$same_field}->value;
}
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/configure', $edit, t('Save'));
- $this->assertRaw(t('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])), "The feed {$edit['title[0][value]']} has been updated.");
+ $this->assertRaw(t('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])), format_string('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])));
// Check feed data.
$this->assertUrl($feed->url('canonical', ['absolute' => TRUE]));
diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php
index 27dded2..261c3ae 100644
--- a/core/modules/block/src/Tests/BlockTest.php
+++ b/core/modules/block/src/Tests/BlockTest.php
@@ -290,7 +290,7 @@ function moveBlockToRegion(array $block, $region) {
$this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
- $this->assertText(t('The block settings have been updated.'), "Block successfully moved to $region region.");
+ $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array( '%region_name' => $region)));
// Confirm that the block is being displayed.
$this->drupalGet('');
diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/src/Tests/Views/DisplayBlockTest.php
index a506a21..3adefe0 100644
--- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php
+++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php
@@ -360,8 +360,8 @@ public function testBlockContextualLinks() {
$id = 'block:block=' . $block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
$cached_id = 'block:block=' . $cached_block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
- $this->assertRaw('
$id)) . '>
', "Contextual link placeholder with id $id exists.");
- $this->assertRaw(' $cached_id)) . '>
', "Contextual link placeholder with id $cached_id exists.");
+ $this->assertRaw(' $id)) . '>
', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id)));
+ $this->assertRaw(' $cached_id)) . '>
', format_string('Contextual link placeholder with id @id exists.', array('@id' => $cached_id)));
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
diff --git a/core/modules/block_content/src/Tests/BlockContentRevisionsTest.php b/core/modules/block_content/src/Tests/BlockContentRevisionsTest.php
index 174e2b6..15e7a10 100644
--- a/core/modules/block_content/src/Tests/BlockContentRevisionsTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentRevisionsTest.php
@@ -69,7 +69,9 @@ public function testRevisions() {
// Confirm the correct revision text appears.
$loaded = entity_revision_load('block_content', $revision_id);
// Verify revision log is the same.
- $this->assertEqual($loaded->getRevisionLog(), $logs[$delta], "Correct log message found for revision {$loaded->getRevisionId()}");
+ $this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
+ '@revision' => $loaded->getRevisionId(),
+ )));
}
// Confirm that this is the default revision.
diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php
index e7de051..54cad1d 100644
--- a/core/modules/book/src/Tests/BookTest.php
+++ b/core/modules/book/src/Tests/BookTest.php
@@ -260,10 +260,10 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F
// Check outline structure.
if ($nodes !== NULL) {
- $this->assertPattern($this->generateOutlinePattern($nodes), "Node $number outline confirmed.");
+ $this->assertPattern($this->generateOutlinePattern($nodes), format_string('Node @number outline confirmed.', array('@number' => $number)));
}
else {
- $this->pass("Node $number does not have outline.");
+ $this->pass(format_string('Node %number does not have outline.', array('%number' => $number)));
}
// Check previous, up, and next links.
@@ -441,7 +441,7 @@ function testBookNavigationBlock() {
$nodes = $this->createBook();
$this->drupalGet('');
$this->assertText($block->label(), 'Book navigation block is displayed.');
- $this->assertText($this->book->label(), "Link to book root ({$nodes[0]->label()}) is displayed.");
+ $this->assertText($this->book->label(), format_string('Link to book root (@title) is displayed.', array('@title' => $nodes[0]->label())));
$this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.');
}
diff --git a/core/modules/comment/src/Tests/CommentBlockTest.php b/core/modules/comment/src/Tests/CommentBlockTest.php
index c44589b..e6eee69 100644
--- a/core/modules/comment/src/Tests/CommentBlockTest.php
+++ b/core/modules/comment/src/Tests/CommentBlockTest.php
@@ -73,13 +73,11 @@ function testRecentCommentBlock() {
// Test the only the 10 latest comments are shown and in the proper order.
$this->assertNoText($comments[10]->getSubject(), 'Comment 11 not found in block.');
for ($i = 0; $i < 10; $i++) {
- $number = 10 - $i;
- $this->assertText($comments[$i]->getSubject(), "Comment $number found in block.");
+ $this->assertText($comments[$i]->getSubject(), SafeMarkup::format('Comment @number found in block.', array('@number' => 10 - $i)));
if ($i > 1) {
$previous_position = $position;
$position = strpos($this->getRawContent(), $comments[$i]->getSubject());
- $last_number = $number + 1;
- $this->assertTrue($position > $previous_position, "Comment $number appears after comment $last_number");
+ $this->assertTrue($position > $previous_position, SafeMarkup::format('Comment @a appears after comment @b', array('@a' => 10 - $i, '@b' => 11 - $i)));
}
$position = strpos($this->getRawContent(), $comments[$i]->getSubject());
}
diff --git a/core/modules/comment/src/Tests/CommentFieldAccessTest.php b/core/modules/comment/src/Tests/CommentFieldAccessTest.php
index d910cc1..ce89d4a 100644
--- a/core/modules/comment/src/Tests/CommentFieldAccessTest.php
+++ b/core/modules/comment/src/Tests/CommentFieldAccessTest.php
@@ -222,11 +222,12 @@ public function testAccessToAdministrativeFields() {
// Check access to normal field.
foreach ($permutations as $set) {
- $username = $set['user']->getUsername();
- $state = $may_update ? 'can' : 'cannot';
- $comment_subject = $set['comment']->getSubject();
$may_update = $set['comment']->access('update', $set['user']) && $set['comment']->subject->access('edit', $set['user']);
- $this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), "User $username $state update field subject on comment $comment_subject");
+ $this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), SafeMarkup::format('User @user @state update field subject on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@state' => $may_update ? 'can' : 'cannot',
+ '@comment' => $set['comment']->getSubject(),
+ ]));
}
// Check read-only fields.
@@ -244,10 +245,18 @@ public function testAccessToAdministrativeFields() {
$view_access = TRUE;
$state = 'can';
}
- $username = $set['user']->getUsername();
- $comment_subject = $set['comment']->getSubject();
- $this->assertEqual($may_view, $view_access, "User $username $state view field $field on comment $comment_subject");
- $this->assertFalse($may_update, "User $username $state update field $field on comment $comment_subject");
+ $this->assertEqual($may_view, $view_access, SafeMarkup::format('User @user @state view field @field on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@comment' => $set['comment']->getSubject(),
+ '@field' => $field,
+ '@state' => $state,
+ ]));
+ $this->assertFalse($may_update, SafeMarkup::format('User @user @state update field @field on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@state' => $may_update ? 'can' : 'cannot',
+ '@comment' => $set['comment']->getSubject(),
+ '@field' => $field,
+ ]));
}
}
@@ -257,11 +266,17 @@ public function testAccessToAdministrativeFields() {
foreach ($permutations as $set) {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
- $username = $set['user']->getUsername();
- $state = $may_update ? 'can' : 'cannot';
- $comment_subject = $set['comment']->getSubject();
- $this->assertEqual($may_view, TRUE, "User $username $state view field $field on comment $comment_subject");
- $this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), "User $username $state update field $field on comment $comment_subject");
+ $this->assertEqual($may_view, TRUE, SafeMarkup::format('User @user can view field @field on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@comment' => $set['comment']->getSubject(),
+ '@field' => $field,
+ ]));
+ $this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), SafeMarkup::format('User @user @state update field @field on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@state' => $may_update ? 'can' : 'cannot',
+ '@comment' => $set['comment']->getSubject(),
+ '@field' => $field,
+ ]));
}
}
@@ -270,9 +285,6 @@ public function testAccessToAdministrativeFields() {
// Check view operation.
foreach ($permutations as $set) {
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
- $username = $set['user']->getUsername();
- $state = $may_update ? 'can' : 'cannot';
- $comment_subject = $set['comment']->getSubject();
// To edit the 'mail' or 'name' field, either the user has the
// "administer comments" permissions or the user is anonymous and
// adding a new comment using a field that allows contact details.
@@ -281,7 +293,12 @@ public function testAccessToAdministrativeFields() {
$set['comment']->isNew() &&
$set['user']->hasPermission('post comments') &&
$set['comment']->getFieldName() == 'comment_other'
- ), "User $username $state update field $field on comment $comment_subject.");
+ ), SafeMarkup::format('User @user @state update field @field on comment @comment', [
+ '@user' => $set['user']->getUsername(),
+ '@state' => $may_update ? 'can' : 'cannot',
+ '@comment' => $set['comment']->getSubject(),
+ '@field' => $field,
+ ]));
}
}
foreach ($permutations as $set) {
diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php
index 6e04b92..408b782 100644
--- a/core/modules/comment/src/Tests/CommentFieldsTest.php
+++ b/core/modules/comment/src/Tests/CommentFieldsTest.php
@@ -56,7 +56,7 @@ function testCommentDefaultFields() {
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field_storage, 'The comment_body field exists');
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
- $this->assertTrue(isset($field), "The comment_body field is present for comments on type $type_name");
+ $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
// Test adding a field that defaults to CommentItemInterface::CLOSED.
$this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
diff --git a/core/modules/comment/src/Tests/CommentLanguageTest.php b/core/modules/comment/src/Tests/CommentLanguageTest.php
index 90e05f5..8db195d 100644
--- a/core/modules/comment/src/Tests/CommentLanguageTest.php
+++ b/core/modules/comment/src/Tests/CommentLanguageTest.php
@@ -122,7 +122,8 @@ function testCommentLanguage() {
->range(0, 1)
->execute();
$comment = Comment::load(reset($cids));
- $this->assertEqual($comment->langcode->value, $langcode, "The comment posted with content language $langcode and belonging to the node with language $node_langcode has language {$comment->langcode->value}");
+ $args = array('%node_language' => $node_langcode, '%comment_language' => $comment->langcode->value, '%langcode' => $langcode);
+ $this->assertEqual($comment->langcode->value, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
$this->assertEqual($comment->comment_body->value, $comment_values[$node_langcode][$langcode], 'Comment body correctly stored.');
}
}
diff --git a/core/modules/comment/src/Tests/CommentNonNodeTest.php b/core/modules/comment/src/Tests/CommentNonNodeTest.php
index c246231..aa06942 100644
--- a/core/modules/comment/src/Tests/CommentNonNodeTest.php
+++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php
@@ -227,10 +227,10 @@ function performCommentOperation($comment, $operation, $approval = FALSE) {
if ($operation == 'delete') {
$this->drupalPostForm(NULL, array(), t('Delete comments'));
- $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), 'Operation "' . $operation . '" was performed on comment.');
+ $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
}
else {
- $this->assertText(t('The update has been performed.'), 'Operation "' . $operation . '" was performed on comment.');
+ $this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
}
}
diff --git a/core/modules/comment/src/Tests/CommentPagerTest.php b/core/modules/comment/src/Tests/CommentPagerTest.php
index 833cbb1..9061f64 100644
--- a/core/modules/comment/src/Tests/CommentPagerTest.php
+++ b/core/modules/comment/src/Tests/CommentPagerTest.php
@@ -8,6 +8,7 @@
namespace Drupal\comment\Tests;
use Drupal\comment\CommentManagerInterface;
+use Drupal\Component\Utility\SafeMarkup;
use Drupal\node\Entity\Node;
/**
@@ -190,7 +191,7 @@ function assertCommentOrder(array $comments, array $expected_order) {
foreach ($comment_anchors as $anchor) {
$result_order[] = substr($anchor['id'], 8);
}
- return $this->assertEqual($expected_cids, $result_order, 'Comment order: expected ' . implode(',', $expected_cids) . ', returned ' . implode(',', $result_order) . '.');
+ return $this->assertEqual($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', array('@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order))));
}
/**
@@ -381,10 +382,10 @@ protected function clickLinkWithXPath($xpath, $arguments = array(), $index = 0)
$urls = $this->xpath($xpath, $arguments);
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
- $this->pass("Clicked link $xpath ($url_target) from $url_before", 'Browser');
+ $this->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', array('%label' => $xpath, '@url_target' => $url_target, '@url_before' => $url_before)), 'Browser');
return $this->drupalGet($url_target);
}
- $this->fail("Link $xpath does not exist on $url_before", 'Browser');
+ $this->fail(SafeMarkup::format('Link %label does not exist on @url_before', array('%label' => $xpath, '@url_before' => $url_before)), 'Browser');
return FALSE;
}
diff --git a/core/modules/comment/src/Tests/CommentThreadingTest.php b/core/modules/comment/src/Tests/CommentThreadingTest.php
index 8c5bde5..14db3cc 100644
--- a/core/modules/comment/src/Tests/CommentThreadingTest.php
+++ b/core/modules/comment/src/Tests/CommentThreadingTest.php
@@ -142,7 +142,13 @@ protected function assertParentLink($cid, $pid) {
//
$pattern = "//a[@id='comment-$cid']/following-sibling::article//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]";
- $this->assertFieldByXpath($pattern, NULL, "Comment $cid has a link to parent $pid.");
+ $this->assertFieldByXpath($pattern, NULL, format_string(
+ 'Comment %cid has a link to parent %pid.',
+ array(
+ '%cid' => $cid,
+ '%pid' => $pid,
+ )
+ ));
}
/**
@@ -159,7 +165,12 @@ protected function assertNoParentLink($cid) {
//
$pattern = "//a[@id='comment-$cid']/following-sibling::article//p[contains(@class, 'parent')]";
- $this->assertNoFieldByXpath($pattern, NULL, "Comment $cid does not have a link to a parent.");
+ $this->assertNoFieldByXpath($pattern, NULL, format_string(
+ 'Comment %cid does not have a link to a parent.',
+ array(
+ '%cid' => $cid,
+ )
+ ));
}
}
diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
index be86c44..60f1c28 100644
--- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
+++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
@@ -117,15 +117,16 @@ function testCommentTokenReplacement() {
foreach ($tests as $input => $expected) {
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
- $this->assertEqual($output, $expected, "Comment token $input replaced.");
+ $this->assertEqual($output, $expected, new FormattableMarkup('Comment token %token replaced.', ['%token' => $input]));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
+
// Test anonymous comment author.
$author_name = 'This is a random & " > string';
$comment->setOwnerId(0)->setAuthorName($author_name);
$input = '[comment:author]';
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
- $this->assertEqual($output, Html::escape($author_name), "Comment author token %$input replaced.");
+ $this->assertEqual($output, Html::escape($author_name), format_string('Comment author token %token replaced.', array('%token' => $input)));
// Load node so comment_count gets computed.
$node = Node::load($node->id());
@@ -137,7 +138,7 @@ function testCommentTokenReplacement() {
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId()));
- $this->assertEqual($output, $expected, "Node comment token $input replaced.");
+ $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
}
}
diff --git a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php
index 27ce903..89b03b3 100644
--- a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php
+++ b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php
@@ -135,7 +135,11 @@ public function testBlockDisplay() {
$this->assertIdenticalResultset($view, $expected_result, $map);
// Check the number of results given by the display is the expected.
- $this->assertEqual(sizeof($view->result), $this->blockDisplayResults, 'There are exactly ' . count($view->result) . ' comments. Expected ' . $this->blockDisplayResults . '.');
+ $this->assertEqual(sizeof($view->result), $this->blockDisplayResults,
+ format_string('There are exactly @results comments. Expected @expected',
+ array('@results' => count($view->result), '@expected' => $this->blockDisplayResults)
+ )
+ );
}
}
diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php
index dc8107f..3d61c9e 100644
--- a/core/modules/config/src/Tests/ConfigCRUDTest.php
+++ b/core/modules/config/src/Tests/ConfigCRUDTest.php
@@ -197,7 +197,9 @@ function testNameValidation() {
unset($test_characters[$i]);
}
}
- $this->assertTrue(empty($test_characters), 'Expected ConfigNameException was thrown for all invalid name characters: ' . implode(' ', $characters));
+ $this->assertTrue(empty($test_characters), format_string('Expected ConfigNameException was thrown for all invalid name characters: @characters', array(
+ '@characters' => implode(' ', $characters),
+ )));
// Verify that a valid config object name can be saved.
$name = 'namespace.object';
@@ -295,7 +297,9 @@ public function testDataTypes() {
$this->fail('No Exception thrown upon saving invalid data type.');
}
catch (UnsupportedDataTypeConfigException $e) {
- $this->pass("{get_class($e)} thrown upon saving invalid data type.");
+ $this->pass(SafeMarkup::format('%class thrown upon saving invalid data type.', array(
+ '%class' => get_class($e),
+ )));
}
// Test that setting an unsupported type for a config object with no schema
@@ -310,7 +314,9 @@ public function testDataTypes() {
$this->fail('No Exception thrown upon saving invalid data type.');
}
catch (UnsupportedDataTypeConfigException $e) {
- $this->pass("{get_class($e)} thrown upon saving invalid data type.");
+ $this->pass(SafeMarkup::format('%class thrown upon saving invalid data type.', array(
+ '%class' => get_class($e),
+ )));
}
}
diff --git a/core/modules/config/src/Tests/ConfigDiffTest.php b/core/modules/config/src/Tests/ConfigDiffTest.php
index be08362..1f32b27 100644
--- a/core/modules/config/src/Tests/ConfigDiffTest.php
+++ b/core/modules/config/src/Tests/ConfigDiffTest.php
@@ -50,8 +50,8 @@ function testDiff() {
$diff = \Drupal::service('config.manager')->diff($active, $sync, $config_name);
$edits = $diff->getEdits();
$this->assertEqual($edits[0]->type, 'change', 'The first item in the diff is a change.');
- $this->assertEqual($edits[0]->orig[0], $change_key . ': ' . $original_data[$change_key], "The active value for key '$change_key' is '$original_data[$change_key]'.");
- $this->assertEqual($edits[0]->closing[0], $change_key . ': ' . $change_data, "The sync value for key '$change_key' is '$change_data'.");
+ $this->assertEqual($edits[0]->orig[0], $change_key . ': ' . $original_data[$change_key], format_string("The active value for key '%change_key' is '%original_data'.", array('%change_key' => $change_key, '%original_data' => $original_data[$change_key])));
+ $this->assertEqual($edits[0]->closing[0], $change_key . ': ' . $change_data, format_string("The sync value for key '%change_key' is '%change_data'.", array('%change_key' => $change_key, '%change_data' => $change_data)));
// Reset data back to original, and remove a key
$sync_data = $original_data;
@@ -63,8 +63,8 @@ function testDiff() {
$edits = $diff->getEdits();
$this->assertEqual($edits[0]->type, 'copy', 'The first item in the diff is a copy.');
$this->assertEqual($edits[1]->type, 'delete', 'The second item in the diff is a delete.');
- $this->assertEqual($edits[1]->orig[0], $remove_key . ': ' . $original_data[$remove_key], "The active value for key '$remove_key' is '$original_data[$remove_key]'.");
- $this->assertFalse($edits[1]->closing, "The key '$remove_key' does not exist in sync.");
+ $this->assertEqual($edits[1]->orig[0], $remove_key . ': ' . $original_data[$remove_key], format_string("The active value for key '%remove_key' is '%original_data'.", array('%remove_key' => $remove_key, '%original_data' => $original_data[$remove_key])));
+ $this->assertFalse($edits[1]->closing, format_string("The key '%remove_key' does not exist in sync.", array('%remove_key' => $remove_key)));
// Reset data back to original and add a key
$sync_data = $original_data;
@@ -76,8 +76,8 @@ function testDiff() {
$edits = $diff->getEdits();
$this->assertEqual($edits[0]->type, 'copy', 'The first item in the diff is a copy.');
$this->assertEqual($edits[1]->type, 'add', 'The second item in the diff is an add.');
- $this->assertFalse($edits[1]->orig, "The key '$add_key' does not exist in active.");
- $this->assertEqual($edits[1]->closing[0], $add_key . ': ' . $add_data, "The sync value for key '$add_key' is '$add_data'.");
+ $this->assertFalse($edits[1]->orig, format_string("The key '%add_key' does not exist in active.", array('%add_key' => $add_key)));
+ $this->assertEqual($edits[1]->closing[0], $add_key . ': ' . $add_data, format_string("The sync value for key '%add_key' is '%add_data'.", array('%add_key' => $add_key, '%add_data' => $add_data)));
// Test diffing a renamed config entity.
$test_entity_id = $this->randomMachineName();
diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php
index 7734c25..13ab721 100644
--- a/core/modules/config/src/Tests/ConfigEntityTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityTest.php
@@ -151,7 +151,9 @@ function testCRUD() {
));
try {
$id_length_config_test->save();
- $this->pass('config_test entity with ID length ' . strlen($id_length_config_test->id()) . ' was saved.');
+ $this->pass(SafeMarkup::format("config_test entity with ID length @length was saved.", array(
+ '@length' => strlen($id_length_config_test->id()))
+ ));
}
catch (ConfigEntityIdLengthException $e) {
$this->fail($e->getMessage());
@@ -163,7 +165,9 @@ function testCRUD() {
));
try {
$id_length_config_test->save();
- $this->pass('config_test entity with ID length ' . strlen($id_length_config_test->id()) . ' was saved.');
+ $this->pass(SafeMarkup::format("config_test entity with ID length @length was saved.", array(
+ '@length' => strlen($id_length_config_test->id()),
+ )));
}
catch (ConfigEntityIdLengthException $e) {
$this->fail($e->getMessage());
@@ -175,10 +179,16 @@ function testCRUD() {
));
try {
$status = $id_length_config_test->save();
- $this->fail('config_test entity with ID length ' . strlen($id_length_config_test->id()) . ' exceeding the maximum allowed length of ' . static::MAX_ID_LENGTH . ' saved successfully');
+ $this->fail(SafeMarkup::format("config_test entity with ID length @length exceeding the maximum allowed length of @max saved successfully", array(
+ '@length' => strlen($id_length_config_test->id()),
+ '@max' => static::MAX_ID_LENGTH,
+ )));
}
catch (ConfigEntityIdLengthException $e) {
- $this->pass('config_test entity with ID length ' . strlen($id_length_config_test->id()) . ' exceeding the maximum allowed length of @' . static::MAX_ID_LENGTH . ' failed to save');
+ $this->pass(SafeMarkup::format("config_test entity with ID length @length exceeding the maximum allowed length of @max failed to save", array(
+ '@length' => strlen($id_length_config_test->id()),
+ '@max' => static::MAX_ID_LENGTH,
+ )));
}
// Ensure that creating an entity with the same id as an existing one is not
diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php
index 1f865e5..8d511ea 100644
--- a/core/modules/config/src/Tests/ConfigImporterTest.php
+++ b/core/modules/config/src/Tests/ConfigImporterTest.php
@@ -299,7 +299,9 @@ function testSecondaryWriteSecondaryFirst() {
$this->assertEqual($logs[0], Html::escape("Unexpected error during import with operation create for $name_primary: 'config_test' entity with ID 'secondary' already exists."));
}
-
+ /**
+ * Tests that secondary updates for deleted files work as expected.
+ */
function testSecondaryUpdateDeletedDeleterFirst() {
$name_deleter = 'config_test.dynamic.deleter';
$name_deletee = 'config_test.dynamic.deletee';
diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php
index 129fc0a..56d80fe 100644
--- a/core/modules/image/src/Tests/ImageAdminStylesTest.php
+++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php
@@ -59,7 +59,7 @@ function testNumericStyleName() {
$this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_label)));
$options = image_style_options();
- $this->assertTrue(array_key_exists($style_name, $options), "Array key $style_name exists.");
+ $this->assertTrue(array_key_exists($style_name, $options), format_string('Array key %key exists.', array('%key' => $style_name)));
}
/**
@@ -151,13 +151,18 @@ function testStyle() {
$uuids[$effect->getPluginId()] = $uuid;
$effect_configuration = $effect->getConfiguration();
foreach ($effect_edits[$effect->getPluginId()] as $field => $value) {
- $this->assertEqual($value, $effect_configuration['data'][$field], "The $field field in the {$effect->getPluginId()} effect has the correct value of $value.");
+ $this->assertEqual($value, $effect_configuration['data'][$field], SafeMarkup::format('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect->getPluginId(), '%value' => $value)));
}
}
// Assert that every effect was saved.
foreach (array_keys($effect_edits) as $effect_name) {
- $this->assertTrue(isset($uuids[$effect_name]), "A $effect_name effect was saved with ID $uuids[$effect_name]");
+ $this->assertTrue(isset($uuids[$effect_name]), format_string(
+ 'A %effect_name effect was saved with ID %uuid',
+ array(
+ '%effect_name' => $effect_name,
+ '%uuid' => $uuids[$effect_name],
+ )));
}
// Image style overview form (ordering and renaming).
@@ -191,7 +196,7 @@ function testStyle() {
// Create an image to make sure it gets flushed after saving.
$image_path = $this->createSampleImage($style);
- $this->assertEqual($this->getImageCount($style), 1, "Image style {$style->label()} image {$image_path} successfully generated.");
+ $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
$this->drupalPostForm($style_path, $edit, t('Update style'));
@@ -201,12 +206,12 @@ function testStyle() {
// Check that the URL was updated.
$this->drupalGet($style_path);
$this->assertTitle(t('Edit style @name | Drupal', array('@name' => $style_label)));
- $this->assertResponse(200, "Image style {$style->id()} renamed to $style_name");
+ $this->assertResponse(200, format_string('Image style %original renamed to %new', array('%original' => $style->id(), '%new' => $style_name)));
// Check that the image was flushed after updating the style.
// This is especially important when renaming the style. Make sure that
// the old image directory has been deleted.
- $this->assertEqual($this->getImageCount($style), 0, "Image style {$style->label()} was flushed after renaming the style and updating the order of effects.");
+ $this->assertEqual($this->getImageCount($style), 0, format_string('Image style %style was flushed after renaming the style and updating the order of effects.', array('%style' => $style->label())));
// Load the style by the new name with the new weights.
$style = ImageStyle::load($style_name);
@@ -227,7 +232,7 @@ function testStyle() {
// Create an image to make sure it gets flushed after deleting an effect.
$image_path = $this->createSampleImage($style);
- $this->assertEqual($this->getImageCount($style), 1, "Image style {$style->label()} image $image_path successfully generated.");
+ $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
// Delete the 'image_crop' effect from the style.
$this->drupalPostForm($style_path . '/effects/' . $uuids['image_crop'] . '/delete', array(), t('Delete'));
@@ -267,8 +272,9 @@ function testStyle() {
// Confirm the style directory has been removed.
$directory = file_default_scheme() . '://styles/' . $style_name;
- $this->assertFalse(is_dir($directory), "Image style{$style->label()} directory removed on {$style->label()} deletion.");
- $this->assertFalse(ImageStyle::load($style_name), "Image style {$style->label()} successfully deleted.");
+ $this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', array('%style' => $style->label())));
+
+ $this->assertFalse(ImageStyle::load($style_name), format_string('Image style %style successfully deleted.', array('%style' => $style->label())));
// Test empty text when there are no image styles.
@@ -368,7 +374,7 @@ function testStyleReplacement() {
'label' => $new_style_label,
);
$this->drupalPostForm($style_path . $style_name, $edit, t('Update style'));
- $this->assertText(t('Changes to the style have been saved.'), "Style $style_name was renamed to $new_style_name.");
+ $this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name)));
$this->drupalGet('node/' . $nid);
// Reload the image style using the new name.
diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
index f30d0fd..ee47e30 100644
--- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
@@ -113,14 +113,20 @@ public function testDefaultImages() {
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field']->id(),
- "Article image field default equals expected file ID of {$default_images['field']->id()}."
+ format_string(
+ 'Article image field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field']->id())
+ )
);
// Confirm the defaults are present on the article field edit form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field']->id(),
- "Article image field field default equals expected file ID of {$default_images['field']->id()}."
+ format_string(
+ 'Article image field field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field']->id())
+ )
);
// Confirm the defaults are present on the page field settings form.
@@ -128,7 +134,10 @@ public function testDefaultImages() {
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field']->id(),
- "Page image field default equals expected file ID of {$default_images['field']->id()}."
+ format_string(
+ 'Page image field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field']->id())
+ )
);
// Confirm the defaults are present on the page field edit form.
$field2_id = $field2->id();
@@ -136,7 +145,10 @@ public function testDefaultImages() {
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field2']->id(),
- "Page image field field default equals expected file ID of {$default_images['field2']->id()}."
+ format_string(
+ 'Page image field field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field2']->id())
+ )
);
// Confirm that the image default is shown for a new article node.
@@ -145,7 +157,10 @@ public function testDefaultImages() {
$this->assertEqual(
$article_built[$field_name][0]['#item']->target_id,
$default_images['field']->id(),
- "A new article node without an image has the expected default image file ID of {$default_images['field']->id()}."
+ format_string(
+ 'A new article node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field']->id())
+ )
);
// Also check that the field renders without warnings when the label is
@@ -161,7 +176,10 @@ public function testDefaultImages() {
$this->assertEqual(
$page_built[$field_name][0]['#item']->target_id,
$default_images['field2']->id(),
- "A new page node without an image has the expected default image file ID of {$default_images['field2']->id()}."
+ format_string(
+ 'A new page node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field2']->id())
+ )
);
// Upload a new default for the field storage.
@@ -175,7 +193,10 @@ public function testDefaultImages() {
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field_new']->id(),
- "Updated image field default equals expected file ID of {$default_images['field_new']->id()}."
+ format_string(
+ 'Updated image field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field_new']->id())
+ )
);
// Reload the nodes and confirm the field field defaults are used.
@@ -185,12 +206,18 @@ public function testDefaultImages() {
$this->assertEqual(
$article_built[$field_name][0]['#item']->target_id,
$default_images['field']->id(),
- "An existing article node without an image has the expected default image file ID of {$default_images['field']->id()}."
+ format_string(
+ 'An existing article node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field']->id())
+ )
);
$this->assertEqual(
$page_built[$field_name][0]['#item']->target_id,
$default_images['field2']->id(),
- "An existing page node without an image has the expected default image file ID of {$default_images['field2']->id()}."
+ format_string(
+ 'An existing page node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field2']->id())
+ )
);
// Upload a new default for the article's field field.
@@ -205,7 +232,10 @@ public function testDefaultImages() {
$this->assertFieldByXpath(
'//input[@name="settings[default_image][uuid][fids]"]',
$default_images['field_new']->id(),
- "Updated article image field field default equals expected file ID of {$default_images['field_new']->id()}."
+ format_string(
+ 'Updated article image field field default equals expected file ID of @fid.',
+ array('@fid' => $default_images['field_new']->id())
+ )
);
// Reload the nodes.
@@ -217,13 +247,19 @@ public function testDefaultImages() {
$this->assertEqual(
$article_built[$field_name][0]['#item']->target_id,
$default_images['field_new']->id(),
- "An existing article node without an image has the expected default image file ID of {$default_images['field_new']->id()}."
+ format_string(
+ 'An existing article node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field_new']->id())
+ )
);
// Confirm the page remains unchanged.
$this->assertEqual(
$page_built[$field_name][0]['#item']->target_id,
$default_images['field2']->id(),
- "An existing page node without an image has the expected default image file ID of {$default_images['field2']->id()}."
+ format_string(
+ 'An existing page node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field2']->id())
+ )
);
// Confirm the default image is shown on the node form.
@@ -253,13 +289,19 @@ public function testDefaultImages() {
$this->assertEqual(
$article_built[$field_name][0]['#item']->target_id,
$default_images['field_new']->id(),
- "An existing article node without an image has the expected default image file ID of {$default_images['field_new']->id()}."
+ format_string(
+ 'An existing article node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field_new']->id())
+ )
);
// Confirm the page remains unchanged.
$this->assertEqual(
$page_built[$field_name][0]['#item']->target_id,
$default_images['field2']->id(),
- "An existing page node without an image has the expected default image file ID of {$default_images['field2']->id()}."
+ format_string(
+ 'An existing page node without an image has the expected default image file ID of @fid.',
+ array('@fid' => $default_images['field2']->id())
+ )
);
$non_image = $this->drupalGetTestFiles('text');
diff --git a/core/modules/image/src/Tests/ImageStyleFlushTest.php b/core/modules/image/src/Tests/ImageStyleFlushTest.php
index 4cc3ce2..0a6a5fa 100644
--- a/core/modules/image/src/Tests/ImageStyleFlushTest.php
+++ b/core/modules/image/src/Tests/ImageStyleFlushTest.php
@@ -87,11 +87,11 @@ function testFlush() {
$image_path = $this->createSampleImage($style, 'public');
// Expecting to find 2 images, one is the sample.png image shown in
// image style preview.
- $this->assertEqual($this->getImageCount($style, 'public'), 2, "Image style {$style->label()} image $image_path successfully generated.");
+ $this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
// Create an image for the 'private' wrapper.
$image_path = $this->createSampleImage($style, 'private');
- $this->assertEqual($this->getImageCount($style, 'private'), 1, "Image style {$style->label()} image $image_path successfully generated.");
+ $this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
// Remove the 'image_scale' effect and updates the style, which in turn
// forces an image style flush.
@@ -106,9 +106,9 @@ function testFlush() {
$this->assertResponse(200);
// Post flush, expected 1 image in the 'public' wrapper (sample.png).
- $this->assertEqual($this->getImageCount($style, 'public'), 1, "Image style {$style->label()} flushed correctly for public wrapper.");
+ $this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'public')));
// Post flush, expected no image in the 'private' wrapper.
- $this->assertEqual($this->getImageCount($style, 'private'), 0, "Image style {$style->label()} flushed correctly for private wrapper.");
+ $this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'private')));
}
}
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 36f61e0..5c9161e 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -109,66 +109,66 @@ protected function doTestReadWrite($entity_type) {
$langcode = 'en';
// Access the name field.
- $this->assertTrue($entity->name instanceof FieldItemListInterface, "$entity_type: Field implements interface");
- $this->assertTrue($entity->name[0] instanceof FieldItemInterface, "$entity_type: Field item implements interface");
+ $this->assertTrue($entity->name instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->name[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', array('%entity_type' => $entity_type)));
- $this->assertEqual($this->entityName, $entity->name->value, "$entity_type: Name value can be read.");
- $this->assertEqual($this->entityName, $entity->name[0]->value, "$entity_type: Name value can be read through list access.");
- $this->assertEqual($entity->name->getValue(), array(0 => array('value' => $this->entityName)), "$entity_type: Plain field value returned.");
+ $this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityName, $entity->name[0]->value, format_string('%entity_type: Name value can be read through list access.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name->getValue(), array(0 => array('value' => $this->entityName)), format_string('%entity_type: Plain field value returned.', array('%entity_type' => $entity_type)));
// Change the name.
$new_name = $this->randomMachineName();
$entity->name->value = $new_name;
- $this->assertEqual($new_name, $entity->name->value, "$entity_type: Name can be updated and read.");
- $this->assertEqual($entity->name->getValue(), array(0 => array('value' => $new_name)), "$entity_type: Plain field value reflects the update.");
+ $this->assertEqual($new_name, $entity->name->value, format_string('%entity_type: Name can be updated and read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name->getValue(), array(0 => array('value' => $new_name)), format_string('%entity_type: Plain field value reflects the update.', array('%entity_type' => $entity_type)));
$new_name = $this->randomMachineName();
$entity->name[0]->value = $new_name;
- $this->assertEqual($new_name, $entity->name->value, "$entity_type: Name can be updated and read through list access.");
+ $this->assertEqual($new_name, $entity->name->value, format_string('%entity_type: Name can be updated and read through list access.', array('%entity_type' => $entity_type)));
// Access the user field.
- $this->assertTrue($entity->user_id instanceof FieldItemListInterface, "$entity_type: Field implements interface");
- $this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, "$entity_type: Field item implements interface");
+ $this->assertTrue($entity->user_id instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', array('%entity_type' => $entity_type)));
- $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, "$entity_type: User id can be read.");
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, "$entity_type: User name can be read.");
+ $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
// Change the assigned user by entity.
$new_user1 = $this->createUser();
$entity->user_id->entity = $new_user1;
- $this->assertEqual($new_user1->id(), $entity->user_id->target_id, "$entity_type: Updated user id can be read.");
- $this->assertEqual($new_user1->getUsername(), $entity->user_id->entity->name->value, "$entity_type: Updated username value can be read.");
+ $this->assertEqual($new_user1->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($new_user1->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', array('%entity_type' => $entity_type)));
// Change the assigned user by id.
$new_user2 = $this->createUser();
$entity->user_id->target_id = $new_user2->id();
- $this->assertEqual($new_user2->id(), $entity->user_id->target_id, "$entity_type: Updated user id can be read.");
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, "$entity_type: Updated username value can be read.");
+ $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', array('%entity_type' => $entity_type)));
// Try unsetting a field property.
$entity->name->value = NULL;
$entity->user_id->target_id = NULL;
- $this->assertNull($entity->name->value, "$entity_type: Name field is not set.");
- $this->assertNull($entity->user_id->target_id, "$entity_type: User ID field is not set.");
- $this->assertNull($entity->user_id->entity, "$entity_type: User entity field is not set.");
+ $this->assertNull($entity->name->value, format_string('%entity_type: Name field is not set.', array('%entity_type' => $entity_type)));
+ $this->assertNull($entity->user_id->target_id, format_string('%entity_type: User ID field is not set.', array('%entity_type' => $entity_type)));
+ $this->assertNull($entity->user_id->entity, format_string('%entity_type: User entity field is not set.', array('%entity_type' => $entity_type)));
// Test setting the values via the typed data API works as well.
// Change the assigned user by entity.
$entity->user_id->first()->get('entity')->setValue($new_user2);
- $this->assertEqual($new_user2->id(), $entity->user_id->target_id, "$entity_type: Updated user id can be read.");
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, "$entity_type: Updated user name value can be read.");
+ $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type)));
// Change the assigned user by id.
$entity->user_id->first()->get('target_id')->setValue($new_user2->id());
- $this->assertEqual($new_user2->id(), $entity->user_id->target_id, "$entity_type: Updated user id can be read.");
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, "$entity_type: Updated user name value can be read.");
+ $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type)));
// Try unsetting a field.
$entity->name->first()->get('value')->setValue(NULL);
$entity->user_id->first()->get('target_id')->setValue(NULL);
- $this->assertNull($entity->name->value, "$entity_type: Name field is not set.");
- $this->assertNull($entity->user_id->target_id, "$entity_type: User ID field is not set.");
- $this->assertNull($entity->user_id->entity, "$entity_type: User entity field is not set.");
+ $this->assertNull($entity->name->value, format_string('%entity_type: Name field is not set.', array('%entity_type' => $entity_type)));
+ $this->assertNull($entity->user_id->target_id, format_string('%entity_type: User ID field is not set.', array('%entity_type' => $entity_type)));
+ $this->assertNull($entity->user_id->entity, format_string('%entity_type: User entity field is not set.', array('%entity_type' => $entity_type)));
// Create a fresh entity so target_id does not get its property object
// instantiated, then verify setting a new value via typed data API works.
@@ -177,38 +177,38 @@ protected function doTestReadWrite($entity_type) {
));
// Access the property object, and set a value.
$entity2->user_id->first()->get('target_id')->setValue($new_user2->id());
- $this->assertEqual($new_user2->id(), $entity2->user_id->target_id, "$entity_type: Updated user id can be read.");
- $this->assertEqual($new_user2->name->value, $entity2->user_id->entity->name->value, "$entity_type: Updated user name value can be read.");
+ $this->assertEqual($new_user2->id(), $entity2->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($new_user2->name->value, $entity2->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type)));
// Test using isset(), empty() and unset().
$entity->name->value = 'test unset';
unset($entity->name->value);
- $this->assertFalse(isset($entity->name->value), "$entity_type: Name is not set");
- $this->assertFalse(isset($entity->name[0]->value), "$entity_type: Name is not set");
- $this->assertTrue(empty($entity->name->value), "$entity_type: Name is empty");
- $this->assertTrue(empty($entity->name[0]->value), "$entity_type: Name is empty");
+ $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type)));
+ $this->assertTrue(empty($entity->name->value), format_string('%entity_type: Name is empty.', array('%entity_type' => $entity_type)));
+ $this->assertTrue(empty($entity->name[0]->value), format_string('%entity_type: Name is empty.', array('%entity_type' => $entity_type)));
$entity->name->value = 'a value';
- $this->assertTrue(isset($entity->name->value), "$entity_type: Name is set");
- $this->assertTrue(isset($entity->name[0]->value), "$entity_type: Name is set.");
- $this->assertFalse(empty($entity->name->value), "$entity_type: Name is not empty");
- $this->assertFalse(empty($entity->name[0]->value), "$entity_type: Name is not empty");
- $this->assertTrue(isset($entity->name[0]), "$entity_type: Name string item is set.");
- $this->assertFalse(isset($entity->name[1]), "$entity_type: Second name string item is not set as it does not exist");
- $this->assertTrue(isset($entity->name), "$entity_type: Name field is set");
- $this->assertFalse(isset($entity->nameInvalid), "$entity_type: Not existing field is not set.");
+ $this->assertTrue(isset($entity->name->value), format_string('%entity_type: Name is set.', array('%entity_type' => $entity_type)));
+ $this->assertTrue(isset($entity->name[0]->value), format_string('%entity_type: Name is set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(empty($entity->name->value), format_string('%entity_type: Name is not empty.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(empty($entity->name[0]->value), format_string('%entity_type: Name is not empty.', array('%entity_type' => $entity_type)));
+ $this->assertTrue(isset($entity->name[0]), format_string('%entity_type: Name string item is set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name[1]), format_string('%entity_type: Second name string item is not set as it does not exist', array('%entity_type' => $entity_type)));
+ $this->assertTrue(isset($entity->name), format_string('%entity_type: Name field is set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->nameInvalid), format_string('%entity_type: Not existing field is not set.', array('%entity_type' => $entity_type)));
unset($entity->name[0]);
- $this->assertFalse(isset($entity->name[0]), "$entity_type: Name field item is not set.");
- $this->assertFalse(isset($entity->name[0]->value), "$entity_type: Name is not set");
- $this->assertFalse(isset($entity->name->value), "$entity_type: Name is not set");
+ $this->assertFalse(isset($entity->name[0]), format_string('%entity_type: Name field item is not set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type)));
// Test emptying a field by assigning an empty value. NULL and array()
// behave the same.
foreach ([NULL, array(), 'unset'] as $empty) {
// Make sure a value is present
$entity->name->value = 'a value';
- $this->assertTrue(isset($entity->name->value), "$entity_type: Name is set");
+ $this->assertTrue(isset($entity->name->value), format_string('%entity_type: Name is set.', array('%entity_type' => $entity_type)));
// Now, empty the field.
if ($empty === 'unset') {
unset($entity->name);
@@ -216,36 +216,36 @@ protected function doTestReadWrite($entity_type) {
else {
$entity->name = $empty;
}
- $this->assertTrue(isset($entity->name), "$entity_type: Name field is set");
- $this->assertTrue($entity->name->isEmpty(), "$entity_type: Name field is set");
- $this->assertIdentical(count($entity->name), 0, "$entity_type: Name field contains no items.");
- $this->assertIdentical($entity->name->getValue(), array(), "$entity_type: Name field value is an empty array.");
- $this->assertFalse(isset($entity->name[0]), "$entity_type: Name field item is not set.");
- $this->assertFalse(isset($entity->name[0]->value), "$entity_type: First name item value is not set.");
- $this->assertFalse(isset($entity->name->value), "$entity_type: Name value is not set.");
+ $this->assertTrue(isset($entity->name), format_string('%entity_type: Name field is set.', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->name->isEmpty(), format_string('%entity_type: Name field is set.', array('%entity_type' => $entity_type)));
+ $this->assertIdentical(count($entity->name), 0, format_string('%entity_type: Name field contains no items.', array('%entity_type' => $entity_type)));
+ $this->assertIdentical($entity->name->getValue(), array(), format_string('%entity_type: Name field value is an empty array.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name[0]), format_string('%entity_type: Name field item is not set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: First name item value is not set.', array('%entity_type' => $entity_type)));
+ $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name value is not set.', array('%entity_type' => $entity_type)));
}
// Access the language field.
$langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
- $this->assertEqual($langcode, $entity->{$langcode_key}->value, "$entity_type: Language object can be read.");
- $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->{$langcode_key}->language, "$entity_type: Language object can be read.");
+ $this->assertEqual($langcode, $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Change the language by code.
$entity->{$langcode_key}->value = \Drupal::languageManager()->getDefaultLanguage()->getId();
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, "$entity_type: Language object can be read.");
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, "$entity_type: Language object can be read.");
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Revert language by code then try setting it by language object.
$entity->{$langcode_key}->value = $langcode;
$entity->{$langcode_key}->language = \Drupal::languageManager()->getDefaultLanguage();
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, "$entity_type: Language object can be read.");
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, "$entity_type: Language object can be read.");
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Access the text field and test updating.
- $this->assertEqual($entity->field_test_text->value, $this->entityFieldText, "$entity_type: Text field can be read.");
+ $this->assertEqual($entity->field_test_text->value, $this->entityFieldText, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
$new_text = $this->randomMachineName();
$entity->field_test_text->value = $new_text;
- $this->assertEqual($entity->field_test_text->value, $new_text, "$entity_type: Updated text field can be read.");
+ $this->assertEqual($entity->field_test_text->value, $new_text, format_string('%entity_type: Updated text field can be read.', array('%entity_type' => $entity_type)));
// Test creating the entity by passing in plain values.
$this->entityName = $this->randomMachineName();
@@ -260,70 +260,70 @@ protected function doTestReadWrite($entity_type) {
'user_id' => $user_item,
'field_test_text' => $text_item,
));
- $this->assertEqual($this->entityName, $entity->name->value, "$entity_type: Name value can be read.");
- $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, "$entity_type: User id can be read.");
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, "$entity_type: User name can be read.");
- $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, "$entity_type: Text field can be read.");
+ $this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
// Tests copying field values by assigning the TypedData objects.
$entity2 = $this->createTestEntity($entity_type);
$entity2->name = $entity->name;
$entity2->user_id = $entity->user_id;
$entity2->field_test_text = $entity->field_test_text;
- $this->assertFalse($entity->name === $entity2->name, "$entity_type: Copying properties results in a different field object.");
- $this->assertEqual($entity->name->value, $entity2->name->value, "$entity_type: Name field copied.");
- $this->assertEqual($entity->user_id->target_id, $entity2->user_id->target_id, "$entity_type: User id field copied.");
- $this->assertEqual($entity->field_test_text->value, $entity2->field_test_text->value, "$entity_type: Text field copied.");
+ $this->assertFalse($entity->name === $entity2->name, format_string('%entity_type: Copying properties results in a different field object.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name->value, $entity2->name->value, format_string('%entity_type: Name field copied.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->user_id->target_id, $entity2->user_id->target_id, format_string('%entity_type: User id field copied.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->field_test_text->value, $entity2->field_test_text->value, format_string('%entity_type: Text field copied.', array('%entity_type' => $entity_type)));
// Tests that assigning TypedData objects to non-field properties keeps the
// assigned value as is.
$entity2 = $this->createTestEntity($entity_type);
$entity2->_not_a_field = $entity->name;
- $this->assertTrue($entity2->_not_a_field === $entity->name, "$entity_type: Typed data objects can be copied to non-field properties as is.");
+ $this->assertTrue($entity2->_not_a_field === $entity->name, format_string('%entity_type: Typed data objects can be copied to non-field properties as is.', array('%entity_type' => $entity_type)));
// Tests adding a value to a field item list.
$entity->name[] = 'Another name';
- $this->assertEqual($entity->name[1]->value, 'Another name', "$entity_type: List item added via [] and the first property.");
+ $this->assertEqual($entity->name[1]->value, 'Another name', format_string('%entity_type: List item added via [] and the first property.', array('%entity_type' => $entity_type)));
$entity->name[] = array('value' => 'Third name');
- $this->assertEqual($entity->name[2]->value, 'Third name', "$entity_type: List item added via [] and an array of properties.");
+ $this->assertEqual($entity->name[2]->value, 'Third name', format_string('%entity_type: List item added via [] and an array of properties.', array('%entity_type' => $entity_type)));
$entity->name[3] = array('value' => 'Fourth name');
- $this->assertEqual($entity->name[3]->value, 'Fourth name', "$entity_type: List item added via offset and an array of properties.");
+ $this->assertEqual($entity->name[3]->value, 'Fourth name', format_string('%entity_type: List item added via offset and an array of properties.', array('%entity_type' => $entity_type)));
unset($entity->name[3]);
// Test removing and empty-ing list items.
- $this->assertEqual(count($entity->name), 3, "$entity_type: List has 3 items.");
+ $this->assertEqual(count($entity->name), 3, format_string('%entity_type: List has 3 items.', array('%entity_type' => $entity_type)));
unset($entity->name[1]);
- $this->assertEqual(count($entity->name), 2, "$entity_type: Second list item has been removed.");
- $this->assertEqual($entity->name[1]->value, 'Third name', "$entity_type: The subsequent items have been shifted up.");
- $this->assertEqual($entity->name[1]->getName(), 1, "$entity_type: The items names have been updated to their new delta.");
+ $this->assertEqual(count($entity->name), 2, format_string('%entity_type: Second list item has been removed.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name[1]->value, 'Third name', format_string('%entity_type: The subsequent items have been shifted up.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name[1]->getName(), 1, format_string('%entity_type: The items names have been updated to their new delta.', array('%entity_type' => $entity_type)));
$entity->name[1] = NULL;
- $this->assertEqual(count($entity->name), 2, "$entity_type: Assigning NULL does not reduce array count.");
- $this->assertTrue($entity->name[1]->isEmpty(), "$entity_type: Assigning NULL empties the item.");
+ $this->assertEqual(count($entity->name), 2, format_string('%entity_type: Assigning NULL does not reduce array count.', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->name[1]->isEmpty(), format_string('%entity_type: Assigning NULL empties the item.', array('%entity_type' => $entity_type)));
// Test using isEmpty().
unset($entity->name[1]);
- $this->assertFalse($entity->name[0]->isEmpty(), "$entity_type: Name item is not empty.");
+ $this->assertFalse($entity->name[0]->isEmpty(), format_string('%entity_type: Name item is not empty.', array('%entity_type' => $entity_type)));
$entity->name->value = NULL;
- $this->assertTrue($entity->name[0]->isEmpty(), "$entity_type: Name item is empty.");
- $this->assertTrue($entity->name->isEmpty(), "$entity_type: Name field is empty.");
- $this->assertEqual(count($entity->name), 1, "$entity_type: Empty item is considered when counting.");
- $this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), "$entity_type: Count matches iterator count.");
- $this->assertTrue($entity->name->getValue() === array(0 => array('value' => NULL)), "$entity_type: Name field value contains a NULL value.");
+ $this->assertTrue($entity->name[0]->isEmpty(), format_string('%entity_type: Name item is empty.', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->name->isEmpty(), format_string('%entity_type: Name field is empty.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(count($entity->name), 1, format_string('%entity_type: Empty item is considered when counting.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), format_string('%entity_type: Count matches iterator count.', array('%entity_type' => $entity_type)));
+ $this->assertTrue($entity->name->getValue() === array(0 => array('value' => NULL)), format_string('%entity_type: Name field value contains a NULL value.', array('%entity_type' => $entity_type)));
// Test using filterEmptyItems().
$entity->name = array(NULL, 'foo');
- $this->assertEqual(count($entity->name), 2, "$entity_type: List has 2 items.");
+ $this->assertEqual(count($entity->name), 2, format_string('%entity_type: List has 2 items.', array('%entity_type' => $entity_type)));
$entity->name->filterEmptyItems();
- $this->assertEqual(count($entity->name), 1, "$entity_type: The empty item was removed.");
- $this->assertEqual($entity->name[0]->value, 'foo', "$entity_type: The items were renumbered.");
- $this->assertEqual($entity->name[0]->getName(), 0, "$entity_type: The deltas were updated in the items.");
+ $this->assertEqual(count($entity->name), 1, format_string('%entity_type: The empty item was removed.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name[0]->value, 'foo', format_string('%entity_type: The items were renumbered.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->name[0]->getName(), 0, format_string('%entity_type: The deltas were updated in the items.', array('%entity_type' => $entity_type)));
// Test get and set field values.
$entity->name = 'foo';
- $this->assertEqual($entity->name[0]->toArray(), array('value' => 'foo'), "$entity_type: Field value has been retrieved via toArray()");
+ $this->assertEqual($entity->name[0]->toArray(), array('value' => 'foo'), format_string('%entity_type: Field value has been retrieved via toArray()', array('%entity_type' => $entity_type)));
$values = $entity->toArray();
- $this->assertEqual($values['name'], array(0 => array('value' => 'foo')), "$entity_type: Field value has been retrieved via toArray() from an entity.");
+ $this->assertEqual($values['name'], array(0 => array('value' => 'foo')), format_string('%entity_type: Field value has been retrieved via toArray() from an entity.', array('%entity_type' => $entity_type)));
// Make sure the user id can be set to zero.
$user_item[0]['target_id'] = 0;
@@ -332,8 +332,8 @@ protected function doTestReadWrite($entity_type) {
'user_id' => $user_item,
'field_test_text' => $text_item,
));
- $this->assertNotNull($entity->user_id->target_id, "$entity_type: User id is not NULL");
- $this->assertIdentical($entity->user_id->target_id, 0, "$entity_type: User id has been set to 0");
+ $this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', array('%entity_type' => $entity_type)));
+ $this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', array('%entity_type' => $entity_type)));
// Test setting the ID with the value only.
$entity = entity_create($entity_type, array(
@@ -341,8 +341,8 @@ protected function doTestReadWrite($entity_type) {
'user_id' => 0,
'field_test_text' => $text_item,
));
- $this->assertNotNull($entity->user_id->target_id, "$entity_type: User id is not NULL");
- $this->assertIdentical($entity->user_id->target_id, 0, "$entity_type: User id has been set to 0");
+ $this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', array('%entity_type' => $entity_type)));
+ $this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', array('%entity_type' => $entity_type)));
}
/**
@@ -365,19 +365,19 @@ protected function doTestSave($entity_type) {
$langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$entity = $this->createTestEntity($entity_type);
$entity->save();
- $this->assertTrue((bool) $entity->id(), "$entity_type: Entity has received an id.");
+ $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity has received an id.', array('%entity_type' => $entity_type)));
$entity = entity_load($entity_type, $entity->id());
- $this->assertTrue((bool) $entity->id(), "$entity_type: Entity loaded.");
+ $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity loaded.', array('%entity_type' => $entity_type)));
// Access the name field.
- $this->assertEqual(1, $entity->id->value, "$entity_type: ID value can be read.");
- $this->assertTrue(is_string($entity->uuid->value), "$entity_type: UUID value can be read.");
- $this->assertEqual('en', $entity->{$langcode_key}->value, "$entity_type: Language object can be read.");
- $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, "$entity_type: Language object can be read.");
- $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, "$entity_type: User id can be read.");
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, "$entity_type: User name can be read.");
- $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, "$entity_type: Text field can be read.");
+ $this->assertEqual(1, $entity->id->value, format_string('%entity_type: ID value can be read.', array('%entity_type' => $entity_type)));
+ $this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
}
/**
@@ -517,8 +517,8 @@ protected function doTestIterator($entity_type) {
}
$fields = $entity->getFields();
- $this->assertEqual(array_keys($fields), array_keys($entity->getTypedData()->getDataDefinition()->getPropertyDefinitions()), "$entity_type: All fields returned.");
- $this->assertEqual($fields, iterator_to_array($entity->getIterator()), "$entity_type: Entity iterator iterates over all fields.");
+ $this->assertEqual(array_keys($fields), array_keys($entity->getTypedData()->getDataDefinition()->getPropertyDefinitions()), format_string('%entity_type: All fields returned.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($fields, iterator_to_array($entity->getIterator()), format_string('%entity_type: Entity iterator iterates over all fields.', array('%entity_type' => $entity_type)));
}
/**
@@ -560,7 +560,7 @@ protected function doTestDataStructureInterfaces($entity_type) {
);
asort($strings);
asort($target_strings);
- $this->assertEqual(array_values($strings), array_values($target_strings), "$entity_type: All contained strings found.");
+ $this->assertEqual(array_values($strings), array_values($target_strings), format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type)));
}
/**
@@ -728,12 +728,12 @@ protected function doTestComputedProperties($entity_type) {
$entity->field_test_text->format = filter_default_format();
$target = "The <strong>text</strong> text to filter.
\n";
- $this->assertEqual($entity->field_test_text->processed, $target, "$entity_type: Text is processed with the default filter.");
+ $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', array('%entity_type' => $entity_type)));
// Save and load entity and make sure it still works.
$entity->save();
$entity = entity_load($entity_type, $entity->id());
- $this->assertEqual($entity->field_test_text->processed, $target, "$entity_type: Text is processed with the default filter.");
+ $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', array('%entity_type' => $entity_type)));
}
}
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
index a605188..de62ba7 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
@@ -43,21 +43,21 @@ protected function doTestEntityLanguageMethods($entity_type) {
'name' => 'test',
'user_id' => $this->container->get('current_user')->id(),
));
- $this->assertEqual($entity->language()->getId(), $this->languageManager->getDefaultLanguage()->getId(), "$entity_type: Entity created with API has default language.");
+ $this->assertEqual($entity->language()->getId(), $this->languageManager->getDefaultLanguage()->getId(), format_string('%entity_type: Entity created with API has default language.', array('%entity_type' => $entity_type)));
$entity = entity_create($entity_type, array(
'name' => 'test',
'user_id' => \Drupal::currentUser()->id(),
$langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
- $this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, "$entity_type: Entity language not specified.");
- $this->assertFalse($entity->getTranslationLanguages(FALSE), "$entity_type: No translations are available");
+ $this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type)));
+ $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Set the value in default language.
$entity->set($this->fieldName, array(0 => array('value' => 'default value')));
// Get the value.
$field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get($this->fieldName);
- $this->assertEqual($field->value, 'default value', "$entity_type: Untranslated value retrieved.");
- $this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, "$entity_type: Field object has the expected langcode.");
+ $this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Try to get add a translation to language neutral entity.
$message = 'Adding a translation to a language-neutral entity results in an error.';
@@ -74,21 +74,21 @@ protected function doTestEntityLanguageMethods($entity_type) {
$default_langcode = $this->langcodes[0];
$entity->{$langcode_key}->value = $default_langcode;
$entity->{$this->fieldName} = array();
- $this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), "$entity_type: Entity language retrieved.");
- $this->assertFalse($entity->getTranslationLanguages(FALSE), "$entity_type: No translations are available");
+ $this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), format_string('%entity_type: Entity language retrieved.', array('%entity_type' => $entity_type)));
+ $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Set the value in default language.
$entity->set($this->fieldName, array(0 => array('value' => 'default value')));
// Get the value.
$field = $entity->get($this->fieldName);
- $this->assertEqual($field->value, 'default value', "$entity_type: Untranslated value retrieved.");
- $this->assertEqual($field->getLangcode(), $default_langcode, "$entity_type: Field object has the expected langcode.");
+ $this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($field->getLangcode(), $default_langcode, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Set a translation.
$entity->addTranslation($this->langcodes[1])->set($this->fieldName, array(0 => array('value' => 'translation 1')));
$field = $entity->getTranslation($this->langcodes[1])->{$this->fieldName};
- $this->assertEqual($field->value, 'translation 1', "$entity_type: Translated value set.");
- $this->assertEqual($field->getLangcode(), $this->langcodes[1], "$entity_type: Field object has the expected langcode.");
+ $this->assertEqual($field->value, 'translation 1', format_string('%entity_type: Translated value set.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($field->getLangcode(), $this->langcodes[1], format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Make sure the untranslated value stays.
$field = $entity->get($this->fieldName);
@@ -109,7 +109,7 @@ protected function doTestEntityLanguageMethods($entity_type) {
}
// Try to get a not available translation.
- $this->assertNull($entity->addTranslation($this->langcodes[2])->get($this->fieldName)->value, "$entity_type: A translation that is not available is NULL.");
+ $this->assertNull($entity->addTranslation($this->langcodes[2])->get($this->fieldName)->value, format_string('%entity_type: A translation that is not available is NULL.', array('%entity_type' => $entity_type)));
// Try to get a value using an invalid language code.
$message = 'Getting an invalid translation results in an error.';
@@ -124,10 +124,10 @@ protected function doTestEntityLanguageMethods($entity_type) {
// Try to set a value using an invalid language code.
try {
$entity->getTranslation('invalid')->set($this->fieldName, NULL);
- $this->fail("$entity_type: Setting a translation for an invalid language throws an exception.");
+ $this->fail(format_string('%entity_type: Setting a translation for an invalid language throws an exception.', array('%entity_type' => $entity_type)));
}
catch (\InvalidArgumentException $e) {
- $this->pass("$entity_type: Setting a translation for an invalid language throws an exception.");
+ $this->pass(format_string('%entity_type: Setting a translation for an invalid language throws an exception.', array('%entity_type' => $entity_type)));
}
// Set the value in default language.
@@ -135,8 +135,8 @@ protected function doTestEntityLanguageMethods($entity_type) {
$entity->getTranslation($this->langcodes[1])->set($field_name, array(0 => array('value' => 'default value2')));
// Get the value.
$field = $entity->get($field_name);
- $this->assertEqual($field->value, 'default value2', "$entity_type: Untranslated value set into a translation in non-strict mode.");
- $this->assertEqual($field->getLangcode(), $default_langcode, "$entity_type: Field object has the expected langcode.");
+ $this->assertEqual($field->value, 'default value2', format_string('%entity_type: Untranslated value set into a translation in non-strict mode.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($field->getLangcode(), $default_langcode, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
}
/**
@@ -168,21 +168,21 @@ protected function doTestMultilingualProperties($entity_type) {
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
- $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, "$entity_type: Entity created as language neutral.");
+ $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type)));
$field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('name');
- $this->assertEqual($name, $field->value, "$entity_type: The entity name has been correctly stored as language neutral.");
- $this->assertEqual($default_langcode, $field->getLangcode(), "$entity_type: The field object has the expected langcode.");
- $this->assertEqual($uid, $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('user_id')->target_id, "$entity_type: The entity author has been correctly stored as language neutral.");
+ $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($uid, $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as language neutral.', array('%entity_type' => $entity_type)));
$translation = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT);
$field = $translation->get('name');
- $this->assertEqual($name, $field->value, "$entity_type: The entity name defaults to neutral language.");
- $this->assertEqual($default_langcode, $field->getLangcode(), "$entity_type: The field object has the expected langcode.");
- $this->assertEqual($uid, $translation->get('user_id')->target_id, "$entity_type: The entity author defaults to neutral language.");
+ $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name defaults to neutral language.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($uid, $translation->get('user_id')->target_id, format_string('%entity_type: The entity author defaults to neutral language.', array('%entity_type' => $entity_type)));
$field = $entity->get('name');
- $this->assertEqual($name, $field->value, "$entity_type: The entity name can be retrieved without specifying a language.");
- $this->assertEqual($default_langcode, $field->getLangcode(), "$entity_type: The field object has the expected langcode.");
- $this->assertEqual($uid, $entity->get('user_id')->target_id, "$entity_type: The entity author can be retrieved without specifying a language.");
+ $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name can be retrieved without specifying a language.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($uid, $entity->get('user_id')->target_id, format_string('%entity_type: The entity author can be retrieved without specifying a language.', array('%entity_type' => $entity_type)));
// Create a language-aware entity and check that properties are stored
// as language-aware.
@@ -190,11 +190,11 @@ protected function doTestMultilingualProperties($entity_type) {
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
- $this->assertEqual($default_langcode, $langcode, "$entity_type: Entity created as language specific.");
+ $this->assertEqual($default_langcode, $langcode, format_string('%entity_type: Entity created as language specific.', array('%entity_type' => $entity_type)));
$field = $entity->getTranslation($langcode)->get('name');
- $this->assertEqual($name, $field->value, "$entity_type: The entity name has been correctly stored as a language-aware property.");
- $this->assertEqual($default_langcode, $field->getLangcode(), "$entity_type: The field object has the expected langcode.");
- $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, "$entity_type: The entity author has been correctly stored as a language-aware property.");
+ $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type)));
// Create property translations.
$properties = array();
@@ -222,11 +222,15 @@ protected function doTestMultilingualProperties($entity_type) {
// Check that property translation were correctly stored.
$entity = entity_load($entity_type, $entity->id());
foreach ($this->langcodes as $langcode) {
+ $args = array(
+ '%entity_type' => $entity_type,
+ '%langcode' => $langcode,
+ );
$field = $entity->getTranslation($langcode)->get('name');
- $this->assertEqual($properties[$langcode]['name'][0], $field->value, "$entity_type: The entity name has been correctly stored for language $langcode.");
+ $this->assertEqual($properties[$langcode]['name'][0], $field->value, format_string('%entity_type: The entity name has been correctly stored for language %langcode.', $args));
$field_langcode = ($langcode == $entity->language()->getId()) ? $default_langcode : $langcode;
- $this->assertEqual($field_langcode, $field->getLangcode(), "$entity_type: The field object has the expected langcode $langcode.");
- $this->assertEqual($properties[$langcode]['user_id'][0], $entity->getTranslation($langcode)->get('user_id')->target_id, "$entity_type: The entity author has been correctly stored for language $langcode.");
+ $this->assertEqual($field_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expected langcode %langcode.', $args));
+ $this->assertEqual($properties[$langcode]['user_id'][0], $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored for language %langcode.', $args));
}
// Test query conditions (cache is reset at each call).
@@ -241,24 +245,24 @@ protected function doTestMultilingualProperties($entity_type) {
))->save();
$entities = entity_load_multiple($entity_type);
- $this->assertEqual(count($entities), 3, "$entity_type: Three entities were created.");
+ $this->assertEqual(count($entities), 3, format_string('%entity_type: Three entities were created.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple($entity_type, array($translated_id));
- $this->assertEqual(count($entities), 1, "$entity_type: One entity correctly loaded by id.");
+ $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by id.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array('name' => $name));
- $this->assertEqual(count($entities), 2, "$entity_type: Two entities correctly loaded by name.");
+ $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities correctly loaded by name.', array('%entity_type' => $entity_type)));
// @todo The default language condition should go away in favor of an
// explicit parameter.
$entities = entity_load_multiple_by_properties($entity_type, array('name' => $properties[$langcode]['name'][0], $default_langcode_key => 0));
- $this->assertEqual(count($entities), 1, "$entity_type: One entity correctly loaded by name translation.");
+ $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name translation.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $default_langcode, 'name' => $name));
- $this->assertEqual(count($entities), 1, "$entity_type: One entity correctly loaded by name and language.");
+ $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name and language.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]));
- $this->assertEqual(count($entities), 0, "$entity_type: No entity loaded by name translation specifying the translation language.");
+ $this->assertEqual(count($entities), 0, format_string('%entity_type: No entity loaded by name translation specifying the translation language.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0], $default_langcode_key => 0));
- $this->assertEqual(count($entities), 1, "$entity_type: One entity loaded by name translation and language specifying to look for translations.");
+ $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity loaded by name translation and language specifying to look for translations.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array('user_id' => $properties[$langcode]['user_id'][0], $default_langcode_key => NULL));
- $this->assertEqual(count($entities), 2, "$entity_type: Two entities loaded by uid without caring about property translatability.");
+ $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities loaded by uid without caring about property translatability.', array('%entity_type' => $entity_type)));
// Test property conditions and orders with multiple languages in the same
// query.
@@ -270,7 +274,7 @@ protected function doTestMultilingualProperties($entity_type) {
->condition($group)
->condition('name', $properties[$langcode]['name'][0], '=', $langcode)
->execute();
- $this->assertEqual(count($result), 1, "$entity_type: One entity loaded by name and uid using different language meta conditions.");
+ $this->assertEqual(count($result), 1, format_string('%entity_type: One entity loaded by name and uid using different language meta conditions.', array('%entity_type' => $entity_type)));
// Test mixed property and field conditions.
$entity = entity_load($entity_type, reset($result), TRUE);
@@ -289,7 +293,7 @@ protected function doTestMultilingualProperties($entity_type) {
->condition($default_langcode_group)
->condition($langcode_group)
->execute();
- $this->assertEqual(count($result), 1, "$entity_type: One entity loaded by name, uid and field value using different language meta conditions.");
+ $this->assertEqual(count($result), 1, format_string('%entity_type: One entity loaded by name, uid and field value using different language meta conditions.', array('%entity_type' => $entity_type)));
}
/**
@@ -449,7 +453,7 @@ protected function doTestEntityTranslationAPI($entity_type) {
$translation = $entity->getTranslation($langcode2);
$entity->removeTranslation($langcode2);
foreach (array('get', 'set', '__get', '__set', 'createDuplicate') as $method) {
- $message = "The $method method raises an exception when trying to manipulate a removed translation.";
+ $message = format_string('The @method method raises an exception when trying to manipulate a removed translation.', array('@method' => $method));
try {
$translation->{$method}('name', $this->randomMachineName());
$this->fail($message);
@@ -471,7 +475,7 @@ protected function doTestEntityTranslationAPI($entity_type) {
// Check that removing an invalid translation causes an exception to be
// thrown.
foreach (array($default_langcode, LanguageInterface::LANGCODE_DEFAULT, $this->randomMachineName()) as $invalid_langcode) {
- $message = "Removing an invalid translation ($invalid_langcode) causes an exception to be thrown.";
+ $message = format_string('Removing an invalid translation (@langcode) causes an exception to be thrown.', array('@langcode' => $invalid_langcode));
try {
$entity->removeTranslation($invalid_langcode);
$this->fail($message);
@@ -687,7 +691,7 @@ function testFieldDefinitions() {
$this->assertTrue(!isset($base_field_definitions['id']->translatable), 'Translatability for the id field is not defined.');
$this->assertFalse($definitions['id']->isTranslatable(), 'Field translatability is disabled by default.');
- // Check that entity id keys have the expected translatability.
+ // Check that entity id keys have the expect translatability.
$translatable_fields = array(
'id' => TRUE,
'uuid' => TRUE,
@@ -698,7 +702,7 @@ function testFieldDefinitions() {
foreach ($translatable_fields as $name => $translatable) {
$this->state->set('entity_test.field_definitions.translatable', array($name => $translatable));
$this->entityManager->clearCachedFieldDefinitions();
- $message = "Field $name cannot be translatable.";
+ $message = format_string('Field %field cannot be translatable.', array('%field' => $name));
try {
$this->entityManager->getBaseFieldDefinitions($entity_type);
@@ -792,7 +796,7 @@ function testEntityAdapter() {
foreach ($langcodes as $langcode) {
$adapter = $entity->getTranslation($langcode)->getTypedData();
$name = $adapter->get('name')->value;
- $this->assertEqual($name, $values[$langcode]['name'], 'Name correctly retrieved from "' . $langcode . '" adapter');
+ $this->assertEqual($name, $values[$langcode]['name'], SafeMarkup::format('Name correctly retrieved from "@langcode" adapter', array('@langcode' => $langcode)));
}
}
@@ -814,10 +818,12 @@ public function testFieldEntityReference() {
$translation = $entity->getTranslation($langcode);
foreach ($translation->getFields() as $field_name => $field) {
if ($field->getFieldDefinition()->isTranslatable()) {
- $this->assertEqual($langcode, $field->getEntity()->language()->getId(), "Translatable field $field_name on translation $langcode has correct entity reference in translation $langcode.");
+ $args = ['%field_name' => $field_name, '%langcode' => $langcode];
+ $this->assertEqual($langcode, $field->getEntity()->language()->getId(), format_string('Translatable field %field_name on translation %langcode has correct entity reference in translation %langcode.', $args));
}
else {
- $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), "Non translatable field $field_name on translation $langcode has correct entity reference in the default translation $default_langcode.");
+ $args = ['%field_name' => $field_name, '%langcode' => $langcode, '%default_langcode' => $default_langcode];
+ $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), format_string('Non translatable field %field_name on translation %langcode has correct entity reference in the default translation %default_langcode.', $args));
}
}
}
diff --git a/core/modules/views/src/Tests/Handler/FieldKernelTest.php b/core/modules/views/src/Tests/Handler/FieldKernelTest.php
index e6fd74b..815b1ec 100644
--- a/core/modules/views/src/Tests/Handler/FieldKernelTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldKernelTest.php
@@ -105,8 +105,9 @@ public function testQuery() {
* The value to search for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
- * messages: just concatenate strings to embed variables in the message text
- * ,not t(). If left blank, a default message will be displayed.
+ * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
+ * variables in the message text, not t(). If left blank, a default message
+ * will be displayed.
* @param string $group
* (optional) The group this message is in, which is displayed in a column
* in test output. Use 'Debug' to indicate this is debugging output. Do not
@@ -129,8 +130,9 @@ protected function assertSubString($haystack, $needle, $message = '', $group = '
* The value to search for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
- * messages: just concatenate strings to embed variables in the message text
- * ,not t(). If left blank, a default message will be displayed.
+ * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
+ * variables in the message text, not t(). If left blank, a default message
+ * will be displayed.
* @param string $group
* (optional) The group this message is in, which is displayed in a column
* in test output. Use 'Debug' to indicate this is debugging output. Do not