Commit 7dbdbcb1 authored by catch's avatar catch

Issue #3166450 by mondrake, longwave, snehalgaikwad: Split assertTrue using &&...

Issue #3166450 by mondrake, longwave, snehalgaikwad: Split assertTrue using && into multiple assertions
parent 0eec7fe5
......@@ -57,12 +57,15 @@ protected function getMails(array $filter = []) {
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
* TRUE on pass.
*/
protected function assertMail($name, $value = '', $message = '', $group = 'Email') {
$captured_emails = $this->container->get('state')->get('system.test_mail_collector') ?: [];
$email = end($captured_emails);
return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, $group);
$this->assertIsArray($email, $message);
$this->assertArrayHasKey($name, $email, $message);
$this->assertEquals($value, $email[$name], $message);
return TRUE;
}
/**
......
......@@ -269,7 +269,8 @@ public function testBigPipeNoJs() {
$this->assertNoRaw(BigPipe::STOP_SIGNAL);
// Verifying BigPipe assets are absent.
$this->assertTrue(!isset($this->getDrupalSettings()['bigPipePlaceholderIds']) && empty($this->getDrupalSettings()['ajaxPageState']), 'BigPipe drupalSettings and BigPipe asset library absent.');
$this->assertArrayNotHasKey('bigPipePlaceholderIds', $this->getDrupalSettings());
$this->assertArrayNotHasKey('ajaxPageState', $this->getDrupalSettings());
$this->assertRaw('</body>');
// Verify that 4xx responses work fine. (4xx responses are handled by
......
......@@ -207,7 +207,9 @@ public function testBlockViewBuilderViewAlter() {
$build = $this->getBlockRenderArray();
$this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before rendering.');
$this->assertIdentical((string) $this->renderer->renderRoot($build), 'Hiya!<br>');
$this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!<br>', 'A cached block without content is altered.');
// Check that a cached block without content is altered.
$this->assertArrayHasKey('#prefix', $build);
$this->assertSame('Hiya!<br>', $build['#prefix']);
}
/**
......
......@@ -40,14 +40,16 @@ public function testBlockMigration() {
/** @var \Drupal\block_content\Entity\BlockContent $block */
$block = BlockContent::load(1);
$this->assertIdentical('My block 1', $block->label());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
$this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
$this->assertIdentical('en', $block->language()->getId());
$this->assertIdentical('<h3>My first custom block body</h3>', $block->body->value);
$this->assertIdentical('full_html', $block->body->format);
$block = BlockContent::load(2);
$this->assertIdentical('My block 2', $block->label());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
$this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
$this->assertIdentical('en', $block->language()->getId());
$this->assertIdentical('<h3>My second custom block body</h3>', $block->body->value);
$this->assertIdentical('full_html', $block->body->format);
......
......@@ -101,8 +101,8 @@ public function testCommentInterface() {
// Test changing the comment author to "Anonymous".
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => '']);
$this->assertTrue($comment->getAuthorName() == 'Anonymous', 'Comment author successfully changed to anonymous.');
$this->assertTrue($comment->getOwnerId() == 0, 'Comment author successfully changed to anonymous.');
$this->assertSame('Anonymous', $comment->getAuthorName());
$this->assertEquals(0, $comment->getOwnerId());
// Test changing the comment author to an unverified user.
$random_name = $this->randomMachineName();
......@@ -114,7 +114,8 @@ public function testCommentInterface() {
// Test changing the comment author to a verified user.
$this->drupalGet('comment/' . $comment->id() . '/edit');
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getAccountName() . ' (' . $this->webUser->id() . ')']);
$this->assertTrue($comment->getAuthorName() == $this->webUser->getAccountName() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.');
$this->assertSame($this->webUser->getAccountName(), $comment->getAuthorName());
$this->assertSame($this->webUser->id(), $comment->getOwnerId());
$this->drupalLogout();
......
......@@ -176,7 +176,8 @@ public function postComment(EntityInterface $entity, $comment, $subject = '', $c
$this->assertText($subject, 'Comment subject posted.');
}
$this->assertText($comment, 'Comment body posted.');
$this->assertTrue((!empty($match) && !empty($match[1])), 'Comment ID found.');
// Check the comment ID was extracted.
$this->assertArrayHasKey(1, $match);
}
if (isset($match[1])) {
......
......@@ -175,7 +175,8 @@ public function postComment($entity, $comment, $subject = '', $contact = NULL, $
$this->assertText($subject, 'Comment subject posted.');
}
$this->assertText($comment, 'Comment body posted.');
$this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.');
// Check the comment ID was extracted.
$this->assertArrayHasKey(1, $match);
}
if (isset($match[1])) {
......
......@@ -70,8 +70,7 @@ public function testInstallProfileConfigOverwrite() {
$config = $this->config('system.site');
// Verify the system.site config has a valid UUID.
$site_uuid = $config->get('uuid');
$this->assertTrue(Uuid::isValid($site_uuid) && strlen($site_uuid) > 0, "Site UUID '$site_uuid' is valid");
$this->assertTrue(Uuid::isValid($config->get('uuid')));
// Verify the profile overrides have been used.
$this->assertEquals(91, $config->get('weight_select_max'));
// Ensure the site configure form is used.
......
......@@ -148,7 +148,8 @@ public function testSettingsUI() {
$field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name');
$this->assertTrue($field_override->isTranslatable(), 'Base fields can be overridden with a base field bundle override entity.');
$definitions = $entity_field_manager->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
$this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Base field bundle overrides were correctly altered.');
$this->assertTrue($definitions['name']->isTranslatable());
$this->assertFalse($definitions['user_id']->isTranslatable());
// Test that language settings are correctly stored.
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_article');
......
......@@ -62,7 +62,8 @@ public function testNoEditorAvailable() {
$roles_pos = strpos($raw_content, 'Roles');
$editor_pos = strpos($raw_content, 'Text editor');
$filters_pos = strpos($raw_content, 'Enabled filters');
$this->assertTrue($roles_pos < $editor_pos && $editor_pos < $filters_pos, '"Text Editor" select appears in the correct location of the text format configuration UI.');
$this->assertGreaterThan($roles_pos, $editor_pos);
$this->assertLessThan($filters_pos, $editor_pos);
// Verify the <select>.
$select = $this->xpath('//select[@name="editor[editor]"]');
......
......@@ -266,8 +266,9 @@ public function testPurgeWithDeletedAndActiveField() {
// The field still exists, deleted, with the same field name.
$fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $deleted_field_uuid, 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted');
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name);
$this->assertArrayHasKey($deleted_field_uuid, $fields);
$this->assertTrue($fields[$deleted_field_uuid]->isDeleted());
$this->assertSame($field_name, $fields[$deleted_field_uuid]->getName());
for ($i = 0; $i < 10; $i++) {
$entity = $this->container->get('entity_type.manager')
......@@ -397,7 +398,8 @@ public function testPurgeFieldStorage() {
// The field still exists, deleted.
$fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted');
$this->assertArrayHasKey($field->uuid(), $fields);
$this->assertTrue($fields[$field->uuid()]->isDeleted());
// Purge again to purge the field.
field_purge_batch(0);
......@@ -407,7 +409,8 @@ public function testPurgeFieldStorage() {
$this->assertCount(0, $fields, 'The field is purged.');
// The field storage still exists, not deleted.
$storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is not deleted');
$this->assertArrayHasKey($field_storage->uuid(), $storages);
$this->assertFalse($storages[$field_storage->uuid()]->isDeleted());
// Delete the second field.
$bundle = next($this->bundles);
......@@ -429,9 +432,11 @@ public function testPurgeFieldStorage() {
// The field and the storage still exist, deleted.
$fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted');
$this->assertArrayHasKey($field->uuid(), $fields);
$this->assertTrue($fields[$field->uuid()]->isDeleted());
$storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is deleted');
$this->assertArrayHasKey($field_storage->uuid(), $storages);
$this->assertTrue($storages[$field_storage->uuid()]->isDeleted());
// Purge again to purge the field and the storage.
field_purge_batch(0);
......
......@@ -284,7 +284,7 @@ public function testDeleteFieldNoData() {
// Test that the first field is not deleted, and then delete it.
$field = current(\Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]));
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
$this->assertFalse($field->isDeleted());
$field->delete();
// Make sure the field was deleted without being marked for purging as there
......@@ -298,7 +298,7 @@ public function testDeleteFieldNoData() {
// Make sure the other field is not deleted.
$another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
$this->assertTrue(!empty($another_field) && !$another_field->isDeleted(), 'A non-deleted field is not marked for deletion.');
$this->assertFalse($another_field->isDeleted());
}
/**
......
......@@ -319,7 +319,7 @@ public function testDeleteNoData() {
// Test that the first field is not deleted, and then delete it.
$field_storage_config_storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
$field_storage = current($field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]));
$this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage is not marked for deletion.');
$this->assertFalse($field_storage->isDeleted());
FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
// Make sure that the field storage is deleted as it had no data.
......@@ -341,18 +341,18 @@ public function testDeleteNoData() {
// Make sure the other field and its storage are not deleted.
$another_field_storage = FieldStorageConfig::load('entity_test.' . $another_field_storage_definition['field_name']);
$this->assertTrue(!empty($another_field_storage) && !$another_field_storage->isDeleted(), 'A non-deleted storage is not marked for deletion.');
$this->assertFalse($another_field_storage->isDeleted());
$another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
$this->assertTrue(!empty($another_field) && !$another_field->isDeleted(), 'A field whose storage was not deleted is not marked for deletion.');
$this->assertFalse($another_field->isDeleted());
// Try to create a new field the same name as a deleted field and
// write data into it.
FieldStorageConfig::create($field_storage_definition)->save();
FieldConfig::create($field_definition)->save();
$field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
$this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage with a previously used name is created.');
$this->assertFalse($field_storage->isDeleted());
$field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
$this->assertTrue(!empty($field) && !$field->isDeleted(), 'A new field for a previously used field name is created.');
$this->assertFalse($field->isDeleted());
// Save an entity with data for the field
$entity = EntityTest::create();
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\language\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -72,21 +71,24 @@ public function testDefaultConfiguration() {
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
$this->assertSame($last_content_language, $last_interface_language);
$this->assertSame($translation->language()->getId(), $last_content_language);
$translation = $this->entity->getTranslation('es');
$this->drupalGet($translation->toUrl());
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
$this->assertSame($last_content_language, $last_interface_language);
$this->assertSame($translation->language()->getId(), $last_content_language);
$translation = $this->entity->getTranslation('fr');
$this->drupalGet($translation->toUrl());
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
$this->assertSame($last_content_language, $last_interface_language);
$this->assertSame($translation->language()->getId(), $last_content_language);
}
/**
......@@ -137,7 +139,11 @@ public function testEnabledLanguageContentNegotiator() {
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this->assertTrue(($last_interface_language == $default_site_langcode) && ($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), 'Interface language and Content language are the same as the default translation language of the entity.');
// Check that interface language and content language are the same as the
// default translation language of the entity.
$this->assertSame($default_site_langcode, $last_interface_language);
$this->assertSame($last_content_language, $last_interface_language);
$this->assertSame($translation->language()->getId(), $last_content_language);
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
......
......@@ -139,7 +139,9 @@ public function testConfigTranslation() {
$string = $this->storage->findString(['source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration']);
$this->assertNotEmpty($string, 'Configuration strings have been created upon installation.');
$locations = $string->getLocations();
$this->assertTrue(isset($locations['configuration']) && isset($locations['configuration']['image.style.medium']), 'Configuration string has been created with the right location');
// Check the configuration string has been created with the right location.
$this->assertArrayHasKey('configuration', $locations);
$this->assertArrayHasKey('image.style.medium', $locations['configuration']);
// Check the string is unique and has no translation yet.
$translations = $this->storage->getTranslations(['language' => $this->langcode, 'type' => 'configuration', 'name' => 'image.style.medium']);
......
......@@ -103,8 +103,8 @@ public function testFileParsing() {
$this->assertTrue(isset($source_strings[$str]), new FormattableMarkup('Found source string: %source', $args));
// Make sure that the proper context was matched.
$message = $context ? new FormattableMarkup('Context for %source is %context', $args) : new FormattableMarkup('Context for %source is blank', $args);
$this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, $message);
$this->assertArrayHasKey($str, $source_strings);
$this->assertSame($context, $source_strings[$str]);
}
$this->assertSame(count($test_strings), count($source_strings), 'Found correct number of source strings.');
......
......@@ -144,13 +144,15 @@ public function testStringTranslation() {
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this->assertRaw($translation_to_en);
$this->assertTrue($name != $translation && t($name, [], ['langcode' => $langcode]) == $translation, 't() works for non-English.');
$this->assertNotEquals($translation, $name);
$this->assertEquals($translation, t($name, [], ['langcode' => $langcode]), 't() works for non-English.');
// Refresh the locale() cache to get fresh data from t() below. We are in
// the same HTTP request and therefore t() is not refreshed by saving the
// translation above.
$this->container->get('string_translation')->reset();
// Now we should get the proper fresh translation from t().
$this->assertTrue($name != $translation_to_en && t($name, [], ['langcode' => 'en']) == $translation_to_en, 't() works for English.');
$this->assertNotEquals($translation_to_en, $name);
$this->assertEquals($translation_to_en, t($name, [], ['langcode' => 'en']), 't() works for English.');
$this->assertTrue(t($name, [], ['langcode' => LanguageInterface::LANGCODE_SYSTEM]) == $name, 't() works for LanguageInterface::LANGCODE_SYSTEM.');
$search = [
......
......@@ -147,11 +147,17 @@ public function testStringSearchApi() {
// Try quick search function with different field combinations.
$langcode = 'es';
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source1->source, 'context' => $source1->context]);
$this->assertTrue($found && isset($found->language) && isset($found->translation) && !$found->isNew(), 'Translation not found searching by source and context.');
$this->assertNotNull($found, 'Translation not found searching by source and context.');
$this->assertNotNull($found->language);
$this->assertNotNull($found->translation);
$this->assertFalse($found->isNew());
$this->assertEquals($translate1[$langcode]->translation, $found->translation);
// Now try a translation not found.
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source3->source, 'context' => $source3->context]);
$this->assertTrue($found && $found->lid == $source3->lid && !isset($found->translation) && $found->isNew());
$this->assertNotNull($found);
$this->assertSame($source3->lid, $found->lid);
$this->assertNull($found->translation);
$this->assertTrue($found->isNew());
// Load all translations. For next queries we'll be loading only translated
// strings.
......
......@@ -83,7 +83,8 @@ public function testMultilingualNodeForm() {
// Check that the node exists in the database.
$node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->assertNotEmpty($node, 'Node found in database.');
$this->assertTrue($node->language()->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly set.');
$this->assertSame($langcode, $node->language()->getId());
$this->assertSame($body_value, $node->body->value);
// Change node language.
$langcode = 'it';
......@@ -95,7 +96,8 @@ public function testMultilingualNodeForm() {
$this->drupalPostForm(NULL, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit[$title_key], TRUE);
$this->assertNotEmpty($node, 'Node found in database.');
$this->assertTrue($node->language()->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly changed.');
$this->assertSame($langcode, $node->language()->getId());
$this->assertSame($body_value, $node->body->value);
// Enable content language URL detection.
$this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, [LanguageNegotiationUrl::METHOD_ID => 0]);
......
......@@ -1210,9 +1210,14 @@ protected function assertPatchProtectedFieldNamesStructure() {
$is_null_or_string = function ($value) {
return is_null($value) || is_string($value);
};
$keys_are_field_names = Inspector::assertAllStrings(array_keys(static::$patchProtectedFieldNames));
$values_are_expected_access_denied_reasons = Inspector::assertAll($is_null_or_string, static::$patchProtectedFieldNames);
$this->assertTrue($keys_are_field_names && $values_are_expected_access_denied_reasons, 'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.');
$this->assertTrue(
Inspector::assertAllStrings(array_keys(static::$patchProtectedFieldNames)),
'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
);
$this->assertTrue(
Inspector::assertAll($is_null_or_string, static::$patchProtectedFieldNames),
'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
);
}
/**
......
......@@ -611,7 +611,8 @@ public function testLivePreview() {
$build = $view->preview();
$rendered_json = $build['#plain_text'];
$this->assertTrue(!isset($build['#markup']) && $rendered_json == $expected, 'Ensure the previewed json is escaped.');
$this->assertArrayNotHasKey('#markup', $build);
$this->assertSame($expected, $rendered_json, 'Ensure the previewed json is escaped.');
$view->destroy();
$expected = $serializer->serialize($entities, 'xml');
......
......@@ -101,12 +101,10 @@ public function testFormRefill() {
// Verify that all of the form fields are filled out.
foreach ($edit as $key => $value) {
if ($key != 'type[page]') {
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
$this->assertTrue(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is set to $value");
$this->assertSession()->fieldValueEquals($key, $value);
}
else {
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
$this->assertTrue(isset($elements[0]) && !empty($elements[0]->getAttribute('checked')), "Field $key is checked");
$this->assertSession()->checkboxChecked($key);
}
}
......
......@@ -59,7 +59,9 @@ public function testJavaScriptOrdering() {
$content = $this->getSession()->getPage()->getContent();
$position1 = strpos($content, 'core/misc/vertical-tabs.js');
$position2 = strpos($content, 'core/misc/collapse.js');
$this->assertTrue($position1 !== FALSE && $position2 !== FALSE && $position1 < $position2, 'vertical-tabs.js is included before collapse.js');
$this->assertNotFalse($position1);
$this->assertNotFalse($position2);
$this->assertGreaterThan($position1, $position2, 'vertical-tabs.js is included before collapse.js');
}
/**
......
......@@ -109,7 +109,8 @@ public function testDependencyResolution() {
$this->assertTrue($result, 'ModuleInstaller::install() returns the correct value.');
// Verify that the fake dependency chain was installed.
$this->assertTrue($this->moduleHandler()->moduleExists('config') && $this->moduleHandler()->moduleExists('help'), 'Dependency chain was installed.');
$this->assertTrue($this->moduleHandler()->moduleExists('config'));
$this->assertTrue($this->moduleHandler()->moduleExists('help'));
// Verify that the original module was installed.
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with dependencies succeeded.');
......@@ -140,7 +141,8 @@ public function testDependencyResolution() {
$this->assertTrue($result, 'ModuleInstaller::install() returns the correct value.');
// Verify that the fake dependency chain was installed.
$this->assertTrue($this->moduleHandler()->moduleExists('config') && $this->moduleHandler()->moduleExists('help'), 'Dependency chain was installed.');
$this->assertTrue($this->moduleHandler()->moduleExists('config'));
$this->assertTrue($this->moduleHandler()->moduleExists('help'));
// Verify that the original module was installed.
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with version dependencies succeeded.');
......
......@@ -128,7 +128,8 @@ public function testTaxonomyTermHierarchy() {
$term2->parent = [$term1->id(), $term3->id()];
$term2->save();
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
$this->assertArrayHasKey($term1->id(), $parents);
$this->assertArrayHasKey($term3->id(), $parents);
}
/**
......
......@@ -69,7 +69,8 @@ public function testUserCancelWithoutPermission() {
// Confirm user's content has not been altered.
$node_storage->resetCache([$node->id()]);
$test_node = $node_storage->load($node->id());
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
$this->assertEquals($account->id(), $test_node->getOwnerId(), 'Node of the user has not been altered.');
$this->assertTrue($test_node->isPublished());
}
/**
......@@ -164,7 +165,8 @@ public function testUserCancelInvalid() {
// Confirm user's content has not been altered.
$node_storage->resetCache([$node->id()]);
$test_node = $node_storage->load($node->id());
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
$this->assertEquals($account->id(), $test_node->getOwnerId(), 'Node of the user has not been altered.');
$this->assertTrue($test_node->isPublished());
}
/**
......@@ -342,17 +344,21 @@ public function testUserAnonymize() {
$anonymous_user = User::getAnonymousUser();
$node_storage->resetCache([$node->id()]);
$test_node = $node_storage->load($node->id());
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.');
$this->assertEquals(0, $test_node->getOwnerId(), 'Node of the user has been attributed to anonymous user.');
$this->assertTrue($test_node->isPublished());
$test_node = node_revision_load($revision, TRUE);
$this->assertTrue(($test_node->getRevisionUser()->id() == 0 && $test_node->isPublished()), 'Node revision of the user has been attributed to anonymous user.');
$this->assertEquals(0, $test_node->getRevisionUser()->id(), 'Node revision of the user has been attributed to anonymous user.');
$this->assertTrue($test_node->isPublished());
$node_storage->resetCache([$revision_node->id()]);
$test_node = $node_storage->load($revision_node->id());
$this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user.");
$this->assertNotEquals(0, $test_node->getOwnerId(), "Current revision of the user's node was not attributed to anonymous user.");
$this->assertTrue($test_node->isPublished());
$storage = \Drupal::entityTypeManager()->getStorage('comment');
$storage->resetCache([$comment->id()]);
$test_comment = $storage->load($comment->id());
$this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.');
$this->assertEquals(0, $test_comment->getOwnerId(), 'Comment of the user has been attributed to anonymous user.');
$this->assertTrue($test_comment->isPublished());
$this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.');
// Confirm that the confirmation message made it through to the end user.
......@@ -402,7 +408,8 @@ public function testUserAnonymizeBatch() {
$node_storage->resetCache(array_keys($nodes));
$test_nodes = $node_storage->loadMultiple(array_keys($nodes));
foreach ($test_nodes as $test_node) {
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node ' . $test_node->id() . ' of the user has been attributed to anonymous user.');
$this->assertEquals(0, $test_node->getOwnerId(), 'Node ' . $test_node->id() . ' of the user has been attributed to anonymous user.');
$this->assertTrue($test_node->isPublished());
}
}
......
......@@ -73,7 +73,9 @@ public function testItemsPerPage() {
$pos4 = strpos($content, $node4->label());
$pos3 = strpos($content, $node3->label());
$pos2 = strpos($content, $node2->label());
$this->assertTrue($pos5 < $pos4 && $pos4 < $pos3 && $pos3 < $pos2, 'The nodes appear in the expected order in the page display.');
$this->assertGreaterThan($pos5, $pos4);
$this->assertGreaterThan($pos4, $pos3);
$this->assertGreaterThan($pos3, $pos2);
// Confirm that the block is listed in the block administration UI.
$this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
......@@ -95,7 +97,8 @@ public function testItemsPerPage() {
$pos5 = strpos($content, $node5->label());
$pos4 = strpos($content, $node4->label());
$pos3 = strpos($content, $node3->label());
$this->assertTrue($pos5 < $pos4 && $pos4 < $pos3, 'The nodes appear in the expected order in the block display.');
$this->assertGreaterThan($pos5, $pos4);
$this->assertGreaterThan($pos4, $pos3);
}
}
......@@ -54,7 +54,8 @@ public function testSorting() {
$pos1 = strpos($content, $node1->label());
$pos2 = strpos($content, $node2->label());
$pos3 = strpos($content, $node3->label());
$this->assertTrue($pos1 < $pos2 && $pos2 < $pos3, 'The nodes appear in the expected order in a view that sorts by oldest first.');
$this->assertGreaterThan($pos1, $pos2);
$this->assertGreaterThan($pos2, $pos3);
// Create a view that sorts newest first.
$view2 = [];
......@@ -79,7 +80,8 @@ public function testSorting() {
$pos3 = strpos($content, $node3->label());
$pos2 = strpos($content, $node2->label());
$pos1 = strpos($content, $node1->label());
$this->assertTrue($pos3 < $pos2 && $pos2 < $pos1, 'The nodes appear in the expected order in a view that sorts by newest first.');
$this->assertGreaterThan($pos3, $pos2);
$this->assertGreaterThan($pos2, $pos1);
}
}
......@@ -163,7 +163,7 @@ public function testFetchBaseTables() {
for ($i = 1; $i < count($base_tables); ++$i) {
$prev = $base_tables[$base_tables_keys[$i - 1]];
$current = $base_tables[$base_tables_keys[$i]];
$this->assertTrue($prev['weight'] <= $current['weight'] && $prev['title'] <= $prev['title'], 'The tables are sorted as expected.');
$this->assertGreaterThanOrEqual($prev['weight'], $current['weight']);
}
//