Commit 19f9474b authored by catch's avatar catch
Browse files

Issue #2742585 by ZeiP, alexpott, mondrake, klausi, tomasnagy, Krzysztof...

Issue #2742585 by ZeiP, alexpott, mondrake, klausi, tomasnagy, Krzysztof Domański, sokru, kristiaanvandeneynde, dawehner, jeroenbegyn: Deprecate dangerous assertTrue/False() compatibility overrides in PHPUnit Kernel, Functional and FunctionalJavascript tests
parent 32d95ecc
......@@ -33,7 +33,7 @@ public function testActionUninstall() {
$storage = $this->container->get('entity_type.manager')->getStorage('action');
$storage->resetCache(['user_block_user_action']);
$this->assertTrue($storage->load('user_block_user_action'), 'Configuration entity \'user_block_user_action\' still exists after uninstalling action module.');
$this->assertNotEmpty($storage->load('user_block_user_action'), 'Configuration entity \'user_block_user_action\' still exists after uninstalling action module.');
$admin_user = $this->drupalCreateUser(['administer users']);
$this->drupalLogin($admin_user);
......
......@@ -89,7 +89,7 @@ public function testActionConfiguration() {
$this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
$action = Action::load($action_id);
$this->assertFalse($action, 'Make sure the action is gone after being deleted.');
$this->assertNull($action, 'Make sure the action is gone after being deleted.');
}
}
......@@ -221,10 +221,10 @@ public function updateAndDelete(FeedInterface $feed, $expected_count) {
$count_query = \Drupal::entityQuery('aggregator_item')->condition('fid', $feed->id())->count();
$this->updateFeedItems($feed, $expected_count);
$count = $count_query->execute();
$this->assertTrue($count);
$this->assertGreaterThan(0, $count);
$this->deleteFeedItems($feed);
$count = $count_query->execute();
$this->assertTrue($count == 0);
$this->assertEquals(0, $count);
}
/**
......
......@@ -47,7 +47,7 @@ public function testAggregatorFeedImport() {
$this->assertNull($feed->getImage());
// As with getLastCheckedTime(), the etag can change as the fixture is
// updated normally, so assert that its format is correct.
$this->assertTrue(preg_match('/^"[a-z0-9]{32}"$/', $feed->getEtag()));
$this->assertRegExp('/^"[a-z0-9]{32}"$/', $feed->getEtag());
$this->assertIdentical('0', $feed->getLastModified());
}
......
......@@ -40,7 +40,7 @@ public function testIPAddressValidation() {
$edit['ip'] = '1.2.3.3';
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
$ip = $connection->query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $edit['ip']])->fetchField();
$this->assertTrue($ip, 'IP address found in database.');
$this->assertNotEmpty($ip, 'IP address found in database.');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $edit['ip']]), 'IP address was banned.');
// Try to block an IP address that's already blocked.
......@@ -71,7 +71,7 @@ public function testIPAddressValidation() {
$submit_ip = '1.2.3.4';
$this->drupalPostForm('admin/config/people/ban/' . $submit_ip, [], t('Add'));
$ip = $connection->query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $submit_ip])->fetchField();
$this->assertTrue($ip, 'IP address found in database');
$this->assertNotEmpty($ip, 'IP address found in database');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $submit_ip]), 'IP address was banned.');
// Submit your own IP address. This fails, although it works when testing
......
......@@ -46,7 +46,7 @@ public function testBasicAuth() {
$this->assertText($account->getAccountName(), 'Account name is displayed.');
$this->assertResponse('200', 'HTTP response is OK');
$this->mink->resetSessions();
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Cache-Control is not set to public');
$this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName());
......@@ -74,7 +74,7 @@ public function testBasicAuth() {
$this->drupalGet($url);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'No page cache response when requesting a cached page with basic auth credentials.');
}
......
......@@ -356,11 +356,11 @@ public function testBlockValidateErrors() {
$arguments = [':message' => 'Only digits are allowed'];
$pattern = '//div[contains(@class,"messages messages--error")]/div[contains(text()[2],:message)]';
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue($elements, 'Plugin error message found in parent form.');
$this->assertNotEmpty($elements, 'Plugin error message found in parent form.');
$error_class_pattern = '//div[contains(@class,"form-item-settings-digits")]/input[contains(@class,"error")]';
$error_class = $this->xpath($error_class_pattern);
$this->assertTrue($error_class, 'Plugin error class found in parent form.');
$this->assertNotEmpty($error_class, 'Plugin error class found in parent form.');
}
/**
......
......@@ -162,10 +162,10 @@ public function testDeleteBlockDisplay() {
$view->displayHandlers->remove('block_1');
$view->storage->save();
$this->assertFalse($block_storage->load($block_1->id()), 'The block for this display was removed.');
$this->assertFalse($block_storage->load($block_2->id()), 'The block for this display was removed.');
$this->assertTrue($block_storage->load($block_3->id()), 'A block from another view was unaffected.');
$this->assertTrue($block_storage->load($block_4->id()), 'A block from another view was unaffected.');
$this->assertNull($block_storage->load($block_1->id()), 'The block for this display was removed.');
$this->assertNull($block_storage->load($block_2->id()), 'The block for this display was removed.');
$this->assertNotEmpty($block_storage->load($block_3->id()), 'A block from another view was unaffected.');
$this->assertNotEmpty($block_storage->load($block_4->id()), 'A block from another view was unaffected.');
$this->drupalGet('test-page');
$this->assertNoBlockAppears($block_1);
$this->assertNoBlockAppears($block_2);
......@@ -179,8 +179,8 @@ public function testDeleteBlockDisplay() {
$view->displayHandlers->remove('block_1');
$view->storage->save();
$this->assertFalse($block_storage->load($block_3->id()), 'The block for this display was removed.');
$this->assertTrue($block_storage->load($block_4->id()), 'A block from another display on the same view was unaffected.');
$this->assertNull($block_storage->load($block_3->id()), 'The block for this display was removed.');
$this->assertNotEmpty($block_storage->load($block_4->id()), 'A block from another display on the same view was unaffected.');
$this->drupalGet('test-page');
$this->assertNoBlockAppears($block_3);
$this->assertBlockAppears($block_4);
......
......@@ -117,7 +117,7 @@ protected function loadTests() {
$this->assertSame('content', $entity->getRegion());
$this->assertTrue($entity->status());
$this->assertEqual($entity->getTheme(), 'stark');
$this->assertTrue($entity->uuid());
$this->assertNotEmpty($entity->uuid());
}
/**
......
......@@ -156,7 +156,7 @@ protected function verifyRenderCacheHandling() {
$build = $this->getBlockRenderArray();
$cid = 'entity_view:block:test_block:' . implode(':', \Drupal::service('cache_contexts_manager')->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'])->getKeys());
$this->renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->assertNotEmpty($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
// Re-save the block and check that the cache entry has been deleted.
$this->block->save();
......@@ -170,7 +170,7 @@ protected function verifyRenderCacheHandling() {
$build['#block'] = $this->block;
$this->renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->assertNotEmpty($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->block->delete();
$this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was deleted.');
......@@ -307,7 +307,7 @@ protected function assertBlockRenderedWithExpectedCacheability(array $expected_k
$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);
$this->assertTrue($cache_item, 'The block render element has been cached with the expected cache ID.');
$this->assertNotEmpty($cache_item, 'The block render element has been cached with the expected cache ID.');
$this->assertIdentical(Cache::mergeTags($expected_tags, ['rendered']), $cache_item->tags);
$this->assertIdentical($final_cache_contexts, $cache_item->data['#cache']['contexts']);
$this->assertIdentical($expected_tags, $cache_item->data['#cache']['tags']);
......
......@@ -72,7 +72,7 @@ public function testBlockContentCreation() {
->getStorage('block_content')
->loadByProperties(['info' => $edit['info[0][value]']]);
$block = reset($blocks);
$this->assertTrue($block, 'Custom Block found in database.');
$this->assertNotEmpty($block, 'Custom Block found in database.');
// Check that attempting to create another block with the same value for
// 'info' returns an error.
......@@ -154,7 +154,7 @@ public function testBlockContentCreationMultipleViewModes() {
->getStorage('block_content')
->loadByProperties(['info' => $edit['info[0][value]']]);
$block = reset($blocks);
$this->assertTrue($block, 'Custom Block found in database.');
$this->assertNotEmpty($block, 'Custom Block found in database.');
// Check that attempting to create another block with the same value for
// 'info' returns an error.
......@@ -191,7 +191,7 @@ public function testDefaultBlockContentCreation() {
->getStorage('block_content')
->loadByProperties(['info' => $edit['info[0][value]']]);
$block = reset($blocks);
$this->assertTrue($block, 'Default Custom Block found in database.');
$this->assertNotEmpty($block, 'Default Custom Block found in database.');
}
/**
......
......@@ -39,7 +39,7 @@ public function testListing() {
// Test for the table.
$element = $this->xpath('//div[@class="layout-content"]//table');
$this->assertTrue($element, 'Configuration entity list table found.');
$this->assertNotEmpty($element, 'Configuration entity list table found.');
// Test the table header.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
......
......@@ -41,7 +41,7 @@ public function testListing() {
// Test for the table.
$element = $this->xpath('//div[@class="layout-content"]//table');
$this->assertTrue($element, 'Views table found.');
$this->assertNotEmpty($element, 'Views table found.');
// Test the table header.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
......
......@@ -56,7 +56,7 @@ public function testImport() {
// Test the import saved.
$block_by_id = BlockContent::load($test_id);
$this->assertTrue($block_by_id, 'Custom block load by block ID.');
$this->assertNotEmpty($block_by_id, 'Custom block load by block ID.');
$this->assertIdentical($block_by_id->body->value, $block_array['body']['value']);
}
......
......@@ -71,7 +71,7 @@ public function testBlockContentTypeCreation() {
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$block_type = BlockContentType::load('foo');
$this->assertTrue($block_type, 'The new block type has been created.');
$this->assertInstanceOf(BlockContentType::class, $block_type, 'The new block type has been created.');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'foo');
$this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.');
......@@ -90,7 +90,7 @@ public function testBlockContentTypeCreation() {
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
$block_type = BlockContentType::load('other');
$this->assertTrue($block_type, 'The new block type has been created.');
$this->assertInstanceOf(BlockContentType::class, $block_type, 'The new block type has been created.');
$this->drupalGet('block/add/' . $block_type->id());
$this->assertResponse(200);
......
......@@ -40,7 +40,7 @@ public function testPageEdit() {
// Check that the block exists in the database.
$blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute();
$block = BlockContent::load(reset($blocks));
$this->assertTrue($block, 'Custom block found in database.');
$this->assertNotEmpty($block, 'Custom block found in database.');
// Load the edit page.
$this->drupalGet('block/' . $block->id());
......
......@@ -70,7 +70,7 @@ public function testBookWithPendingRevisions() {
];
$this->drupalPostForm('node/add/book', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue($node);
$this->assertNotEmpty($node);
$edit = [
'moderation_state[0][state]' => 'draft',
......
......@@ -61,7 +61,7 @@ public function testExistingFormat() {
// Ensure no Editor config entity exists yet.
$editor = Editor::load('filtered_html');
$this->assertFalse($editor, 'No Editor config entity exists yet.');
$this->assertNull($editor, 'No Editor config entity exists yet.');
// Verify the "Text Editor" <select> when a text editor is available.
$select = $this->xpath('//select[@name="editor[editor]"]');
......@@ -117,7 +117,7 @@ public function testExistingFormat() {
// Keep the "CKEditor" editor selected and click the "Configure" button.
$this->drupalPostForm(NULL, $edit, 'editor_configure');
$editor = Editor::load('filtered_html');
$this->assertFalse($editor, 'No Editor config entity exists yet.');
$this->assertNull($editor, 'No Editor config entity exists yet.');
// Ensure that drupalSettings is correct.
$ckeditor_settings_toolbar = [
......@@ -266,9 +266,9 @@ public function testNewFormat() {
];
$this->drupalPostForm(NULL, $edit, 'editor_configure');
$filter_format = FilterFormat::load('amazing_format');
$this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.');
$this->assertNull($filter_format, 'No FilterFormat config entity exists yet.');
$editor = Editor::load('amazing_format');
$this->assertFalse($editor, 'No Editor config entity exists yet.');
$this->assertNull($editor, 'No Editor config entity exists yet.');
// Ensure the toolbar buttons configuration value is initialized to the
// default value.
......
......@@ -95,19 +95,19 @@ public function testCommentClasses() {
// Verify the by-anonymous class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-anonymous")]');
if ($case['comment_uid'] == 0) {
$this->assertTrue(count($comments) == 1, 'by-anonymous class found.');
$this->assertCount(1, $comments, 'by-anonymous class found.');
}
else {
$this->assertFalse(count($comments), 'by-anonymous class not found.');
$this->assertCount(0, $comments, 'by-anonymous class not found.');
}
// Verify the by-node-author class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-node-author")]');
if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
$this->assertTrue(count($comments) == 1, 'by-node-author class found.');
$this->assertCount(1, $comments, 'by-node-author class found.');
}
else {
$this->assertFalse(count($comments), 'by-node-author class not found.');
$this->assertCount(0, $comments, 'by-node-author class not found.');
}
// Verify the data-comment-user-id attribute, which is used by the
......@@ -121,10 +121,10 @@ public function testCommentClasses() {
// Verify the unpublished class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "unpublished")]');
if ($case['comment_status'] == CommentInterface::NOT_PUBLISHED && $case['user'] == 'admin') {
$this->assertTrue(count($comments) == 1, 'unpublished class found.');
$this->assertCount(1, $comments, 'unpublished class found.');
}
else {
$this->assertFalse(count($comments), 'unpublished class not found.');
$this->assertCount(0, $comments, 'unpublished class not found.');
}
// Verify the data-comment-timestamp attribute, which is used by the
......
......@@ -45,7 +45,7 @@ public function testCommentDefaultFields() {
// Check that the 'comment_body' field is not deleted since it is persisted
// even if it has no fields.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field_storage, 'The comment_body field storage was not deleted');
$this->assertInstanceOf(FieldStorageConfig::class, $field_storage, 'The comment_body field storage was not deleted');
// Create a new content type.
$type_name = 'test_node_type_2';
......@@ -55,7 +55,7 @@ public function testCommentDefaultFields() {
// Check that the 'comment_body' field exists and has an instance on the
// new comment bundle.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field_storage, 'The comment_body field exists');
$this->assertInstanceOf(FieldStorageConfig::class, $field_storage, 'The comment_body field exists');
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this->assertTrue(isset($field), new FormattableMarkup('The comment_body field is present for comments on type @type', ['@type' => $type_name]));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment