summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreffulgentsia2015-09-14 17:31:04 (GMT)
committereffulgentsia2015-09-14 17:31:04 (GMT)
commit7dee9f8f276cdf853d52bc84492ab0a40eae66fa (patch)
tree30a7cfb2644b0f910f538abdf5543161aff1280f
parent9343f6c7eb7d57508e3c5cab765e175dbe5dff90 (diff)
Issue #2566447 by stefan.r, joelpittet, alexpott, lauriii, dawehner: Cast safe string objects to string or use assertEqual() in some assertIdentical() comparisons
-rw-r--r--core/modules/block/src/Tests/BlockInterfaceTest.php2
-rw-r--r--core/modules/block_content/src/Tests/BlockContentListTest.php2
-rw-r--r--core/modules/block_content/src/Tests/BlockContentListViewsTest.php2
-rw-r--r--core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php2
-rw-r--r--core/modules/ckeditor/src/Tests/CKEditorAdminTest.php14
-rw-r--r--core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php8
-rw-r--r--core/modules/ckeditor/src/Tests/CKEditorTest.php27
-rw-r--r--core/modules/config/src/Tests/ConfigImportRenameValidationTest.php4
-rw-r--r--core/modules/locale/src/Tests/LocaleImportFunctionalTest.php8
-rw-r--r--core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php2
-rw-r--r--core/modules/node/src/Tests/Migrate/d6/MigrateNodeBuilderTest.php4
-rw-r--r--core/modules/shortcut/src/Tests/ShortcutSetsTest.php2
-rw-r--r--core/modules/simpletest/src/AssertHelperTrait.php40
-rw-r--r--core/modules/simpletest/src/TestBase.php42
-rw-r--r--core/modules/simpletest/src/WebTestBase.php2
-rw-r--r--core/modules/simpletest/tests/src/Unit/AssertHelperTraitTest.php47
-rw-r--r--core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php22
-rw-r--r--core/modules/system/src/Tests/Form/ValidationTest.php2
-rw-r--r--core/modules/system/src/Tests/Plugin/InspectionTest.php6
-rw-r--r--core/modules/views/src/Tests/ModuleTest.php14
-rw-r--r--core/tests/Drupal/KernelTests/KernelTestBase.php2
21 files changed, 157 insertions, 97 deletions
diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php
index 7215765..f7af9fe 100644
--- a/core/modules/block/src/Tests/BlockInterfaceTest.php
+++ b/core/modules/block/src/Tests/BlockInterfaceTest.php
@@ -109,7 +109,7 @@ class BlockInterfaceTest extends KernelTestBase {
$actual_form = $display_block->buildConfigurationForm(array(), $form_state);
// Remove the visibility sections, as that just tests condition plugins.
unset($actual_form['visibility'], $actual_form['visibility_tabs']);
- $this->assertIdentical($actual_form, $expected_form, 'Only the expected form elements were present.');
+ $this->assertIdentical($this->castSafeStrings($actual_form), $this->castSafeStrings($expected_form), 'Only the expected form elements were present.');
$expected_build = array(
'#children' => 'My custom display message.',
diff --git a/core/modules/block_content/src/Tests/BlockContentListTest.php b/core/modules/block_content/src/Tests/BlockContentListTest.php
index aeed4dc..8b77d1a 100644
--- a/core/modules/block_content/src/Tests/BlockContentListTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentListTest.php
@@ -46,7 +46,7 @@ class BlockContentListTest extends BlockContentTestBase {
// Test the contents of each th cell.
$expected_items = array(t('Block description'), t('Operations'));
foreach ($elements as $key => $element) {
- $this->assertIdentical((string) $element[0], $expected_items[$key]);
+ $this->assertEqual($element[0], $expected_items[$key]);
}
$label = 'Antelope';
diff --git a/core/modules/block_content/src/Tests/BlockContentListViewsTest.php b/core/modules/block_content/src/Tests/BlockContentListViewsTest.php
index ba84f2b..34a5f22 100644
--- a/core/modules/block_content/src/Tests/BlockContentListViewsTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentListViewsTest.php
@@ -42,7 +42,7 @@ class BlockContentListViewsTest extends BlockContentTestBase {
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
// Test the contents of each th cell.
- $expected_items = [t('Block description'), t('Block type'), t('Updated'), t('Operations')];
+ $expected_items = ['Block description', 'Block type', 'Updated', 'Operations'];
foreach ($elements as $key => $element) {
if ($element->xpath('a')) {
$this->assertIdentical(trim((string) $element->xpath('a')[0]), $expected_items[$key]);
diff --git a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
index 0668c86..942239b 100644
--- a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
+++ b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
@@ -193,7 +193,7 @@ class BreakpointDiscoveryTest extends KernelTestBase {
);
$breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
// Ensure the order is as expected. Should be sorted by label.
- $this->assertIdentical($expected, $breakpoint_groups);
+ $this->assertIdentical($expected, $this->castSafeStrings($breakpoint_groups));
$expected = array(
'breakpoint_theme_test' => 'theme',
diff --git a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php
index ca1954f..6c5ee13 100644
--- a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php
+++ b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php
@@ -87,23 +87,23 @@ class CKEditorAdminTest extends WebTestBase {
// Button groups
array(
array(
- 'name' => t('Formatting'),
+ 'name' => 'Formatting',
'items' => array('Bold', 'Italic',),
),
array(
- 'name' => t('Links'),
+ 'name' => 'Links',
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
- 'name' => t('Lists'),
+ 'name' => 'Lists',
'items' => array('BulletedList', 'NumberedList',),
),
array(
- 'name' => t('Media'),
+ 'name' => 'Media',
'items' => array('Blockquote', 'DrupalImage',),
),
array(
- 'name' => t('Tools'),
+ 'name' => 'Tools',
'items' => array('Source',),
),
),
@@ -111,7 +111,7 @@ class CKEditorAdminTest extends WebTestBase {
),
'plugins' => array(),
);
- $this->assertIdentical($ckeditor->getDefaultSettings(), $expected_default_settings);
+ $this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings);
// Keep the "CKEditor" editor selected and click the "Configure" button.
$this->drupalPostAjaxForm(NULL, $edit, 'editor_configure');
@@ -279,7 +279,7 @@ class CKEditorAdminTest extends WebTestBase {
$expected_settings['plugins']['stylescombo']['styles'] = '';
$editor = entity_load('editor', 'amazing_format');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.');
- $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
+ $this->assertIdentical($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.');
}
}
diff --git a/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php b/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php
index 01b9081..1081eb9 100644
--- a/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php
+++ b/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php
@@ -107,12 +107,12 @@ class CKEditorLoadingTest extends WebTestBase {
$expected = array('formats' => array('filtered_html' => array(
'format' => 'filtered_html',
'editor' => 'ckeditor',
- 'editorSettings' => $ckeditor_plugin->getJSSettings($editor),
+ 'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
'editorSupportsContentFiltering' => TRUE,
'isXssSafe' => FALSE,
)));
$this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
- $this->assertIdentical($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct.");
+ $this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
$this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
$this->assertTrue(count($body) === 1, 'A body field exists.');
$this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.');
@@ -138,12 +138,12 @@ class CKEditorLoadingTest extends WebTestBase {
'filtered_html' => array(
'format' => 'filtered_html',
'editor' => 'ckeditor',
- 'editorSettings' => $ckeditor_plugin->getJSSettings($editor),
+ 'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
'editorSupportsContentFiltering' => TRUE,
'isXssSafe' => FALSE,
)));
$this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
- $this->assertIdentical($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct.");
+ $this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
$this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
$this->assertTrue(in_array('ckeditor/drupal.ckeditor', explode(',', $settings['ajaxPageState']['libraries'])), 'CKEditor glue library is present.');
}
diff --git a/core/modules/ckeditor/src/Tests/CKEditorTest.php b/core/modules/ckeditor/src/Tests/CKEditorTest.php
index d2a59bc..f842862 100644
--- a/core/modules/ckeditor/src/Tests/CKEditorTest.php
+++ b/core/modules/ckeditor/src/Tests/CKEditorTest.php
@@ -94,8 +94,9 @@ class CKEditorTest extends KernelTestBase {
'drupallink' => file_create_url('core/modules/ckeditor/js/plugins/drupallink/plugin.js'),
),
);
+ $expected_config = $this->castSafeStrings($expected_config);
ksort($expected_config);
- $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for default configuration.');
+ $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for default configuration.');
// Customize the configuration: add button, have two contextually enabled
// buttons, and configure a CKEditor plugin setting.
@@ -116,7 +117,7 @@ class CKEditorTest extends KernelTestBase {
$expected_config['drupalExternalPlugins']['llama_contextual_and_button'] = file_create_url('core/modules/ckeditor/tests/modules/js/llama_contextual_and_button.js');
$expected_config['contentsCss'][] = file_create_url('core/modules/ckeditor/tests/modules/ckeditor_test.css');
ksort($expected_config);
- $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Change the allowed HTML tags; the "allowedContent" and "format_tags"
// settings for CKEditor should automatically be updated as well.
@@ -127,7 +128,7 @@ class CKEditorTest extends KernelTestBase {
$expected_config['allowedContent']['pre'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['h3'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
$expected_config['format_tags'] = 'p;h2;h3;h4;h5;h6;pre';
- $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Disable the filter_html filter: allow *all *tags.
$format->setFilterConfig('filter_html', array('status' => 0));
@@ -136,7 +137,7 @@ class CKEditorTest extends KernelTestBase {
$expected_config['allowedContent'] = TRUE;
$expected_config['disallowedContent'] = FALSE;
$expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
- $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Enable the filter_test_restrict_tags_and_attributes filter.
$format->setFilterConfig('filter_test_restrict_tags_and_attributes', array(
@@ -205,7 +206,7 @@ class CKEditorTest extends KernelTestBase {
);
$expected_config['format_tags'] = 'p';
ksort($expected_config);
- $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
}
/**
@@ -216,7 +217,7 @@ class CKEditorTest extends KernelTestBase {
// Default toolbar.
$expected = $this->getDefaultToolbarConfig();
- $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
+ $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
// Customize the configuration.
$settings = $editor->getSettings();
@@ -224,7 +225,7 @@ class CKEditorTest extends KernelTestBase {
$editor->setSettings($settings);
$editor->save();
$expected[0]['items'][] = 'Strike';
- $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
+ $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
// Enable the editor_test module, customize further.
$this->enableModules(array('ckeditor_test'));
@@ -236,7 +237,7 @@ class CKEditorTest extends KernelTestBase {
$editor->save();
$expected[0]['name'] = 'JunkScience';
$expected[0]['items'][] = 'Llama';
- $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
+ $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
}
/**
@@ -442,23 +443,23 @@ class CKEditorTest extends KernelTestBase {
protected function getDefaultToolbarConfig() {
return array(
array(
- 'name' => t('Formatting'),
+ 'name' => 'Formatting',
'items' => array('Bold', 'Italic',),
),
array(
- 'name' => t('Links'),
+ 'name' => 'Links',
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
- 'name' => t('Lists'),
+ 'name' => 'Lists',
'items' => array('BulletedList', 'NumberedList',),
),
array(
- 'name' => t('Media'),
+ 'name' => 'Media',
'items' => array('Blockquote', 'DrupalImage',),
),
array(
- 'name' => t('Tools'),
+ 'name' => 'Tools',
'items' => array('Source',),
),
'/',
diff --git a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
index 7f0d72e..e0b6a70 100644
--- a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
+++ b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
@@ -112,7 +112,7 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
$expected = array(
SafeMarkup::format('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id))
);
- $this->assertIdentical($expected, $this->configImporter->getErrors());
+ $this->assertEqual($expected, $this->configImporter->getErrors());
}
}
@@ -155,7 +155,7 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
$expected = array(
SafeMarkup::format('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array('@old_name' => 'config_test.old', '@new_name' => 'config_test.new'))
);
- $this->assertIdentical($expected, $this->configImporter->getErrors());
+ $this->assertEqual($expected, $this->configImporter->getErrors());
}
}
diff --git a/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
index 05af294..1c13517 100644
--- a/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
+++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
@@ -238,8 +238,10 @@ class LocaleImportFunctionalTest extends WebTestBase {
'langcode' => 'hr',
));
- $this->assertIdentical(t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', 'Long month name context is working.');
- $this->assertIdentical(t('May', array(), array('langcode' => 'hr')), 'Svi.', 'Default context is working.');
+ // We cast the return value of t() to string so as to retrieve the
+ // translated value, rendered as a string.
+ $this->assertIdentical((string) t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', 'Long month name context is working.');
+ $this->assertIdentical((string) t('May', array(), array('langcode' => 'hr')), 'Svi.', 'Default context is working.');
}
/**
@@ -254,7 +256,7 @@ class LocaleImportFunctionalTest extends WebTestBase {
));
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
- $this->assertIdentical(t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', 'String imported and translated.');
+ $this->assertIdentical((string) t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', 'String imported and translated.');
// Try importing a .po file.
$this->importPoFile($this->getPoFileWithEmptyMsgstr(), array(
diff --git a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php
index 59caa80..d3a5574 100644
--- a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php
+++ b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php
@@ -69,7 +69,7 @@ class MigrateDependenciesTest extends MigrateDrupal6TestBase {
$executable = new MigrateExecutable($migration, $this);
$this->startCollectingMessages();
$executable->import();
- $this->assertIdentical($this->migrateMessages['error'], array(SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', array('@id' => $migration->id()))));
+ $this->assertEqual($this->migrateMessages['error'], array(SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', array('@id' => $migration->id()))));
$this->collectMessages = FALSE;
}
diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeBuilderTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeBuilderTest.php
index 4a5483a..dc95d66 100644
--- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeBuilderTest.php
+++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeBuilderTest.php
@@ -34,8 +34,8 @@ class MigrateNodeBuilderTest extends MigrateDrupal6TestBase {
protected function assertEntity($id, $label) {
$migration = $this->builtMigrations[$id];
$this->assertTrue($migration instanceof Migration);
- $this->assertIdentical($id, $migration->Id());
- $this->assertIdentical($label, $migration->label());
+ $this->assertIdentical($id, $migration->id());
+ $this->assertEqual($label, $migration->label());
}
/**
diff --git a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php
index bc3c5f9..47efc0f 100644
--- a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php
+++ b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php
@@ -73,7 +73,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
// Test the contents of each th cell.
$expected_items = array(t('Name'), t('Weight'), t('Operations'));
foreach ($elements as $key => $element) {
- $this->assertIdentical((string) $element[0], $expected_items[$key]);
+ $this->assertEqual((string) $element[0], $expected_items[$key]);
}
// Look for test shortcuts in the table.
diff --git a/core/modules/simpletest/src/AssertHelperTrait.php b/core/modules/simpletest/src/AssertHelperTrait.php
new file mode 100644
index 0000000..102b9d9
--- /dev/null
+++ b/core/modules/simpletest/src/AssertHelperTrait.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\simpletest\AssertHelperTrait.
+ */
+
+namespace Drupal\simpletest;
+
+use Drupal\Component\Utility\SafeStringInterface;
+
+/**
+ * Provides helper methods for assertions.
+ */
+trait AssertHelperTrait {
+
+ /**
+ * Casts SafeStringInterface objects into strings.
+ *
+ * @param string|array $value
+ * The value to act on.
+ *
+ * @return mixed
+ * The input value, with SafeStringInterface objects casted to string.
+ */
+ protected function castSafeStrings($value) {
+ if ($value instanceof SafeStringInterface) {
+ $value = (string) $value;
+ }
+ if (is_array($value)) {
+ array_walk_recursive($value, function (&$item) {
+ if ($item instanceof SafeStringInterface) {
+ $item = (string) $item;
+ }
+ });
+ }
+ return $value;
+ }
+
+}
diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php
index 62e4c9f..ddb02e9 100644
--- a/core/modules/simpletest/src/TestBase.php
+++ b/core/modules/simpletest/src/TestBase.php
@@ -30,6 +30,7 @@ abstract class TestBase {
use SessionTestTrait;
use RandomGeneratorTrait;
+ use AssertHelperTrait;
/**
* The test run ID.
@@ -658,10 +659,11 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertEqual($first, $second, $message = '', $group = 'Other') {
- // We cast objects implementing SafeStringInterface to string ourself so as
- // to not rely on PHP casting them to string depending on what we're
+ // Cast objects implementing SafeStringInterface to string instead of
+ // relying on PHP casting them to string depending on what they are being
// comparing with.
- $this->castSafeStrings($first, $second);
+ $first = $this->castSafeStrings($first);
+ $second = $this->castSafeStrings($second);
return $this->assert($first == $second, $message ? $message : SafeMarkup::format('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
}
@@ -691,40 +693,6 @@ abstract class TestBase {
}
/**
- * Casts SafeStringInterface objects into string in 2 compared values.
- *
- * @param string|array &$first
- * The first value to act on.
- * @param string|array &$second
- * The second value to act on (optional).
- *
- * @return mixed
- * The input values, with SafeStringInterface objects casted to string.
- */
- protected function castSafeStrings(&$first, &$second = NULL) {
- if ($first instanceof SafeStringInterface) {
- $first = (string) $first;
- }
- if ($second instanceof SafeStringInterface) {
- $second = (string) $second;
- }
- if (is_array($first)) {
- array_walk_recursive($first, function (&$first) {
- if ($first instanceof SafeStringInterface) {
- $first = (string) $first;
- }
- });
- }
- if (is_array($second)) {
- array_walk_recursive($second, function (&$second) {
- if ($second instanceof SafeStringInterface) {
- $second = (string) $second;
- }
- });
- }
- }
-
- /**
* Check to see if two values are identical.
*
* @param $first
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index fcdb00a..c890beb 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -1697,7 +1697,7 @@ abstract class WebTestBase extends TestBase {
$submit = (string) $submit;
}
if (is_array($edit)) {
- array_walk_recursive($edit, [$this, 'castSafeStrings']);
+ $edit = $this->castSafeStrings($edit);
}
$submit_matches = FALSE;
diff --git a/core/modules/simpletest/tests/src/Unit/AssertHelperTraitTest.php b/core/modules/simpletest/tests/src/Unit/AssertHelperTraitTest.php
new file mode 100644
index 0000000..172474e
--- /dev/null
+++ b/core/modules/simpletest/tests/src/Unit/AssertHelperTraitTest.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\simpletest\Unit\AssertHelperTraitTest.
+ */
+
+namespace Drupal\Tests\simpletest\Unit;
+
+use Drupal\Core\Render\SafeString;
+use Drupal\simpletest\AssertHelperTrait;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\simpletest\AssertHelperTrait
+ * @group simpletest
+ */
+class AssertHelperTraitTest extends UnitTestCase {
+
+ /**
+ * @covers ::castSafeStrings
+ * @dataProvider providerCastSafeStrings
+ */
+ public function testCastSafeStrings($expected, $value) {
+ $class = new AssertHelperTestClass();
+ $this->assertSame($expected, $class->testMethod($value));
+ }
+
+ public function providerCastSafeStrings() {
+ $safe_string = SafeString::create('test safe string');
+ return [
+ ['test simple string', 'test simple string'],
+ [['test simple array', 'test simple array'], ['test simple array', 'test simple array']],
+ ['test safe string', $safe_string],
+ [['test safe string', 'test safe string'], [$safe_string, $safe_string]],
+ [['test safe string', 'mixed array', 'test safe string'], [$safe_string, 'mixed array', $safe_string]],
+ ];
+ }
+}
+
+class AssertHelperTestClass {
+ use AssertHelperTrait;
+
+ public function testMethod($value) {
+ return $this->castSafeStrings($value);
+ }
+}
diff --git a/core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php b/core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php
index 1010b03..af9ccbc 100644
--- a/core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php
@@ -107,7 +107,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel())),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); //, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); //, 'EntityDefinitionUpdateManager reports the expected change summary.');
// Run the update and ensure the revision table is created.
$this->entityDefinitionUpdateManager->applyUpdates();
@@ -146,7 +146,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Create the %field_name field.', array('%field_name' => t('A new base field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Column created in shared table for new_base_field.');
@@ -159,7 +159,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %field_name field.', array('%field_name' => t('A new base field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index created.');
@@ -172,7 +172,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %field_name field.', array('%field_name' => t('A new base field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index deleted.');
@@ -186,7 +186,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %field_name field.', array('%field_name' => t('A new base field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Original column deleted in shared table for new_base_field.');
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field__value'), 'Value column created in shared table for new_base_field.');
@@ -201,7 +201,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Delete the %field_name field.', array('%field_name' => t('A new base field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_value'), 'Value column deleted from shared table for new_base_field.');
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_format'), 'Format column deleted from shared table for new_base_field.');
@@ -220,7 +220,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Create the %field_name field.', array('%field_name' => t('A new bundle field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertTrue($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table created for new_bundle_field.');
@@ -234,7 +234,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %field_name field.', array('%field_name' => t('A new bundle field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update__new_bundle_field', 'new_bundle_field_format'), 'Format column created in dedicated table for new_base_field.');
@@ -247,7 +247,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Delete the %field_name field.', array('%field_name' => t('A new bundle field'))),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager->applyUpdates();
$this->assertFalse($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table deleted for new_bundle_field.');
}
@@ -489,7 +489,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel())),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
// Run the update and ensure the new index is created.
$this->entityDefinitionUpdateManager->applyUpdates();
@@ -504,7 +504,7 @@ class EntityDefinitionUpdateTest extends EntityUnitTestBase {
t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel())),
),
);
- $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
// Run the update and ensure the index is deleted.
$this->entityDefinitionUpdateManager->applyUpdates();
diff --git a/core/modules/system/src/Tests/Form/ValidationTest.php b/core/modules/system/src/Tests/Form/ValidationTest.php
index 693d0af..74e9583 100644
--- a/core/modules/system/src/Tests/Form/ValidationTest.php
+++ b/core/modules/system/src/Tests/Form/ValidationTest.php
@@ -293,7 +293,7 @@ class ValidationTest extends WebTestBase {
$this->fail(format_string('The error message for the "@title" element with key "@key" was not found.', ['@title' => $message['title'], '@key' => $message['key']]));
}
else {
- $this->assertIdentical($message['message'], (string) $element[$delta]);
+ $this->assertEqual($message['message'], (string) $element[$delta]);
}
// Gather the element for checking the jump link section.
diff --git a/core/modules/system/src/Tests/Plugin/InspectionTest.php b/core/modules/system/src/Tests/Plugin/InspectionTest.php
index 814a174..69f0a7e 100644
--- a/core/modules/system/src/Tests/Plugin/InspectionTest.php
+++ b/core/modules/system/src/Tests/Plugin/InspectionTest.php
@@ -31,8 +31,8 @@ class InspectionTest extends PluginTestBase {
$plugin = $this->mockBlockManager->createInstance($id);
$expected_definition = $this->mockBlockExpectedDefinitions[$id];
$this->assertIdentical($plugin->getPluginId(), $id);
- $this->assertIdentical($this->mockBlockManager->getDefinition($id), $expected_definition);
- $this->assertIdentical($plugin->getPluginDefinition(), $expected_definition);
+ $this->assertIdentical($this->castSafeStrings($this->mockBlockManager->getDefinition($id)), $expected_definition);
+ $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);
}
// Test a plugin manager that provides defaults.
foreach (array('test_block1', 'test_block2') as $id) {
@@ -40,7 +40,7 @@ class InspectionTest extends PluginTestBase {
$expected_definition = $this->defaultsTestPluginExpectedDefinitions[$id];
$this->assertIdentical($plugin->getPluginId(), $id);
$this->assertIdentical($this->defaultsTestPluginManager->getDefinition($id), $expected_definition);
- $this->assertIdentical($plugin->getPluginDefinition(), $expected_definition);
+ $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);
}
}
diff --git a/core/modules/views/src/Tests/ModuleTest.php b/core/modules/views/src/Tests/ModuleTest.php
index 7d5a31b..dca3eed 100644
--- a/core/modules/views/src/Tests/ModuleTest.php
+++ b/core/modules/views/src/Tests/ModuleTest.php
@@ -178,14 +178,14 @@ class ModuleTest extends ViewKernelTestBase {
foreach ($all_views as $id => $view) {
$expected_options[$id] = $view->label();
}
- $this->assertIdentical($expected_options, Views::getViewsAsOptions(TRUE), 'Expected options array was returned.');
+ $this->assertIdentical($expected_options, $this->castSafeStrings(Views::getViewsAsOptions(TRUE)), 'Expected options array was returned.');
// Test the default.
- $this->assertIdentical($this->formatViewOptions($all_views), Views::getViewsAsOptions(), 'Expected options array for all views was returned.');
+ $this->assertIdentical($this->formatViewOptions($all_views), $this->castSafeStrings(Views::getViewsAsOptions()), 'Expected options array for all views was returned.');
// Test enabled views.
- $this->assertIdentical($this->formatViewOptions($expected_enabled), Views::getViewsAsOptions(FALSE, 'enabled'), 'Expected enabled options array was returned.');
+ $this->assertIdentical($this->formatViewOptions($expected_enabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'enabled')), 'Expected enabled options array was returned.');
// Test disabled views.
- $this->assertIdentical($this->formatViewOptions($expected_disabled), Views::getViewsAsOptions(FALSE, 'disabled'), 'Expected disabled options array was returned.');
+ $this->assertIdentical($this->formatViewOptions($expected_disabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'disabled')), 'Expected disabled options array was returned.');
// Test the sort parameter.
$all_views_sorted = $all_views;
@@ -201,10 +201,10 @@ class ModuleTest extends ViewKernelTestBase {
$expected_opt_groups = array();
foreach ($all_views as $view) {
foreach ($view->get('display') as $display) {
- $expected_opt_groups[$view->id()][$view->id() . ':' . $display['id']] = t('@view : @display', array('@view' => $view->id(), '@display' => $display['id']));
+ $expected_opt_groups[$view->id()][$view->id() . ':' . $display['id']] = (string) t('@view : @display', array('@view' => $view->id(), '@display' => $display['id']));
}
}
- $this->assertIdentical($expected_opt_groups, Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
+ $this->assertIdentical($expected_opt_groups, $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE)), 'Expected option array for an option group returned.');
}
/**
@@ -347,7 +347,7 @@ class ModuleTest extends ViewKernelTestBase {
$expected_options = array();
foreach ($views as $view) {
foreach ($view->get('display') as $display) {
- $expected_options[$view->id() . ':' . $display['id']] = t('View: @view - Display: @display',
+ $expected_options[$view->id() . ':' . $display['id']] = (string) t('View: @view - Display: @display',
array('@view' => $view->id(), '@display' => $display['id']));
}
}
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index 74a885e..646731d 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -20,6 +20,7 @@ use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Site\Settings;
use Drupal\simpletest\AssertContentTrait;
+use Drupal\simpletest\AssertHelperTrait;
use Drupal\simpletest\RandomGeneratorTrait;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
@@ -52,6 +53,7 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
use AssertLegacyTrait;
use AssertContentTrait;
+ use AssertHelperTrait;
use RandomGeneratorTrait;
/**