Issue #3123120 by mondrake, ridhimaabrol24, longwave: Properly deprecate AssertLegacyTrait::pass

merge-requests/2/head
catch 2020-07-14 10:58:42 +01:00
parent 33c16bf2a2
commit b7627bcae4
87 changed files with 307 additions and 594 deletions

View File

@ -186,7 +186,7 @@ class BigPipeTest extends BrowserTestBase {
$this->assertRaw('</body>', 'Closing body tag present.');
$this->pass('Verifying BigPipe assets are present…', 'Debug');
// Verifying BigPipe assets are present.
$this->assertFalse(empty($this->getDrupalSettings()), 'drupalSettings present.');
$this->assertContains('big_pipe/big_pipe', explode(',', $this->getDrupalSettings()['ajaxPageState']['libraries']), 'BigPipe asset library is present.');
@ -205,7 +205,8 @@ class BigPipeTest extends BrowserTestBase {
$this->drupalGet(Url::fromUri('base:non-existing-path'));
// Simulate development.
$this->pass('Verifying BigPipe provides useful error output when an error occurs while rendering a placeholder if verbose error logging is enabled.', 'Debug');
// Verifying BigPipe provides useful error output when an error occurs
// while rendering a placeholder if verbose error logging is enabled.
$this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save();
$this->drupalGet(Url::fromRoute('big_pipe_test'));
// The 'edge_case__html_exception' case throws an exception.
@ -259,13 +260,13 @@ class BigPipeTest extends BrowserTestBase {
$cases['exception__embedded_response']->bigPipePlaceholderId => NULL,
]);
$this->pass('Verifying there are no BigPipe placeholders & replacements…', 'Debug');
// Verifying there are no BigPipe placeholders & replacements.
$this->assertEqual('<none>', $this->drupalGetHeader('BigPipe-Test-Placeholders'));
$this->pass('Verifying BigPipe start/stop signals are absent…', 'Debug');
// Verifying BigPipe start/stop signals are absent.
$this->assertNoRaw(BigPipe::START_SIGNAL, 'BigPipe start signal absent.');
$this->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent.');
$this->pass('Verifying BigPipe assets are absent…', 'Debug');
// Verifying BigPipe assets are absent.
$this->assertTrue(!isset($this->getDrupalSettings()['bigPipePlaceholderIds']) && empty($this->getDrupalSettings()['ajaxPageState']), 'BigPipe drupalSettings and BigPipe asset library absent.');
$this->assertRaw('</body>', 'Closing body tag present.');
@ -274,7 +275,8 @@ class BigPipeTest extends BrowserTestBase {
$this->drupalGet(Url::fromUri('base:non-existing-path'));
// Simulate development.
$this->pass('Verifying BigPipe provides useful error output when an error occurs while rendering a placeholder if verbose error logging is enabled.', 'Debug');
// Verifying BigPipe provides useful error output when an error occurs
// while rendering a placeholder if verbose error logging is enabled.
$this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save();
$this->drupalGet(Url::fromRoute('big_pipe_test'));
// The 'edge_case__html_exception' case throws an exception.
@ -322,7 +324,6 @@ class BigPipeTest extends BrowserTestBase {
}
protected function assertBigPipeResponseHeadersPresent() {
$this->pass('Verifying BigPipe response headers…', 'Debug');
// Check that Cache-Control header set to "private".
$this->assertSession()->responseHeaderContains('Cache-Control', 'private');
$this->assertEqual('no-store, content="BigPipe/1.0"', $this->drupalGetHeader('Surrogate-Control'));
@ -337,10 +338,10 @@ class BigPipeTest extends BrowserTestBase {
* markup.
*/
protected function assertBigPipeNoJsPlaceholders(array $expected_big_pipe_nojs_placeholders) {
$this->pass('Verifying BigPipe no-JS placeholders & replacements…', 'Debug');
$this->assertSetsEqual(array_keys($expected_big_pipe_nojs_placeholders), array_map('rawurldecode', explode(' ', $this->drupalGetHeader('BigPipe-Test-No-Js-Placeholders'))));
foreach ($expected_big_pipe_nojs_placeholders as $big_pipe_nojs_placeholder => $expected_replacement) {
$this->pass('Checking whether the replacement for the BigPipe no-JS placeholder "' . $big_pipe_nojs_placeholder . '" is present:');
// Checking whether the replacement for the BigPipe no-JS placeholder
// $big_pipe_nojs_placeholder is present.
$this->assertNoRaw($big_pipe_nojs_placeholder);
if ($expected_replacement !== NULL) {
$this->assertRaw($expected_replacement);
@ -358,12 +359,10 @@ class BigPipeTest extends BrowserTestBase {
* defined in the order that they are expected to be rendered & streamed.
*/
protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholders, array $expected_big_pipe_placeholder_stream_order) {
$this->pass('Verifying BigPipe placeholders & replacements…', 'Debug');
$this->assertSetsEqual(array_keys($expected_big_pipe_placeholders), explode(' ', $this->drupalGetHeader('BigPipe-Test-Placeholders')));
$placeholder_positions = [];
$placeholder_replacement_positions = [];
foreach ($expected_big_pipe_placeholders as $big_pipe_placeholder_id => $expected_ajax_response) {
$this->pass('BigPipe placeholder: ' . $big_pipe_placeholder_id, 'Debug');
// Verify expected placeholder.
$expected_placeholder_html = '<span data-big-pipe-placeholder-id="' . $big_pipe_placeholder_id . '"></span>';
$this->assertRaw($expected_placeholder_html, 'BigPipe placeholder for placeholder ID "' . $big_pipe_placeholder_id . '" found.');
@ -396,14 +395,15 @@ class BigPipeTest extends BrowserTestBase {
$this->assertSetsEqual(array_keys($expected_big_pipe_placeholders_with_replacements), array_values($placeholder_replacement_positions));
$this->assertSame(count($expected_big_pipe_placeholders_with_replacements), preg_match_all('/' . preg_quote('<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="', '/') . '/', $this->getSession()->getPage()->getContent()));
$this->pass('Verifying BigPipe start/stop signals…', 'Debug');
// Verifying BigPipe start/stop signals.
$this->assertRaw(BigPipe::START_SIGNAL, 'BigPipe start signal present.');
$this->assertRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal present.');
$start_signal_position = strpos($this->getSession()->getPage()->getContent(), BigPipe::START_SIGNAL);
$stop_signal_position = strpos($this->getSession()->getPage()->getContent(), BigPipe::STOP_SIGNAL);
$this->assertTrue($start_signal_position < $stop_signal_position, 'BigPipe start signal appears before stop signal.');
$this->pass('Verifying BigPipe placeholder replacements and start/stop signals were streamed in the correct order…', 'Debug');
// Verifying BigPipe placeholder replacements and start/stop signals were
// streamed in the correct order.
$expected_stream_order = array_keys($expected_big_pipe_placeholders_with_replacements);
array_unshift($expected_stream_order, BigPipe::START_SIGNAL);
array_push($expected_stream_order, BigPipe::STOP_SIGNAL);

View File

@ -292,7 +292,6 @@ class BlockViewBuilderTest extends KernelTestBase {
// Check that the expected cacheability metadata is present in:
// - the built render array;
$this->pass('Built render array');
$build = $this->getBlockRenderArray();
$this->assertIdentical($expected_keys, $build['#cache']['keys']);
$this->assertIdentical($expected_contexts, $build['#cache']['contexts']);
@ -300,10 +299,8 @@ class BlockViewBuilderTest extends KernelTestBase {
$this->assertIdentical($expected_max_age, $build['#cache']['max-age']);
$this->assertFalse(isset($build['#create_placeholder']));
// - the rendered render array;
$this->pass('Rendered render array');
$this->renderer->renderRoot($build);
// - the render cache item.
$this->pass('Render cache item');
$final_cache_contexts = Cache::mergeContexts($expected_contexts, $required_cache_contexts);
$cid = implode(':', $expected_keys) . ':' . implode(':', \Drupal::service('cache_contexts_manager')->convertTokensToKeys($final_cache_contexts)->getKeys());
$cache_item = $this->container->get('cache.render')->get($cid);

View File

@ -206,7 +206,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->fail('Expected exception has not been thrown.');
}
catch (\Exception $e) {
$this->pass('Expected exception has been thrown.');
// Expected exception; just continue testing.
}
$connection = Database::getConnection();

View File

@ -118,12 +118,10 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
$entity->addTranslation('it', $values);
try {
$message = 'Blocks can have translations with the same "info" value.';
$entity->save();
$this->pass($message);
}
catch (\Exception $e) {
$this->fail($message);
$this->fail('Blocks can have translations with the same "info" value.');
}
// Check that the translate operation link is shown.

View File

@ -33,15 +33,10 @@ class MigrateBlockContentStubTest extends MigrateDrupalTestBase {
* Tests creation of block content stubs with no block_content_type available.
*/
public function testStubFailure() {
$message = 'Expected MigrateException thrown when no bundles exist.';
try {
$this->createEntityStub('block_content');
$this->fail($message);
}
catch (MigrateException $e) {
$this->pass($message);
$this->assertEqual('Stubbing failed, no bundles available for entity type: block_content', $e->getMessage());
}
// Expected MigrateException thrown when no bundles exist.
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('Stubbing failed, no bundles available for entity type: block_content');
$this->createEntityStub('block_content');
}
/**

View File

@ -429,7 +429,6 @@ class CommentPagerTest extends CommentTestBase {
$urls = $this->xpath($xpath, $arguments);
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]->getAttribute('href'));
$this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $xpath, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
return $this->drupalGet($url_target);
}
$this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $xpath, '@url_before' => $url_before]), 'Browser');

View File

@ -186,7 +186,7 @@ class CommentTypeTest extends CommentTestBase {
$this->fail('Exception not thrown.');
}
catch (\InvalidArgumentException $e) {
$this->pass('Exception thrown if attempting to re-use comment-type from another entity type.');
// Expected exception; just continue testing.
}
// Delete the comment type.

View File

@ -40,28 +40,23 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
* Tests that comment fields cannot be added entities with non-integer IDs.
*/
public function testCommentFieldNonStringId() {
try {
$bundle = CommentType::create([
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
]);
$bundle->save();
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => [
'comment_type' => 'entity_test_string_id',
],
'type' => 'comment',
]);
$field_storage->save();
$this->fail('Did not throw an exception as expected.');
}
catch (\UnexpectedValueException $e) {
$this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
}
$this->expectException(\UnexpectedValueException::class);
$bundle = CommentType::create([
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
]);
$bundle->save();
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => [
'comment_type' => 'entity_test_string_id',
],
'type' => 'comment',
]);
$field_storage->save();
}
}

View File

@ -69,7 +69,7 @@ class ConfigEntityTest extends BrowserTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify that an empty entity cannot be saved.
@ -78,7 +78,7 @@ class ConfigEntityTest extends BrowserTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify that an entity with an empty ID string is considered empty, too.
@ -91,7 +91,7 @@ class ConfigEntityTest extends BrowserTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify properties on a newly created entity.
@ -116,7 +116,6 @@ class ConfigEntityTest extends BrowserTestBase {
// Verify that the entity can be saved.
try {
$status = $config_test->save();
$this->pass('EntityMalformedException was not thrown.');
}
catch (EntityMalformedException $e) {
$this->fail('EntityMalformedException was not thrown.');
@ -151,9 +150,6 @@ class ConfigEntityTest extends BrowserTestBase {
]);
try {
$id_length_config_test->save();
$this->pass(new FormattableMarkup("config_test entity with ID length @length was saved.", [
'@length' => strlen($id_length_config_test->id()),
]));
}
catch (ConfigEntityIdLengthException $e) {
$this->fail($e->getMessage());
@ -165,9 +161,6 @@ class ConfigEntityTest extends BrowserTestBase {
]);
try {
$id_length_config_test->save();
$this->pass(new FormattableMarkup("config_test entity with ID length @length was saved.", [
'@length' => strlen($id_length_config_test->id()),
]));
}
catch (ConfigEntityIdLengthException $e) {
$this->fail($e->getMessage());
@ -185,10 +178,7 @@ class ConfigEntityTest extends BrowserTestBase {
]));
}
catch (ConfigEntityIdLengthException $e) {
$this->pass(new FormattableMarkup("config_test entity with ID length @length exceeding the maximum allowed length of @max failed to save", [
'@length' => strlen($id_length_config_test->id()),
'@max' => static::MAX_ID_LENGTH,
]));
// Expected exception; just continue testing.
}
// Ensure that creating an entity with the same id as an existing one is not
@ -202,7 +192,7 @@ class ConfigEntityTest extends BrowserTestBase {
$this->fail('Not possible to overwrite an entity entity.');
}
catch (EntityStorageException $e) {
$this->pass('Not possible to overwrite an entity entity.');
// Expected exception; just continue testing.
}
// Verify that renaming the ID returns correct status and properties.

View File

@ -29,38 +29,32 @@ class SchemaConfigListenerWebTest extends BrowserTestBase {
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
// Test a non-existing schema.
$msg = 'Expected SchemaIncompleteException thrown';
try {
$this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
$this->fail($msg);
$this->fail('Expected SchemaIncompleteException thrown');
}
catch (SchemaIncompleteException $e) {
$this->pass($msg);
$this->assertEquals('No schema for config_schema_test.schemaless', $e->getMessage());
}
// Test a valid schema.
$msg = 'Unexpected SchemaIncompleteException thrown';
$config = $this->config('config_test.types')->set('int', 10);
try {
$config->save();
$this->pass($msg);
}
catch (SchemaIncompleteException $e) {
$this->fail($msg);
$this->fail('Unexpected SchemaIncompleteException thrown');
}
// Test an invalid schema.
$msg = 'Expected SchemaIncompleteException thrown';
$config = $this->config('config_test.types')
->set('foo', 'bar')
->set('array', 1);
try {
$config->save();
$this->fail($msg);
$this->fail('Expected SchemaIncompleteException thrown');
}
catch (SchemaIncompleteException $e) {
$this->pass($msg);
$this->assertEquals('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema', $e->getMessage());
}

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\editor\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Serialization\Json;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
@ -282,10 +281,6 @@ class EditorSecurityTest extends BrowserTestBase {
// Log in as each user that may edit the content, and assert the value.
foreach ($expected as $case) {
foreach ($case['users'] as $account) {
$this->pass(new FormattableMarkup('Scenario: sample %sample_id, %format.', [
'%sample_id' => $case['node_id'],
'%format' => $case['format'],
]));
$this->drupalLogin($account);
$this->drupalGet('node/' . $case['node_id'] . '/edit');
$dom_node = $this->xpath('//textarea[@id="edit-body-0-value"]');
@ -407,12 +402,6 @@ class EditorSecurityTest extends BrowserTestBase {
// Switch to every other text format/editor and verify the results.
foreach ($case['switch_to'] as $format => $expected_filtered_value) {
$this->pass(new FormattableMarkup('Scenario: sample %sample_id, switch from %original_format to %format.', [
'%sample_id' => $case['node_id'],
'%original_format' => $case['format'],
'%format' => $format,
]));
$post = [
'value' => self::$sampleContent,
'original_format_id' => $case['format'],

View File

@ -71,44 +71,44 @@ class EditorFileReferenceFilterTest extends KernelTestBase {
$uuid_2 = $image_2->uuid();
$cache_tag_2 = ['file:' . $id_2];
$this->pass('No data-entity-type and no data-entity-uuid attribute.');
// No data-entity-type and no data-entity-uuid attribute.
$input = '<img src="llama.jpg" />';
$output = $test($input);
$this->assertIdentical($input, $output->getProcessedText());
$this->pass('A non-file data-entity-type attribute value.');
// A non-file data-entity-type attribute value.
$input = '<img src="llama.jpg" data-entity-type="invalid-entity-type-value" data-entity-uuid="' . $uuid . '" />';
$output = $test($input);
$this->assertIdentical($input, $output->getProcessedText());
$this->pass('One data-entity-uuid attribute.');
// One data-entity-uuid attribute.
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$expected_output = '<img src="/' . $this->siteDirectory . '/files/llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$output = $test($input);
$this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute with odd capitalization.');
// One data-entity-uuid attribute with odd capitalization.
$input = '<img src="llama.jpg" data-entity-type="file" DATA-entity-UUID = "' . $uuid . '" />';
$expected_output = '<img src="/' . $this->siteDirectory . '/files/llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$output = $test($input);
$this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute on a non-image tag.');
// One data-entity-uuid attribute on a non-image tag.
$input = '<video src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$expected_output = '<video src="/' . $this->siteDirectory . '/files/llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '"></video>';
$output = $test($input);
$this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute with an invalid value.');
// One data-entity-uuid attribute with an invalid value.
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="invalid-' . $uuid . '" />';
$output = $test($input);
$this->assertIdentical($input, $output->getProcessedText());
$this->assertEqual([], $output->getCacheTags());
$this->pass('Two different data-entity-uuid attributes.');
// Two different data-entity-uuid attributes.
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$input .= '<img src="alpaca.jpg" data-entity-type="file" data-entity-uuid="' . $uuid_2 . '" />';
$expected_output = '<img src="/' . $this->siteDirectory . '/files/llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
@ -117,7 +117,7 @@ class EditorFileReferenceFilterTest extends KernelTestBase {
$this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual(Cache::mergeTags($cache_tag, $cache_tag_2), $output->getCacheTags());
$this->pass('Two identical data-entity-uuid attributes.');
// Two identical data-entity-uuid attributes.
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$input .= '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
$expected_output = '<img src="/' . $this->siteDirectory . '/files/llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';

View File

@ -90,15 +90,10 @@ class SqlContentEntityStorageSchemaColumnTest extends KernelTestBase {
// Now attempt to run automatic updates. An exception should be thrown
// since there is data in the table.
try {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('test', 'entity_test_rev');
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
$this->fail('Failed to detect a schema change in a field with data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('Detected a schema change in a field with data.');
}
$this->expectException(FieldStorageDefinitionUpdateForbiddenException::class);
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('test', 'entity_test_rev');
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}
}

View File

@ -187,8 +187,8 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
$entity->field_test_taxonomy_term = ['target_id' => 'invalid', 'entity' => $term2];
$this->fail('Assigning an invalid item throws an exception.');
}
catch (\InvalidArgumentException $e) {
$this->pass('Assigning an invalid item throws an exception.');
catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
// Delete terms so we have nothing to reference and try again

View File

@ -103,7 +103,7 @@ class FieldCrudTest extends FieldKernelTestBase {
$this->fail('Cannot create two fields with the same field / bundle combination.');
}
catch (EntityStorageException $e) {
$this->pass('Cannot create two fields with the same field / bundle combination.');
// Expected exception; just continue testing.
}
// Check that the specified field exists.
@ -113,7 +113,7 @@ class FieldCrudTest extends FieldKernelTestBase {
$this->fail('Cannot create a field with a non-existing storage.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field with a non-existing storage.');
// Expected exception; just continue testing.
}
// TODO: test other failures.

View File

@ -65,46 +65,25 @@ class FieldDefinitionIntegrityTest extends KernelTestBase {
foreach ($field_type_manager->getDefinitions() as $definition) {
// Test default field widgets.
if (isset($definition['default_widget'])) {
if (in_array($definition['default_widget'], $available_field_widget_ids)) {
$this->pass(sprintf('Field type %s uses an existing field widget by default.', $definition['id']));
}
else {
$this->fail(sprintf('Field type %s uses a non-existent field widget by default: %s', $definition['id'], $definition['default_widget']));
}
$this->assertContains($definition['default_widget'], $available_field_widget_ids, sprintf('Field type %s uses a non-existent field widget by default: %s', $definition['id'], $definition['default_widget']));
}
// Test default field formatters.
if (isset($definition['default_formatter'])) {
if (in_array($definition['default_formatter'], $available_field_formatter_ids)) {
$this->pass(sprintf('Field type %s uses an existing field formatter by default.', $definition['id']));
}
else {
$this->fail(sprintf('Field type %s uses a non-existent field formatter by default: %s', $definition['id'], $definition['default_formatter']));
}
$this->assertContains($definition['default_formatter'], $available_field_formatter_ids, sprintf('Field type %s uses a non-existent field formatter by default: %s', $definition['id'], $definition['default_formatter']));
}
}
// Test the field widget plugins.
foreach ($field_widget_manager->getDefinitions() as $definition) {
$missing_field_type_ids = array_diff($definition['field_types'], $available_field_type_ids);
if ($missing_field_type_ids) {
$this->fail(sprintf('Field widget %s integrates with non-existent field types: %s', $definition['id'], implode(', ', $missing_field_type_ids)));
}
else {
$this->pass(sprintf('Field widget %s integrates with existing field types.', $definition['id']));
}
$this->assertEmpty($missing_field_type_ids, sprintf('Field widget %s integrates with non-existent field types: %s', $definition['id'], implode(', ', $missing_field_type_ids)));
}
// Test the field formatter plugins.
foreach ($field_formatter_manager->getDefinitions() as $definition) {
$missing_field_type_ids = array_diff($definition['field_types'], $available_field_type_ids);
if ($missing_field_type_ids) {
$this->fail(sprintf('Field formatter %s integrates with non-existent field types: %s', $definition['id'], implode(', ', $missing_field_type_ids)));
}
else {
$this->pass(sprintf('Field formatter %s integrates with existing field types.', $definition['id']));
}
$this->assertEmpty($missing_field_type_ids, sprintf('Field formatter %s integrates with non-existent field types: %s', $definition['id'], implode(', ', $missing_field_type_ids)));
}
}

View File

@ -80,8 +80,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create two fields with the same name.');
}
catch (EntityStorageException $e) {
$this->pass('Cannot create two fields with the same name.');
catch (\Exception $e) {
$this->assertInstanceOf(EntityStorageException::class, $e);
}
// Check that field type is required.
@ -93,8 +93,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field with no type.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field with no type.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that field name is required.
@ -106,8 +106,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create an unnamed field.');
}
catch (FieldException $e) {
$this->pass('Cannot create an unnamed field.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that entity type is required.
try {
@ -118,8 +118,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field without an entity type.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field without an entity type.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that field name must start with a letter or _.
@ -132,8 +132,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field with a name starting with a digit.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field with a name starting with a digit.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that field name must only contain lowercase alphanumeric or _.
@ -146,8 +146,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field with a name containing an illegal character.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field with a name containing an illegal character.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that field name cannot be longer than 32 characters long.
@ -160,8 +160,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field with a name longer than 32 characters.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field with a name longer than 32 characters.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
// Check that field name can not be an entity key.
@ -175,8 +175,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldStorageConfig::create($field_storage_definition)->save();
$this->fail('Cannot create a field bearing the name of an entity key.');
}
catch (FieldException $e) {
$this->pass('Cannot create a field bearing the name of an entity key.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
}
@ -380,8 +380,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
$field_storage->save();
$this->fail('Cannot update a field to a different type.');
}
catch (FieldException $e) {
$this->pass('Cannot update a field to a different type.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldException::class, $e);
}
}
@ -480,7 +480,6 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
$field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1);
try {
$field_storage->save();
$this->pass('A changeable setting can be updated.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->fail('An unchangeable setting cannot be updated.');
@ -490,8 +489,8 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
$field_storage->save();
$this->fail('An unchangeable setting can be updated.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('An unchangeable setting cannot be updated.');
catch (\Exception $e) {
$this->assertInstanceOf(FieldStorageDefinitionUpdateForbiddenException::class, $e);
}
}

View File

@ -207,10 +207,6 @@ class FilterFormTest extends BrowserTestBase {
foreach ($found_options as $found_key => $found_option) {
$expected_key = array_search($found_option->getValue(), $expected_options);
if ($expected_key !== FALSE) {
$this->pass(new FormattableMarkup('Option @option for field @id exists.', [
'@option' => $expected_options[$expected_key],
'@id' => $id,
]));
unset($found_options[$found_key]);
unset($expected_options[$expected_key]);
}

View File

@ -58,7 +58,7 @@ class DenormalizeTest extends NormalizerTestBase {
$this->fail('Exception should be thrown when type is invalid.');
}
catch (UnexpectedValueException $e) {
$this->pass('Exception thrown when type is invalid.');
// Expected exception; just continue testing.
}
// No type.
@ -70,7 +70,7 @@ class DenormalizeTest extends NormalizerTestBase {
$this->fail('Exception should be thrown when no type is provided.');
}
catch (UnexpectedValueException $e) {
$this->pass('Exception thrown when no type is provided.');
// Expected exception; just continue testing.
}
}

View File

@ -35,15 +35,10 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
->condition('type', 'module')
->execute();
try {
$this->getMigration('d6_imagecache_presets')
->getSourcePlugin()
->checkRequirements();
$this->fail('Did not catch expected RequirementsException.');
}
catch (RequirementsException $e) {
$this->pass('Caught expected RequirementsException: ' . $e->getMessage());
}
$this->expectException(RequirementsException::class);
$this->getMigration('d6_imagecache_presets')
->getSourcePlugin()
->checkRequirements();
}
/**
@ -162,7 +157,7 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
if ($effect_config['id'] == $id && $effect_config['data'] == $config) {
// We found this effect so succeed and return.
return $this->pass('Effect ' . $id . ' imported correctly');
return TRUE;
}
}
// The loop did not find the effect so we it was not imported correctly.

View File

@ -48,7 +48,7 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
$this->fail('Expected DeleteDefaultLanguageException thrown.');
}
catch (DeleteDefaultLanguageException $e) {
$this->pass('Expected DeleteDefaultLanguageException thrown.');
// Expected exception; just continue testing.
}
// Re-save the previous default language and the delete should work.

View File

@ -84,9 +84,9 @@ class EditorMediaDialogTest extends KernelTestBase {
]);
$form_state->setRequestMethod('POST');
EditorMediaDialog::create($this->container)
$form = EditorMediaDialog::create($this->container)
->buildForm([], $form_state, $editor->reveal());
$this->pass('Form was built without errors.');
$this->assertNotNull($form, 'Form should have been built without errors.');
}
}

View File

@ -64,7 +64,6 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after modifying the menu, there is a cache miss.
$this->pass('Test modification of menu.', 'Debug');
$menu->set('label', 'Awesome llama');
$menu->save();
$this->verifyPageCache($url, 'MISS');
@ -74,14 +73,12 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
// Verify that after modifying the menu link weight, there is a cache miss.
$menu_link_manager->updateDefinition('test_page_test.test_page', ['weight' => -10]);
$this->pass('Test modification of menu link.', 'Debug');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($url, 'HIT');
// Verify that after adding a menu link, there is a cache miss.
$this->pass('Test addition of menu link.', 'Debug');
$menu_link_2 = MenuLinkContent::create([
'id' => '',
'parent' => '',
@ -99,7 +96,6 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
$this->verifyPageCache($url, 'HIT');
// Verify that after resetting the first menu link, there is a cache miss.
$this->pass('Test reset of menu link.', 'Debug');
$this->assertTrue($menu_link->isResettable(), 'First link can be reset');
$menu_link = $menu_link_manager->resetLink($menu_link->getPluginId());
$this->verifyPageCache($url, 'MISS');
@ -108,7 +104,6 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after deleting the menu, there is a cache miss.
$this->pass('Test deletion of menu.', 'Debug');
$menu->delete();
$this->verifyPageCache($url, 'MISS');

View File

@ -82,7 +82,6 @@ class NodeAccessGrantsCacheContextTest extends NodeTestBase {
if ($uid > 0) {
$this->drupalLogin($this->userMapping[$uid]);
}
$this->pass('Asserting cache context for user ' . $uid . '.');
$this->assertIdentical($context, $this->container->get('cache_context.user.node_grants')->getContext('view'));
}
$this->drupalLogout();

View File

@ -115,7 +115,7 @@ class NodeCreationTest extends NodeTestBase {
$this->fail('Expected exception has not been thrown.');
}
catch (\Exception $e) {
$this->pass('Expected exception has been thrown.');
// Expected exception; just continue testing.
}
// Check that the node does not exist in the database.

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\views\Views;
@ -60,7 +59,6 @@ class BulkFormTest extends NodeTestBase {
'promote' => FALSE,
];
$node = $this->drupalCreateNode($values);
$this->pass(new FormattableMarkup('Node %title created with language %langcode.', ['%title' => $node->label(), '%langcode' => $node->language()->getId()]));
$this->nodes[] = $node;
}
@ -71,7 +69,6 @@ class BulkFormTest extends NodeTestBase {
if (!$node->hasTranslation($langcode)) {
$title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
$translation = $node->addTranslation($langcode, ['title' => $title, 'promote' => FALSE]);
$this->pass(new FormattableMarkup('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
}
}
$node->save();
@ -82,7 +79,6 @@ class BulkFormTest extends NodeTestBase {
$langcode = 'en';
$title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
$translation = $node->addTranslation($langcode, ['title' => $title]);
$this->pass(new FormattableMarkup('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
$node->save();
// Check that all created translations are selected by the test view.

View File

@ -304,7 +304,6 @@ class FrontPageTest extends ViewTestBase {
'timezone',
]);
$this->pass('First page');
// First page.
$first_page_result_cache_tags = [
'config:views.view.frontpage',
@ -344,7 +343,6 @@ class FrontPageTest extends ViewTestBase {
);
// Second page.
$this->pass('Second page');
$this->assertPageCacheContextsAndTags(Url::fromRoute('view.frontpage.page_1', [], ['query' => ['page' => 1]]), $cache_contexts, [
// The cache tags for the listed nodes.
'node:1',

View File

@ -43,7 +43,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
$this->fail('Cannot update a list field storage to not include keys with existing data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('Cannot update a list field storage to not include keys with existing data.');
// Expected exception; just continue testing.
}
// Empty the value, so that we can actually remove the option.
unset($entity->{$this->fieldName});

View File

@ -61,7 +61,7 @@ class GetRdfNamespacesTest extends BrowserTestBase {
$this->fail('Expected exception not thrown for conflicting namespace declaration.');
}
catch (\Exception $e) {
$this->pass('Expected exception thrown: ' . $e->getMessage());
// Expected exception; just continue testing.
}
}

View File

@ -48,7 +48,7 @@ class SerializationTest extends KernelTestBase {
$this->fail('The serializer was expected to throw an exception for an unsupported format, but did not.');
}
catch (UnexpectedValueException $e) {
$this->pass('The serializer threw an exception for an unsupported format.');
// Expected exception; just continue testing.
}
}

View File

@ -71,7 +71,6 @@ class UrlTest extends BrowserTestBase {
'#url' => Url::fromUri($uri),
];
\Drupal::service('renderer')->renderRoot($link);
$this->pass($title);
$this->assertEqual($expected_cacheability, $link['#cache']);
$this->assertEqual($expected_attachments, $link['#attached']);
}

View File

@ -57,15 +57,12 @@ class HtmlToTextTest extends BrowserTestBase {
$tested_tags = implode(', ', array_unique($matches[1]));
$message .= ' (' . $tested_tags . ')';
$result = MailFormatHelper::htmlToText($html, $allowed_tags);
$pass = $this->assertEqual($result, $text, Html::escape($message));
$this->assertEqual($result, $text, Html::escape($message));
$verbose = 'html = <pre>' . $this->stringToHtml($html)
. '</pre><br />result = <pre>' . $this->stringToHtml($result)
. '</pre><br />expected = <pre>' . $this->stringToHtml($text)
. '</pre>';
$this->verbose($verbose);
if (!$pass) {
$this->pass("Previous test verbose info:<br />$verbose");
}
}
/**

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\system\Functional\Menu;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
@ -61,12 +60,7 @@ class LocalTasksTest extends BrowserTestBase {
foreach ($routes as $index => $route_info) {
list($route_name, $route_parameters) = $route_info;
$expected = Url::fromRoute($route_name, $route_parameters)->toString();
$method = ($elements[$index]->getAttribute('href') == $expected ? 'pass' : 'fail');
$this->{$method}(new FormattableMarkup('Task @number href @value equals @expected.', [
'@number' => $index + 1,
'@value' => $elements[$index]->getAttribute('href'),
'@expected' => $expected,
]));
$this->assertEquals($expected, $elements[$index]->getAttribute('href'), "Task " . ($index + 1) . "number href " . $elements[$index]->getAttribute('href') . " equals $expected.");
}
}

View File

@ -82,8 +82,8 @@ class InstallTest extends BrowserTestBase {
$this->container->get('module_installer')->install([$module_name]);
$this->fail($message);
}
catch (ExtensionNameLengthException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ExtensionNameLengthException::class, $e);
}
// Since for the UI, the submit callback uses FALSE, test that too.
@ -92,8 +92,8 @@ class InstallTest extends BrowserTestBase {
$this->container->get('module_installer')->install([$module_name], FALSE);
$this->fail($message);
}
catch (ExtensionNameLengthException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ExtensionNameLengthException::class, $e);
}
}

View File

@ -157,7 +157,7 @@ class UninstallTest extends BrowserTestBase {
$this->fail($message);
}
catch (EntityMalformedException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Even though the module failed to install properly, its configuration

View File

@ -307,7 +307,7 @@ class RouterTest extends BrowserTestBase {
$this->fail('Route was delete on uninstall.');
}
catch (RouteNotFoundException $e) {
$this->pass('Route was delete on uninstall.');
// Expected exception; just continue testing.
}
// Install the module again.
\Drupal::service('module_installer')->install(['router_test']);

View File

@ -161,7 +161,6 @@ class SiteMaintenanceTest extends BrowserTestBase {
\Drupal::state()->set('system.maintenance_mode', TRUE);
$formats = ['json', 'xml', 'non-existing'];
foreach ($formats as $format) {
$this->pass('Testing format ' . $format);
$this->drupalGet('<front>', ['query' => ['_format' => $format]]);
$this->assertSession()->statusCodeEquals(503);
$this->assertRaw('Drupal is currently under maintenance. We should be back shortly. Thank you for your patience.');

View File

@ -59,7 +59,6 @@ class PageRenderTest extends KernelTestBase {
$this->error($assertion);
}
catch (\LogicException $e) {
$this->pass($assertion);
$this->assertEqual($e->getMessage(), 'Only #attached and #cache may be set in ' . $hook . '().');
}
\Drupal::state()->set('bc_test.' . $hook . '.descendant_attached', FALSE);
@ -73,7 +72,6 @@ class PageRenderTest extends KernelTestBase {
$this->error($assertion);
}
catch (\LogicException $e) {
$this->pass($assertion);
$this->assertEqual($e->getMessage(), 'Only #attached and #cache may be set in ' . $hook . '().');
}
\Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);

View File

@ -96,7 +96,7 @@ class ModuleHandlerTest extends KernelTestBase {
$this->fail('ModuleInstaller::install() throws an exception if dependencies are missing.');
}
catch (MissingDependencyException $e) {
$this->pass('ModuleInstaller::install() throws an exception if dependencies are missing.');
// Expected exception; just continue testing.
}
$this->assertFalse($this->moduleHandler()->moduleExists('color'), 'ModuleInstaller::install() aborts if dependencies are missing.');
@ -254,7 +254,7 @@ class ModuleHandlerTest extends KernelTestBase {
$this->fail($message);
}
catch (ModuleUninstallValidatorException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
// Expected exception; just continue testing.
}
// Uninstalling help needs entity_test to be un-installable.
@ -264,7 +264,7 @@ class ModuleHandlerTest extends KernelTestBase {
$this->fail($message);
}
catch (ModuleUninstallValidatorException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
// Expected exception; just continue testing.
}
// Deleting the entity.

View File

@ -131,12 +131,7 @@ class ToolbarCacheContextsTest extends BrowserTestBase {
$this->drupalGet('test-page');
$return = $return && $this->assertCacheContexts($cache_contexts);
if ($return) {
$this->pass($message);
}
else {
$this->fail($message);
}
$this->assertTrue($return, $message);
return $return;
}

View File

@ -59,7 +59,6 @@ class TourCacheTagsTest extends PageCacheTagsTestBase {
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after modifying the tour, there is a cache miss.
$this->pass('Test modification of tour.', 'Debug');
Tour::load('tour-test')->save();
$this->verifyPageCache($url, 'MISS');
@ -67,7 +66,6 @@ class TourCacheTagsTest extends PageCacheTagsTestBase {
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after deleting the tour, there is a cache miss.
$this->pass('Test deletion of tour.', 'Debug');
Tour::load('tour-test')->delete();
$this->verifyPageCache($url, 'MISS');

View File

@ -89,11 +89,9 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
* Whether to check Views' result & output caches.
*/
protected function assertCacheTagsForFieldBasedView($do_assert_views_caches) {
$this->pass('Checking cache tags for field-based view.');
$view = Views::getview('entity_test_fields');
// Empty result (no entities yet).
$this->pass('Test without entities');
$base_tags = ['config:views.view.entity_test_fields', 'entity_test_list'];
$this->assertViewsCacheTags($view, $base_tags, $do_assert_views_caches, $base_tags);
$this->assertViewsCacheTagsFromStaticRenderArray($view, $base_tags, $do_assert_views_caches);
@ -103,7 +101,6 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$entities[] = $entity = EntityTest::create();
$entity->save();
$this->pass('Test with entities');
$tags_with_entity = Cache::mergeTags($base_tags, $entities[0]->getCacheTags());
$this->assertViewsCacheTags($view, $tags_with_entity, $do_assert_views_caches, $tags_with_entity);
$this->assertViewsCacheTagsFromStaticRenderArray($view, $tags_with_entity, $do_assert_views_caches);
@ -114,9 +111,8 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$entity->save();
}
// Test pager.
// Page 1.
$this->pass('Test pager');
$this->pass('Page 1');
\Drupal::request()->query->set('page', 0);
$tags_page_1 = Cache::mergeTags($base_tags, $entities[1]->getCacheTags());
$tags_page_1 = Cache::mergeTags($tags_page_1, $entities[2]->getCacheTags());
@ -127,7 +123,6 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$this->assertViewsCacheTagsFromStaticRenderArray($view, $tags_page_1, $do_assert_views_caches);
$view->destroy();
// Page 2.
$this->pass('Page 2');
$view->setCurrentPage(1);
\Drupal::request()->query->set('page', 1);
$tags_page_2 = Cache::mergeTags($base_tags, $entities[0]->getCacheTags());
@ -135,8 +130,7 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$view->destroy();
// Ensure that invalidation works on both pages.
$this->pass('Page invalidations');
$this->pass('Page 2');
// Page 2.
$view->setCurrentPage(1);
\Drupal::request()->query->set('page', 1);
$entities[0]->name->value = $random_name = $this->randomMachineName();
@ -148,7 +142,7 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$this->assertStringContainsString($random_name, (string) $build['#markup']);
$view->destroy();
$this->pass('Page 1');
// Page 1.
$view->setCurrentPage(0);
\Drupal::request()->query->set('page', 0);
$entities[1]->name->value = $random_name = $this->randomMachineName();
@ -159,8 +153,6 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
$view->destroy();
// Setup arguments to ensure that render caching also varies by them.
$this->pass('Test arguments');
// Custom assert for a single result row.
$single_entity_assertions = function (array $build, EntityInterface $entity) {
$this->setRawContent($build['#markup']);
@ -239,7 +231,6 @@ class RenderCacheIntegrationTest extends ViewsKernelTestBase {
* Tests cache tags on output & result cache items for an entity-based view.
*/
protected function assertCacheTagsForEntityBasedView($do_assert_views_caches) {
$this->pass('Checking cache tags for entity-based view.');
$view = Views::getview('entity_test_row');
// Empty result (no entities yet).

View File

@ -138,11 +138,10 @@ class ViewsConfigUpdaterTest extends ViewsKernelTestBase {
foreach ($view_ids as $view_id) {
$test_view = $this->loadTestView($view_id);
$this->configUpdater->updateAll($test_view);
$this->assertTrue($this->configUpdater->updateAll($test_view), "View $view_id should be updated.");
}
// @todo Improve this in https://www.drupal.org/node/3121008.
$this->pass('Views processed');
}
}

View File

@ -83,7 +83,6 @@ class DemoUmamiProfileTest extends BrowserTestBase {
// FunctionalTestSetupTrait::installParameters().
'system.site' => ['uuid:', 'name:', 'mail:'],
]);
$this->pass("$config_name has no differences");
}
else {
$this->fail("$config_name has not been installed");

View File

@ -240,8 +240,7 @@ class UncaughtExceptionTest extends BrowserTestBase {
default:
// We can not carry out this test.
$this->pass('Unable to run \Drupal\system\Tests\System\UncaughtExceptionTest::testLostDatabaseConnection for this database type.');
return;
$this->markTestSkipped('Unable to run \Drupal\system\Tests\System\UncaughtExceptionTest::testLostDatabaseConnection for this database type.');
}
// We simulate a broken database connection by rewrite settings.php to no

View File

@ -328,7 +328,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "notexisting" field was found.');
}
catch (ExpectationFailedException $e) {
$this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.');
// Expected exception; just continue testing.
}
try {
@ -336,7 +336,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-name" field was not found.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.');
// Expected exception; just continue testing.
}
try {
@ -344,7 +344,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-name" field is found with the value "not the value".');
}
catch (ExpectationFailedException $e) {
$this->pass('The "edit-name" field is not found with the value "not the value".');
// Expected exception; just continue testing.
}
}
@ -363,7 +363,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field was not found based on name.');
}
catch (ExpectationException $e) {
$this->pass('assertNoField correctly failed. The "name" field was found by name.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly when searching by id.
@ -372,7 +372,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field was not found based on id.');
}
catch (ExpectationException $e) {
$this->pass('assertNoField correctly failed. The "name" field was found by id.');
// Expected exception; just continue testing.
}
// *** 2. assertField().
@ -385,7 +385,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "invalid_name_and_id" field was found.');
}
catch (ExpectationFailedException $e) {
$this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
// Expected exception; just continue testing.
}
// *** 3. assertNoFieldById().
@ -400,7 +400,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "description" field, with no value was not found.');
}
catch (ExpectationException $e) {
$this->pass('The "description" field, with no value was found.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly if a NULL value is passed in.
@ -409,7 +409,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field was not found.');
}
catch (ExpectationException $e) {
$this->pass('The "name" field was found.');
// Expected exception; just continue testing.
}
// *** 4. assertFieldById().
@ -424,7 +424,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-name" field with no value was found.');
}
catch (ExpectationFailedException $e) {
$this->pass('The "edit-name" field with no value was not found.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly if the wrong value is passed in.
@ -433,7 +433,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field was found, using the wrong value.');
}
catch (ExpectationFailedException $e) {
$this->pass('The "name" field was not found, using the wrong value.');
// Expected exception; just continue testing.
}
// *** 5. assertNoFieldByName().
@ -448,7 +448,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "description" field, with no value was not found.');
}
catch (ExpectationException $e) {
$this->pass('The "description" field, with no value was found.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly if a NULL value is passed in.
@ -457,7 +457,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field was not found.');
}
catch (ExpectationException $e) {
$this->pass('The "name" field was found.');
// Expected exception; just continue testing.
}
// *** 6. assertFieldByName().
@ -474,7 +474,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "non-existing-name" field was found.');
}
catch (ExpectationFailedException $e) {
$this->pass('The "non-existing-name" field was not found');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly if given the wrong value.
@ -483,7 +483,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "name" field with incorrect value was found.');
}
catch (ExpectationFailedException $e) {
$this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
// Expected exception; just continue testing.
}
// Test that text areas can contain new lines.
@ -508,7 +508,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The select option "four" was found.');
}
catch (ExpectationException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
$this->assertOption('options', 1);
@ -517,7 +517,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The select option "4" was found.');
}
catch (ExpectationException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
$this->assertNoOption('options', 'non-existing');
@ -526,7 +526,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The select option "one" was not found.');
}
catch (ExpectationException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
$this->assertTrue($this->assertSession()->optionExists('options', 2)->isSelected());
@ -535,7 +535,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The select option "4" was selected.');
}
catch (ExpectationException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
try {
@ -543,7 +543,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The select option "1" was selected.');
}
catch (ExpectationFailedException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
}
@ -562,7 +562,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The field with id of "Save" was found.');
}
catch (ExpectationFailedException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
$this->assertNoFieldById('Save', NULL);
@ -573,7 +573,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The field with id of "edit-save" was not found.');
}
catch (ExpectationException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
// Test that multiple fields with the same name are validated correctly.
@ -586,7 +586,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.');
// Expected exception; just continue testing.
}
}
@ -623,7 +623,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "checkbox_enabled" field was not found by name, using NULL value.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.');
// Expected exception; just continue testing.
}
// Part 2 - Test by ID.
@ -653,7 +653,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-checkbox-disabled" field was not found by ID, using NULL value.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.');
// Expected exception; just continue testing.
}
// Part 3 - Test the specific 'checked' assertions.
@ -666,7 +666,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "incorrect_checkbox_id" field was found');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldChecked correctly failed. The "incorrect_checkbox_id" field was not found.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly for a checkbox that is checked.
@ -675,7 +675,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-checkbox-enabled" field was not found in a checked state.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldChecked correctly failed. The "edit-checkbox-enabled" field was found in a checked state.');
// Expected exception; just continue testing.
}
// Test that the assertion fails correctly for a checkbox that is not
@ -685,7 +685,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->fail('The "edit-checkbox-disabled" field was found and checked.');
}
catch (ExpectationException $e) {
$this->pass('assertFieldChecked correctly failed. The "edit-checkbox-disabled" field was not found in a checked state.');
// Expected exception; just continue testing.
}
}

View File

@ -124,7 +124,6 @@ class DistributionProfileExistingSettingsTest extends InstallerTestBase {
$this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
$this->rebuildContainer();
$this->pass('Container can be rebuilt even though distribution is not written to settings.php.');
$this->assertEqual(\Drupal::installProfile(), 'mydistro');
}

View File

@ -85,7 +85,6 @@ class MultipleDistributionsProfileTest extends InstallerTestBase {
$this->assertEqual($this->config('core.extension')->get('profile'), 'distribution_one', 'The install profile has been written to core.extension configuration.');
$this->rebuildContainer();
$this->pass('Container can be rebuilt as distribution is written to configuration.');
$this->assertEqual(\Drupal::installProfile(), 'distribution_one');
}

View File

@ -118,10 +118,9 @@ class DefaultConfigTest extends KernelTestBase {
$entity_storage->load($id)->calculateDependencies()->save();
}
$result = $config_manager->diff($default_config_storage, $active_config_storage, $config_name);
$this->assertConfigDiff($result, $config_name, static::$skippedConfig);
// The method call above will throw an exception if the configuration is
// ::assertConfigDiff will throw an exception if the configuration is
// different.
$this->pass("$config_name has no differences");
$this->assertNull($this->assertConfigDiff($result, $config_name, static::$skippedConfig));
}
else {
$info = $this->container->get('extension.list.module')->getExtensionInfo($module);

View File

@ -229,8 +229,7 @@ class LibraryDiscoveryIntegrationTest extends KernelTestBase {
$this->libraryDiscovery->clearCachedDefinitions();
// Assert message.
$this->pass(sprintf('Activated theme "%s"', $theme_name));
$this->assertSame($theme_name, $theme_manager->getActiveTheme()->getName());
}
/**
@ -257,7 +256,7 @@ class LibraryDiscoveryIntegrationTest extends KernelTestBase {
$library = $this->libraryDiscovery->getLibraryByName($extension, $library_name);
foreach ($library[$sub_key] as $definition) {
if ($asset == $definition['data']) {
return $this->pass($message);
return TRUE;
}
}
return $this->fail($message);
@ -290,7 +289,7 @@ class LibraryDiscoveryIntegrationTest extends KernelTestBase {
return $this->fail($message);
}
}
return $this->pass($message);
return TRUE;
}
}

View File

@ -44,15 +44,6 @@ class DbDumpTest extends KernelTestBase {
*/
protected $data;
/**
* Flag to skip these tests, which are database-backend dependent (MySQL).
*
* @see \Drupal\Core\Command\DbDumpCommand
*
* @var bool
*/
protected $skipTests = FALSE;
/**
* An array of original table schemas.
*
@ -93,8 +84,9 @@ class DbDumpTest extends KernelTestBase {
protected function setUp(): void {
parent::setUp();
// Determine what database backend is running, and set the skip flag.
$this->skipTests = Database::getConnection()->databaseType() !== 'mysql';
if (Database::getConnection()->databaseType() !== 'mysql') {
$this->markTestSkipped("Skipping test since the DbDumpCommand is currently only compatible with MySql");
}
// Create some schemas so our export contains tables.
$this->installSchema('system', [
@ -162,11 +154,6 @@ class DbDumpTest extends KernelTestBase {
* Test the command directly.
*/
public function testDbDumpCommand() {
if ($this->skipTests) {
$this->pass("Skipping test since the DbDumpCommand is currently only compatible with MySql");
return;
}
$application = new DbDumpApplication();
$command = $application->find('dump-database-d8-mysql');
$command_tester = new CommandTester($command);
@ -196,11 +183,6 @@ class DbDumpTest extends KernelTestBase {
* Test loading the script back into the database.
*/
public function testScriptLoad() {
if ($this->skipTests) {
$this->pass("Skipping test since the DbDumpCommand is currently only compatible with MySql");
return;
}
// Generate the script.
$application = new DbDumpApplication();
$command = $application->find('dump-database-d8-mysql');

View File

@ -193,24 +193,22 @@ class ConfigCRUDTest extends KernelTestBase {
public function testNameValidation() {
// Verify that an object name without namespace causes an exception.
$name = 'nonamespace';
$message = 'Expected ConfigNameException was thrown for a name without a namespace.';
try {
$this->config($name)->save();
$this->fail($message);
$this->fail('Expected ConfigNameException was thrown for a name without a namespace.');
}
catch (ConfigNameException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ConfigNameException::class, $e);
}
// Verify that a name longer than the maximum length causes an exception.
$name = 'config_test.herman_melville.moby_dick_or_the_whale.harper_1851.now_small_fowls_flew_screaming_over_the_yet_yawning_gulf_a_sullen_white_surf_beat_against_its_steep_sides_then_all_collapsed_and_the_great_shroud_of_the_sea_rolled_on_as_it_rolled_five_thousand_years_ago';
$message = 'Expected ConfigNameException was thrown for a name longer than Config::MAX_NAME_LENGTH.';
try {
$this->config($name)->save();
$this->fail($message);
$this->fail('Expected ConfigNameException was thrown for a name longer than Config::MAX_NAME_LENGTH.');
}
catch (ConfigNameException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ConfigNameException::class, $e);
}
// Verify that disallowed characters in the name cause an exception.
@ -231,14 +229,12 @@ class ConfigCRUDTest extends KernelTestBase {
// Verify that a valid config object name can be saved.
$name = 'namespace.object';
$message = 'ConfigNameException was not thrown for a valid object name.';
try {
$config = $this->config($name);
$config->save();
$this->pass($message);
}
catch (ConfigNameException $e) {
$this->fail($message);
$this->fail('ConfigNameException was not thrown for a valid object name.');
}
}
@ -248,23 +244,21 @@ class ConfigCRUDTest extends KernelTestBase {
*/
public function testValueValidation() {
// Verify that setData() will catch dotted keys.
$message = 'Expected ConfigValueException was thrown from setData() for value with dotted keys.';
try {
$this->config('namespace.object')->setData(['key.value' => 12])->save();
$this->fail($message);
$this->fail('Expected ConfigValueException was thrown from setData() for value with dotted keys.');
}
catch (ConfigValueException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ConfigValueException::class, $e);
}
// Verify that set() will catch dotted keys.
$message = 'Expected ConfigValueException was thrown from set() for value with dotted keys.';
try {
$this->config('namespace.object')->set('foo', ['key.value' => 12])->save();
$this->fail($message);
$this->fail('Expected ConfigValueException was thrown from set() for value with dotted keys.');
}
catch (ConfigValueException $e) {
$this->pass($message);
catch (\Exception $e) {
$this->assertInstanceOf(ConfigValueException::class, $e);
}
}
@ -325,9 +319,7 @@ class ConfigCRUDTest extends KernelTestBase {
$this->fail('No Exception thrown upon saving invalid data type.');
}
catch (UnsupportedDataTypeConfigException $e) {
$this->pass(new FormattableMarkup('%class thrown upon saving invalid data type.', [
'%class' => get_class($e),
]));
// Expected exception; just continue testing.
}
// Test that setting an unsupported type for a config object with no schema
@ -342,9 +334,7 @@ class ConfigCRUDTest extends KernelTestBase {
$this->fail('No Exception thrown upon saving invalid data type.');
}
catch (UnsupportedDataTypeConfigException $e) {
$this->pass(new FormattableMarkup('%class thrown upon saving invalid data type.', [
'%class' => get_class($e),
]));
// Expected exception; just continue testing.
}
}

View File

@ -2,7 +2,6 @@
namespace Drupal\KernelTests\Core\Config;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Config\ConfigDuplicateUUIDException;
use Drupal\KernelTests\KernelTestBase;
@ -44,7 +43,7 @@ class ConfigEntityStorageTest extends KernelTestBase {
$this->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.');
}
catch (ConfigDuplicateUUIDException $e) {
$this->pass(new FormattableMarkup('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', ['%e' => $e]));
// Expected exception; just continue testing.
}
// Ensure that the config entity was not corrupted.

View File

@ -40,13 +40,8 @@ class ConfigExportStorageTest extends KernelTestBase {
}
// Test that the export storage is read-only.
try {
$export->deleteAll();
$this->fail("export storage must not allow editing");
}
catch (\BadMethodCallException $exception) {
$this->pass("Exception is thrown.");
}
$this->expectException(\BadMethodCallException::class);
$export->deleteAll();
}
}

View File

@ -110,7 +110,6 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
$this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
}
catch (ConfigImporterException $e) {
$this->pass('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
$expected = [
new FormattableMarkup('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', ['@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id]),
];
@ -153,7 +152,6 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
$this->fail('Expected ConfigImporterException thrown when simple configuration is renamed.');
}
catch (ConfigImporterException $e) {
$this->pass('Expected ConfigImporterException thrown when simple configuration is renamed.');
$expected = [
new FormattableMarkup('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', ['@old_name' => 'config_test.old', '@new_name' => 'config_test.new']),
];

View File

@ -84,14 +84,9 @@ class ConfigImporterTest extends KernelTestBase {
* fails.
*/
public function testEmptyImportFails() {
try {
$this->container->get('config.storage.sync')->deleteAll();
$this->configImporter->reset()->import();
$this->fail('ConfigImporterException thrown, successfully stopping an empty import.');
}
catch (ConfigImporterException $e) {
$this->pass('ConfigImporterException thrown, successfully stopping an empty import.');
}
$this->expectException(ConfigImporterException::class);
$this->container->get('config.storage.sync')->deleteAll();
$this->configImporter->reset()->import();
}
/**
@ -809,7 +804,7 @@ class ConfigImporterTest extends KernelTestBase {
$this->fail('Expected \InvalidArgumentException thrown');
}
catch (\InvalidArgumentException $e) {
$this->pass('Expected \InvalidArgumentException thrown');
// Expected exception; just continue testing.
}
$this->assertFalse(\Drupal::isConfigSyncing(), 'After an invalid step \Drupal::isConfigSyncing() returns FALSE');
}

View File

@ -560,35 +560,29 @@ class ConfigSchemaTest extends KernelTestBase {
// Ensure that keys can not be added or removed by
// hook_config_schema_info_alter().
\Drupal::state()->set('config_schema_test_exception_remove', TRUE);
$message = 'Expected ConfigSchemaAlterException thrown.';
try {
$typed_config->getDefinitions();
$this->fail($message);
$this->fail('Expected ConfigSchemaAlterException thrown.');
}
catch (ConfigSchemaAlterException $e) {
$this->pass($message);
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has removed (config_schema_test.hook) schema definitions');
}
\Drupal::state()->set('config_schema_test_exception_add', TRUE);
$message = 'Expected ConfigSchemaAlterException thrown.';
try {
$typed_config->getDefinitions();
$this->fail($message);
$this->fail('Expected ConfigSchemaAlterException thrown.');
}
catch (ConfigSchemaAlterException $e) {
$this->pass($message);
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_defintion) and removed (config_schema_test.hook) schema definitions');
}
\Drupal::state()->set('config_schema_test_exception_remove', FALSE);
$message = 'Expected ConfigSchemaAlterException thrown.';
try {
$typed_config->getDefinitions();
$this->fail($message);
$this->fail('Expected ConfigSchemaAlterException thrown.');
}
catch (ConfigSchemaAlterException $e) {
$this->pass($message);
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_defintion) schema definitions');
}

View File

@ -82,7 +82,6 @@ class FileStorageTest extends ConfigStorageTestBase {
$config_parsed = $this->storage->read('core.extension');
}
catch (UnsupportedDataTypeConfigException $e) {
$this->pass('Exception thrown when trying to read a field containing invalid data type.');
$this->assertStringContainsString($this->storage->getFilePath('core.extension'), $e->getMessage(), 'Erroneous file path is displayed.');
}
}

View File

@ -144,33 +144,17 @@ class ConnectionTest extends DatabaseTestBase {
$this->markTestSkipped("This test only runs for MySQL");
}
$db = Database::getConnection('default', 'default');
// Disable the protection at the PHP level.
try {
$db->query('SELECT * FROM {test}; SELECT * FROM {test_people}',
[],
['allow_delimiter_in_query' => TRUE]
);
$this->fail('No PDO exception thrown for multiple statements.');
}
catch (DatabaseExceptionWrapper $e) {
$this->pass('PDO exception thrown for multiple statements.');
}
$this->expectException(DatabaseExceptionWrapper::class);
Database::getConnection('default', 'default')->query('SELECT * FROM {test}; SELECT * FROM {test_people}', [], ['allow_delimiter_in_query' => TRUE]);
}
/**
* Ensure that you cannot execute multiple statements.
*/
public function testMultipleStatements() {
$db = Database::getConnection('default', 'default');
try {
$db->query('SELECT * FROM {test}; SELECT * FROM {test_people}');
$this->fail('No exception thrown for multiple statements.');
}
catch (\InvalidArgumentException $e) {
$this->pass('Exception thrown for multiple statements.');
}
$this->expectException(\InvalidArgumentException::class);
Database::getConnection('default', 'default')->query('SELECT * FROM {test}; SELECT * FROM {test_people}');
}
/**

View File

@ -32,14 +32,8 @@ class DatabaseExceptionWrapperTest extends KernelTestBase {
$this->fail('Expected PDOException or DatabaseExceptionWrapper, none was thrown.');
}
catch (\PDOException $e) {
$this->pass('Expected PDOException was thrown.');
}
catch (DatabaseExceptionWrapper $e) {
$this->pass('Expected DatabaseExceptionWrapper was thrown.');
}
catch (\Exception $e) {
$this->fail("Thrown exception is not a PDOException:\n" . (string) $e);
$this->assertTrue($e instanceof \PDOException || $e instanceof DatabaseExceptionWrapper, 'Exception should be an instance of \PDOException or DatabaseExceptionWrapper, thrown ' . get_class($e));
}
}
@ -68,17 +62,8 @@ class DatabaseExceptionWrapperTest extends KernelTestBase {
* Tests the expected database exception thrown for inexistent tables.
*/
public function testQueryThrowsDatabaseExceptionWrapperException() {
$connection = Database::getConnection();
try {
$connection->query('SELECT * FROM {does_not_exist}');
$this->fail('Expected PDOException, none was thrown.');
}
catch (DatabaseExceptionWrapper $e) {
$this->pass('Expected DatabaseExceptionWrapper was thrown.');
}
catch (\Exception $e) {
$this->fail("Thrown exception is not a DatabaseExceptionWrapper:\n" . (string) $e);
}
$this->expectException(DatabaseExceptionWrapper::class);
Database::getConnection()->query('SELECT * FROM {does_not_exist}');
}
}

View File

@ -36,7 +36,7 @@ class InsertDefaultsTest extends DatabaseTestBase {
$this->fail('Expected exception NoFieldsException has not been thrown.');
}
catch (NoFieldsException $e) {
$this->pass('Expected exception NoFieldsException has been thrown.');
// Expected exception; just continue testing.
}
$num_records_after = (int) $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();

View File

@ -207,11 +207,9 @@ class MergeTest extends DatabaseTestBase {
'name' => 'Tiffany',
])
->execute();
$this->pass('$options[\'throw_exception\'] is FALSE, no InvalidMergeQueryException thrown.');
}
catch (InvalidMergeQueryException $e) {
$this->fail('$options[\'throw_exception\'] is FALSE, but InvalidMergeQueryException thrown for invalid query.');
return;
}
try {
@ -222,12 +220,11 @@ class MergeTest extends DatabaseTestBase {
'name' => 'Tiffany',
])
->execute();
$this->fail('InvalidMergeQueryException should be thrown.');
}
catch (InvalidMergeQueryException $e) {
$this->pass('InvalidMergeQueryException thrown for invalid query.');
return;
catch (\Exception $e) {
$this->assertInstanceOf(InvalidMergeQueryException::class, $e);
}
$this->fail('No InvalidMergeQueryException thrown');
}
/**

View File

@ -28,8 +28,8 @@ class QueryTest extends DatabaseTestBase {
$names = $this->connection->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [':ages[]' => 25])->fetchAll();
$this->fail('Array placeholder with scalar argument should result in an exception.');
}
catch (\InvalidArgumentException $e) {
$this->pass('Array placeholder with scalar argument should result in an exception.');
catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
}
@ -48,7 +48,7 @@ class QueryTest extends DatabaseTestBase {
$this->fail('SQL injection attempt via array arguments should result in a database exception.');
}
catch (\InvalidArgumentException $e) {
$this->pass('SQL injection attempt via array arguments should result in a database exception.');
// Expected exception; just continue testing.
}
// Test that the insert query that was used in the SQL injection attempt did
@ -85,7 +85,7 @@ class QueryTest extends DatabaseTestBase {
$this->fail('Should not be able to attempt SQL injection via condition operator.');
}
catch (\ErrorException $e) {
$this->pass('SQL injection attempt via condition arguments should result in a database exception.');
// Expected exception; just continue testing.
}
// Test that the insert query that was used in the SQL injection attempt did
@ -113,7 +113,7 @@ class QueryTest extends DatabaseTestBase {
$this->fail('Should not be able to attempt SQL injection via operator.');
}
catch (\ErrorException $e) {
$this->pass('SQL injection attempt via condition arguments should result in a database exception.');
// Expected exception; just continue testing.
}
// Attempt SQLi via union query - uppercase tablename.
@ -130,7 +130,7 @@ class QueryTest extends DatabaseTestBase {
$this->fail('Should not be able to attempt SQL injection via operator.');
}
catch (\ErrorException $e) {
$this->pass('SQL injection attempt via condition arguments should result in a database exception.');
// Expected exception; just continue testing.
}
restore_error_handler();
}

View File

@ -433,7 +433,7 @@ class SchemaTest extends KernelTestBase {
$this->fail('\Drupal\Core\Database\SchemaObjectExistsException exception missed.');
}
catch (SchemaObjectExistsException $e) {
$this->pass('\Drupal\Core\Database\SchemaObjectExistsException thrown when index already exists.');
// Expected exception; just continue testing.
}
try {
@ -441,7 +441,7 @@ class SchemaTest extends KernelTestBase {
$this->fail('\Drupal\Core\Database\SchemaObjectDoesNotExistException exception missed.');
}
catch (SchemaObjectDoesNotExistException $e) {
$this->pass('\Drupal\Core\Database\SchemaObjectDoesNotExistException thrown when index already exists.');
// Expected exception; just continue testing.
}
// Get index information.
@ -687,7 +687,6 @@ class SchemaTest extends KernelTestBase {
'primary key' => ['serial_column'],
];
$this->schema->createTable($table_name, $table_spec);
$this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name]));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
@ -705,7 +704,6 @@ class SchemaTest extends KernelTestBase {
'primary key' => ['serial_column'],
];
$this->schema->createTable($table_name, $table_spec);
$this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name]));
// Insert some rows to the table to test the handling of initial values.
for ($i = 0; $i < 3; $i++) {
@ -723,7 +721,6 @@ class SchemaTest extends KernelTestBase {
->execute();
$this->schema->addField($table_name, 'test_field', $field_spec);
$this->pass(new FormattableMarkup('Column %column created.', ['%column' => 'test_field']));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
@ -1025,7 +1022,6 @@ class SchemaTest extends KernelTestBase {
'primary key' => ['serial_column'],
];
$this->schema->createTable($table_name, $table_spec);
$this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name]));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $old_spec);

View File

@ -4,6 +4,7 @@ namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\InvalidQueryException;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
/**
* Tests the Select query builder.
@ -549,7 +550,7 @@ class SelectTest extends DatabaseTestBase {
}
/**
* Tests that an invalid merge query throws an exception.
* Tests that an invalid count query throws an exception.
*/
public function testInvalidSelectCount() {
try {
@ -561,12 +562,9 @@ class SelectTest extends DatabaseTestBase {
->fields('t')
->countQuery()
->execute();
$this->pass('$options[\'throw_exception\'] is FALSE, no Exception thrown.');
}
catch (\Exception $e) {
$this->fail('$options[\'throw_exception\'] is FALSE, but Exception thrown for invalid query.');
return;
}
try {
@ -575,12 +573,11 @@ class SelectTest extends DatabaseTestBase {
->fields('t')
->countQuery()
->execute();
$this->fail('No Exception thrown.');
}
catch (\Exception $e) {
$this->pass('Exception thrown for invalid query.');
return;
$this->assertInstanceOf(DatabaseExceptionWrapper::class, $e);
}
$this->fail('No Exception thrown.');
}
/**

View File

@ -268,7 +268,7 @@ class TransactionTest extends DatabaseTestBase {
// $this->fail('Rolling back a transaction containing DDL should fail.');
}
catch (TransactionNoActiveException $e) {
$this->pass('Rolling back a transaction containing DDL should fail.');
// Expected exception; just continue testing.
}
$this->assertRowPresent('row');
}
@ -429,12 +429,12 @@ class TransactionTest extends DatabaseTestBase {
$this->fail('Rolling back the outer transaction while the inner transaction is active resulted in an exception.');
}
catch (TransactionOutOfOrderException $e) {
$this->pass('Rolling back the outer transaction while the inner transaction is active resulted in an exception.');
// Expected exception; just continue testing.
}
$this->assertFalse($this->connection->inTransaction(), 'No more in a transaction after rolling back the outer transaction');
// Try to commit one inner transaction.
unset($transaction3);
$this->pass('Trying to commit an inner transaction resulted in an exception.');
// Try to rollback one inner transaction.
try {
$transaction->rollBack();
@ -442,7 +442,7 @@ class TransactionTest extends DatabaseTestBase {
$this->fail('Trying to commit an inner transaction resulted in an exception.');
}
catch (TransactionNoActiveException $e) {
$this->pass('Trying to commit an inner transaction resulted in an exception.');
// Expected exception; just continue testing.
}
$this->assertRowAbsent('outer');
$this->assertRowAbsent('inner');
@ -459,10 +459,10 @@ class TransactionTest extends DatabaseTestBase {
// Test a failed query using the query() method.
try {
$this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'David'])->fetchField();
$this->fail('Using the query method failed.');
$this->fail('Using the query method should have failed.');
}
catch (\Exception $e) {
$this->pass('Using the query method failed.');
// Just continue testing.
}
// Test a failed select query.
@ -471,10 +471,10 @@ class TransactionTest extends DatabaseTestBase {
->fields('test', ['name'])
->execute();
$this->fail('Select query failed.');
$this->fail('Select query should have failed.');
}
catch (\Exception $e) {
$this->pass('Select query failed.');
// Just continue testing.
}
// Test a failed insert query.
@ -486,10 +486,10 @@ class TransactionTest extends DatabaseTestBase {
])
->execute();
$this->fail('Insert query failed.');
$this->fail('Insert query should have failed.');
}
catch (\Exception $e) {
$this->pass('Insert query failed.');
// Just continue testing.
}
// Test a failed update query.
@ -499,10 +499,10 @@ class TransactionTest extends DatabaseTestBase {
->condition('id', 1)
->execute();
$this->fail('Update query failed.');
$this->fail('Update query should have failed.');
}
catch (\Exception $e) {
$this->pass('Update query failed.');
// Just continue testing.
}
// Test a failed delete query.
@ -511,10 +511,10 @@ class TransactionTest extends DatabaseTestBase {
->condition('id', 1)
->execute();
$this->fail('Delete query failed.');
$this->fail('Delete query should have failed.');
}
catch (\Exception $e) {
$this->pass('Delete query failed.');
// Just continue testing.
}
// Test a failed merge query.
@ -527,10 +527,10 @@ class TransactionTest extends DatabaseTestBase {
])
->execute();
$this->fail('Merge query failed.');
$this->fail('Merge query should have failed.');
}
catch (\Exception $e) {
$this->pass('Merge query failed.');
// Just continue testing.
}
// Test a failed upsert query.
@ -545,10 +545,10 @@ class TransactionTest extends DatabaseTestBase {
])
->execute();
$this->fail('Upset query failed.');
$this->fail('Upsert query should have failed.');
}
catch (\Exception $e) {
$this->pass('Upset query failed.');
// Just continue testing.
}
// Create the missing schema and insert a row.

View File

@ -4,6 +4,7 @@ namespace Drupal\KernelTests\Core\DrupalKernel;
use Composer\Autoload\ClassLoader;
use Drupal\Core\DrupalKernel;
use Drupal\Core\DrupalKernelInterface;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;
use Prophecy\Argument;
@ -160,10 +161,8 @@ class DrupalKernelTest extends KernelTestBase {
$kernel = DrupalKernel::createFromRequest($request, $class_loader, $environment);
$this->setSetting('container_yamls', []);
$this->setSetting('hash_salt', $this->databasePrefix);
$kernel->boot();
$this->assertInstanceOf(DrupalKernelInterface::class, $kernel->boot(), "Environment $environment should boot.");
}
$this->pass('Repeatedly loaded compiled DIC with different environment');
}
/**

View File

@ -214,7 +214,6 @@ class EntityApiTest extends EntityKernelTestBase {
try {
unset($GLOBALS['entity_test_throw_exception']);
$entity->save();
$this->pass('Exception presave not thrown and not caught.');
}
catch (EntityStorageException $e) {
$this->assertNotEqual($e->getCode(), 1, 'Entity presave EntityStorageException caught.');
@ -236,7 +235,6 @@ class EntityApiTest extends EntityKernelTestBase {
$entity->save();
try {
$entity->delete();
$this->pass('Entity predelete EntityStorageException not thrown and not caught.');
}
catch (EntityStorageException $e) {
$this->assertNotEqual($e->getCode(), 2, 'Entity predelete EntityStorageException thrown.');

View File

@ -115,7 +115,7 @@ class EntityAutocompleteTest extends EntityKernelTestBase {
$this->fail('Non-existent selection settings key throws an exception.');
}
catch (AccessDeniedHttpException $e) {
$this->pass('Non-existent selection settings key throws an exception.');
// Expected exception; just continue testing.
}
try {
@ -129,12 +129,7 @@ class EntityAutocompleteTest extends EntityKernelTestBase {
$entity_reference_controller->handleAutocomplete($request, $this->entityType, 'default', $selection_settings_key);
}
catch (AccessDeniedHttpException $e) {
if ($e->getMessage() == 'Invalid selection settings key.') {
$this->pass('Invalid selection settings key throws an exception.');
}
else {
$this->fail('Invalid selection settings key throws an exception.');
}
$this->assertSame('Invalid selection settings key.', $e->getMessage());
}
}

View File

@ -550,7 +550,7 @@ class EntityCrudHookTest extends EntityKernelTestBase {
$this->fail('Expected exception has not been thrown.');
}
catch (\Exception $e) {
$this->pass('Expected exception has been thrown.');
// Expected exception; just continue testing.
}
// Check that the block does not exist in the database.

View File

@ -144,7 +144,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail('EntityStorageException thrown when trying to apply an update that requires shared table schema changes.');
}
catch (EntityStorageException $e) {
$this->pass('EntityStorageException thrown when trying to apply an update that requires shared table schema changes.');
// Expected exception; just continue testing.
}
}
@ -426,7 +426,6 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->assertTrue($assert, 'Columns created again in shared table for new_base_field.');
$entity = $storage->create(['name' => $name]);
$entity->save();
$this->pass('The new_base_field columns are still nullable');
}
/**
@ -490,7 +489,6 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->database->insert('entity_test_update__new_bundle_field')
->fields($values)
->execute();
$this->pass($message);
}
else {
// Keep throwing it.
@ -763,7 +761,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
// Expected exception; just continue testing.
}
}
@ -787,7 +785,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
// Expected exception; just continue testing.
}
}
@ -972,7 +970,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (PluginNotFoundException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Ensure that a field cannot be installed on non-existing entity type.
@ -985,7 +983,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (PluginNotFoundException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Ensure that installing an existing entity type is a no-op.
@ -1114,14 +1112,13 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (EntityStorageException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Check that the update is correctly applied when no NULL data is left.
$entity->set('new_base_field', $this->randomString());
$entity->save();
$this->applyEntityUpdates();
$this->pass('The update is correctly performed when no NULL data exists.');
// Check that the update actually applied a NOT NULL constraint.
$entity->set('new_base_field', NULL);
@ -1131,7 +1128,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (EntityStorageException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}
@ -1269,7 +1266,6 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
}
catch (FieldException $e) {
$this->assertEquals('Illegal initial value definition on new_base_field: The field field_that_does_not_exist does not exist.', $e->getMessage());
$this->pass('Using a non-existent field as initial value does not work.');
}
try {
@ -1282,7 +1278,6 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
}
catch (FieldException $e) {
$this->assertEquals('Illegal initial value definition on new_base_field: The field types do not match.', $e->getMessage());
$this->pass('Using a field of a different type as initial value does not work.');
}
try {
@ -1306,7 +1301,6 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
}
catch (FieldException $e) {
$this->assertEquals('Illegal initial value definition on new_base_field: Both fields have to be stored in the shared entity tables.', $e->getMessage());
$this->pass('Using a field that is not stored in the shared tables as initial value does not work.');
}
}

View File

@ -1106,17 +1106,12 @@ class EntityQueryTest extends EntityKernelTestBase {
* database driver's EntityQuery\Condition class.
*/
public function testInjectionInCondition() {
try {
$this->queryResults = $this->storage
->getQuery()
->condition('1 ; -- ', [0, 1], 'IN')
->sort('id')
->execute();
$this->fail('SQL Injection attempt in Entity Query condition in operator should result in an exception.');
}
catch (\Exception $e) {
$this->pass('SQL Injection attempt in Entity Query condition in operator should result in an exception.');
}
$this->expectException(\Exception::class);
$this->queryResults = $this->storage
->getQuery()
->condition('1 ; -- ', [0, 1], 'IN')
->sort('id')
->execute();
}
/**

View File

@ -273,7 +273,7 @@ class EntityReferenceFieldTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
$this->assertUserAutocreate($entity, function (EntityInterface $entity, UserInterface $user) {
$entity->user_id = $user;
@ -307,7 +307,7 @@ class EntityReferenceFieldTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
$this->assertUserRoleAutocreate($entity, function (EntityInterface $entity, RoleInterface $role) {
$entity->user_role = $role;
@ -404,7 +404,6 @@ class EntityReferenceFieldTest extends EntityKernelTestBase {
->getStorage($entity_type->id())
->create(['name' => $this->randomString()]);
$entity->target_reference = $target_id;
$this->pass($message);
}
catch (EntityStorageException $e) {
$this->fail($message);
@ -418,7 +417,7 @@ class EntityReferenceFieldTest extends EntityKernelTestBase {
$this->fail($message);
}
catch (EntityStorageException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}

View File

@ -62,13 +62,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, new FormattableMarkup('%entity_type: Field object has the expected langcode.', ['%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.';
try {
$entity->addTranslation($this->langcodes[1]);
$this->fail($message);
$this->fail('Adding a translation to a language-neutral entity results in an error.');
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Now, make the entity language-specific by assigning a language and test
@ -101,26 +100,24 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$this->assertEqual($entity->getTranslationLanguages(FALSE), $translations, 'Translations retrieved.');
// Try to get a value using a language code for a non-existing translation.
$message = 'Getting a non existing translation results in an error.';
try {
$entity->getTranslation($this->langcodes[2])->get($this->fieldName)->value;
$this->fail($message);
$this->fail('Getting a non existing translation results in an error.');
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Try to get a not available translation.
$this->assertNull($entity->addTranslation($this->langcodes[2])->get($this->fieldName)->value, new FormattableMarkup('%entity_type: A translation that is not available is NULL.', ['%entity_type' => $entity_type]));
// Try to get a value using an invalid language code.
$message = 'Getting an invalid translation results in an error.';
try {
$entity->getTranslation('invalid')->get($this->fieldName)->value;
$this->fail($message);
$this->fail('Getting an invalid translation results in an error.');
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Try to set a value using an invalid language code.
@ -129,7 +126,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$this->fail(new FormattableMarkup('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type]));
}
catch (\InvalidArgumentException $e) {
$this->pass(new FormattableMarkup('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type]));
// Expected exception; just continue testing.
}
// Set the value in default language.
@ -352,13 +349,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Verify that trying to retrieve a translation for a locked language when
// the entity is language-aware causes an exception to be thrown.
$message = 'A language-neutral translation cannot be retrieved.';
try {
$entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED);
$this->fail($message);
$this->fail('A language-neutral translation cannot be retrieved.');
}
catch (\LogicException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Create a translation and verify that the translation object and the
@ -391,23 +387,20 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Verify that changing translation language causes an exception to be
// thrown.
$message = 'The translation language cannot be changed.';
try {
$translation->{$langcode_key}->value = $this->langcodes[2];
$this->fail($message);
$this->fail('The translation language cannot be changed.');
}
catch (\LogicException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
// Verify that reassigning the same translation language is allowed.
$message = 'The translation language can be reassigned the same value.';
try {
$translation->{$langcode_key}->value = $langcode;
$this->pass($message);
}
catch (\LogicException $e) {
$this->fail($message);
$this->fail('The translation language can be reassigned the same value.');
}
// Verify that changing the default translation flag causes an exception to
@ -416,22 +409,19 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$translation = $entity->getTranslation($t_langcode);
$default = $translation->isDefaultTranslation();
$message = 'The default translation flag can be reassigned the same value.';
try {
$translation->{$default_langcode_key}->value = $default;
$this->pass($message);
}
catch (\LogicException $e) {
$this->fail($message);
$this->fail('The default translation flag can be reassigned the same value.');
}
$message = 'The default translation flag cannot be changed.';
try {
$translation->{$default_langcode_key}->value = !$default;
$this->fail($message);
$this->fail('The default translation flag cannot be changed.');
}
catch (\LogicException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
$this->assertEqual($translation->{$default_langcode_key}->value, $default);
@ -464,13 +454,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$translation = $entity->getTranslation($langcode2);
$entity->removeTranslation($langcode2);
foreach (['get', 'set', '__get', '__set', 'createDuplicate'] as $method) {
$message = new FormattableMarkup('The @method method raises an exception when trying to manipulate a removed translation.', ['@method' => $method]);
try {
$translation->{$method}('name', $this->randomMachineName());
$this->fail($message);
$this->fail("The $method method raises an exception when trying to manipulate a removed translation.");
}
catch (\Exception $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}
@ -486,13 +475,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Check that removing an invalid translation causes an exception to be
// thrown.
foreach ([$default_langcode, LanguageInterface::LANGCODE_DEFAULT, $this->randomMachineName()] as $invalid_langcode) {
$message = new FormattableMarkup('Removing an invalid translation (@langcode) causes an exception to be thrown.', ['@langcode' => $invalid_langcode]);
try {
$entity->removeTranslation($invalid_langcode);
$this->fail($message);
$this->fail("Removing an invalid translation ($invalid_langcode) causes an exception to be thrown.");
}
catch (\Exception $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}
@ -714,14 +702,13 @@ class EntityTranslationTest extends EntityLanguageTestBase {
foreach ($translatable_fields as $name => $translatable) {
$this->state->set('entity_test.field_definitions.translatable', [$name => $translatable]);
$entity_field_manager->clearCachedFieldDefinitions();
$message = new FormattableMarkup('Field %field cannot be translatable.', ['%field' => $name]);
try {
$entity_field_manager->getBaseFieldDefinitions($entity_type);
$this->fail($message);
$this->fail("Field $name cannot be translatable.");
}
catch (\LogicException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}
}
@ -778,13 +765,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Check that setting the default language to an existing translation
// language causes an exception to be thrown.
$message = 'An exception is thrown when setting the default language to an existing translation language';
try {
$entity->{$langcode_key}->value = $this->langcodes[2];
$this->fail($message);
$this->fail('An exception is thrown when setting the default language to an existing translation language');
}
catch (\InvalidArgumentException $e) {
$this->pass($message);
// Expected exception; just continue testing.
}
}

View File

@ -340,13 +340,8 @@ class FieldSqlStorageTest extends EntityKernelTestBase {
// Attempt to update the field in a way that would work without data.
$field_storage->setSetting('scale', 3);
try {
$field_storage->save();
$this->fail('Cannot update field schema with data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('Cannot update field schema with data.');
}
$this->expectException(FieldStorageDefinitionUpdateForbiddenException::class);
$field_storage->save();
}
/**
@ -374,7 +369,7 @@ class FieldSqlStorageTest extends EntityKernelTestBase {
$this->fail('Update succeeded.');
}
catch (\Exception $e) {
$this->pass('Update properly failed.');
// Expected exception; just continue testing.
}
// Ensure that the field tables are still there.

View File

@ -77,15 +77,10 @@ class ModuleImplementsAlterTest extends KernelTestBase {
// Install the module_test module.
\Drupal::service('module_installer')->install(['module_test']);
try {
// Trigger hook discovery.
\Drupal::moduleHandler()->getImplementations('unimplemented_test_hook');
$this->fail('An exception should be thrown for the non-existing implementation.');
}
catch (\RuntimeException $e) {
$this->pass('An exception should be thrown for the non-existing implementation.');
$this->assertEqual($e->getMessage(), 'An invalid implementation module_test_unimplemented_test_hook was added by hook_module_implements_alter()');
}
// Trigger hook discovery.
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('An invalid implementation module_test_unimplemented_test_hook was added by hook_module_implements_alter()');
\Drupal::moduleHandler()->getImplementations('unimplemented_test_hook');
}
}

View File

@ -62,7 +62,7 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify that an empty entity cannot be saved.
@ -71,7 +71,7 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify that an entity with an empty ID string is considered empty, too.
@ -84,7 +84,7 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
$this->fail('EntityMalformedException was thrown.');
}
catch (EntityMalformedException $e) {
$this->pass('EntityMalformedException was thrown.');
// Expected exception; just continue testing.
}
// Verify properties on a newly created entity.
@ -108,7 +108,6 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
// Verify that the entity can be saved.
try {
$status = $entity_test->save();
$this->pass('EntityMalformedException was not thrown.');
}
catch (EntityMalformedException $e) {
$this->fail('EntityMalformedException was not thrown.');
@ -143,7 +142,7 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
$this->fail('Not possible to overwrite an entity entity.');
}
catch (EntityStorageException $e) {
$this->pass('Not possible to overwrite an entity entity.');
// Expected exception; just continue testing.
}
// Verify that renaming the ID returns correct status and properties.

View File

@ -214,7 +214,7 @@ class MenuTreeStorageTest extends KernelTestBase {
$this->fail('Exception was not thrown');
}
catch (PluginException $e) {
$this->pass($e->getMessage());
// Expected exception; just continue testing.
}
// The opposite move should work, and change the has_children flag.
$this->moveMenuLink('footerA', 'test1');
@ -354,7 +354,6 @@ class MenuTreeStorageTest extends KernelTestBase {
}
catch (\InvalidArgumentException $e) {
$this->assertRegExp('/^An invalid property name, .+ was specified. Allowed property names are:/', $e->getMessage(), 'Found expected exception message.');
$this->pass($message);
}
}
$this->addMenuLink('test_link.1', '', 'test', [], 'menu1');

View File

@ -31,11 +31,8 @@ class FactoryTest extends PluginTestBase {
$this->testPluginManager->createInstance('non_existing');
$this->fail('Drupal\Component\Plugin\Exception\ExceptionInterface expected');
}
catch (ExceptionInterface $e) {
$this->pass('Drupal\Component\Plugin\Exception\ExceptionInterface expected and caught.');
}
catch (\Exception $e) {
$this->fail('Drupal\Component\Plugin\Exception\ExceptionInterface expected, but ' . get_class($e) . ' was thrown.');
$this->assertInstanceOf(ExceptionInterface::class, $e);
}
}
@ -68,11 +65,8 @@ class FactoryTest extends PluginTestBase {
$this->mockBlockManager->createInstance($invalid_id);
$this->fail('Drupal\Component\Plugin\Exception\ExceptionInterface expected');
}
catch (ExceptionInterface $e) {
$this->pass('Drupal\Component\Plugin\Exception\ExceptionInterface expected and caught.');
}
catch (\Exception $e) {
$this->fail('An unexpected Exception of type "' . get_class($e) . '" was thrown with message ' . $e->getMessage());
$this->assertInstanceOf(ExceptionInterface::class, $e);
}
}
}

View File

@ -68,13 +68,8 @@ class RenderTest extends KernelTestBase {
$build['#attached']['library'][] = 'core/drupal.states';
$build['#attached']['drupal_process_states'][] = [];
$renderer = $this->container->get('bare_html_page_renderer');
try {
$renderer->renderBarePage($build, '', 'maintenance_page');
$this->fail("Invalid #attachment 'drupal_process_states' allowed");
}
catch (\LogicException $e) {
$this->pass("Invalid #attachment 'drupal_process_states' not allowed");
}
$this->expectException(\LogicException::class);
$renderer->renderBarePage($build, '', 'maintenance_page');
}
}

View File

@ -136,17 +136,13 @@ class ContentNegotiationRoutingTest extends KernelTestBase {
$path = $test[0];
$accept_header = $test[1];
$content_type = $test[2];
$message = "Testing path:$path Accept:$accept_header Content-type:$content_type";
$request = Request::create('/' . $path);
$request->headers->set('Accept', $accept_header);
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
$kernel = \Drupal::getContainer()->get('http_kernel');
$response = $kernel->handle($request);
// Verbose message since simpletest doesn't let us provide a message and
// see the error.
$this->pass($message);
$this->assertEqual($response->getStatusCode(), Response::HTTP_OK);
$this->assertEqual($response->getStatusCode(), Response::HTTP_OK, "Testing path:$path Accept:$accept_header Content-type:$content_type");
}
}

View File

@ -95,16 +95,8 @@ class MatcherDumperTest extends KernelTestBase {
$dumper_routes = $dumper->getRoutes()->all();
$collection_routes = $collection->all();
$success = TRUE;
foreach ($collection_routes as $name => $route) {
if (empty($dumper_routes[$name])) {
$success = FALSE;
$this->fail('Not all routes found in the dumper.');
}
}
if ($success) {
$this->pass('All routes found in the dumper.');
$this->assertNotEmpty($dumper_routes[$name], "Route $name should be present in the dumper.");
}
}

View File

@ -50,18 +50,9 @@ class AccountSwitcherTest extends KernelTestBase {
// Verify that AccountSwitcherInterface::switchBack() will throw
// an exception if there are no accounts left in the stack.
try {
$switcher->switchBack();
$this->fail('::switchBack() throws exception if called without previous switch.');
}
catch (\RuntimeException $e) {
if ($e->getMessage() == 'No more accounts to revert to.') {
$this->pass('::switchBack() throws exception if called without previous switch.');
}
else {
$this->fail($e->getMessage());
}
}
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No more accounts to revert to.');
$switcher->switchBack();
}
}

View File

@ -115,8 +115,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->install([$name]);
$this->fail($message);
}
catch (UnknownExtensionException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(UnknownExtensionException::class, $e);
}
$themes = $this->themeHandler()->listInfo();
@ -134,8 +134,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->install([$name]);
$this->fail($message);
}
catch (ExtensionNameLengthException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(ExtensionNameLengthException::class, $e);
}
}
@ -230,8 +230,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->uninstall([$name]);
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
$themes = $this->themeHandler()->listInfo();
@ -257,8 +257,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->uninstall([$name]);
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
$themes = $this->themeHandler()->listInfo();
@ -295,8 +295,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->uninstall([$name]);
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
$themes = $this->themeHandler()->listInfo();
@ -325,8 +325,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->uninstall([$name]);
$this->fail($message);
}
catch (UnknownExtensionException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(UnknownExtensionException::class, $e);
}
$themes = $this->themeHandler()->listInfo();
@ -367,8 +367,8 @@ class ThemeInstallerTest extends KernelTestBase {
$this->themeInstaller()->uninstall([$name]);
$this->fail($message);
}
catch (UnknownExtensionException $e) {
$this->pass(get_class($e) . ': ' . $e->getMessage());
catch (\Exception $e) {
$this->assertInstanceOf(UnknownExtensionException::class, $e);
}
}

View File

@ -428,7 +428,7 @@ class TypedDataTest extends KernelTestBase {
$this->fail('No exception has been thrown when setting an invalid value.');
}
catch (\Exception $e) {
$this->pass('Exception thrown:' . $e->getMessage());
// Expected exception; just continue testing.
}
}
@ -550,7 +550,7 @@ class TypedDataTest extends KernelTestBase {
$this->fail('No exception has been thrown when getting an invalid value.');
}
catch (\Exception $e) {
$this->pass('Exception thrown:' . $e->getMessage());
// Expected exception; just continue testing.
}
// Test setting invalid values.
@ -559,7 +559,7 @@ class TypedDataTest extends KernelTestBase {
$this->fail('No exception has been thrown when setting an invalid value.');
}
catch (\Exception $e) {
$this->pass('Exception thrown:' . $e->getMessage());
// Expected exception; just continue testing.
}
// Test adding a new property to the map.

View File

@ -216,6 +216,14 @@ class AssertLegacyTraitTest extends UnitTestCase {
$this->assertElementNotPresent('.pager');
}
/**
* @covers ::pass
* @expectedDeprecation AssertLegacyTrait::pass() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit interrupts a test as soon as a test assertion fails, so there is usually no need to call this method. If a test's logic relies on this method, refactor the test. See https://www.drupal.org/node/3129738
*/
public function testPass() {
$this->pass('Passed.');
}
/**
* Returns a mocked behat session object.
*

View File

@ -169,7 +169,6 @@ trait DeprecationListenerTrait {
'AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertNotIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotSame() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::pass() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit interrupts a test as soon as a test assertion fails, so there is usually no need to call this method. If a test\'s logic relies on this method, refactor the test. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->pageTextContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738',