Commit 40a5bd7e authored by catch's avatar catch

Issue #3126965 by jungle, quietone, longwave, mondrake, dww: Replace assert*...

Issue #3126965 by jungle, quietone, longwave, mondrake, dww: Replace assert* involving count() and an integer literal with assertCount()
parent 9674c99b
......@@ -72,7 +72,7 @@ public function testOverviewPage() {
$result = $this->xpath('//table/tbody/tr');
// Check if the amount of feeds in the overview matches the amount created.
$this->assertEqual(1, count($result), 'Created feed is found in the overview');
$this->assertCount(1, $result, 'Created feed is found in the overview');
// Check if the fields in the table match with what's expected.
$link = $this->xpath('//table/tbody/tr//td[1]/a');
$this->assertEquals($feed->label(), $link[0]->getText());
......
......@@ -39,7 +39,7 @@ public function testValidation() {
]);
$violations = $feed->validate();
$this->assertEqual(count($violations), 0);
$this->assertCount(0, $violations);
$feed->save();
......@@ -53,7 +53,7 @@ public function testValidation() {
$violations = $feed->validate();
$this->assertEqual(count($violations), 2);
$this->assertCount(2, $violations);
$this->assertEqual($violations[0]->getPropertyPath(), 'title');
$this->assertEqual($violations[0]->getMessage(), t('A feed named %value already exists. Enter a unique title.', [
'%value' => $feed->label(),
......
......@@ -93,7 +93,7 @@ public function testIPAddressValidation() {
$query->fields('bip', ['iid']);
$query->condition('bip.ip', $ip);
$ip_count = $query->execute()->fetchAll();
$this->assertEqual(1, count($ip_count));
$this->assertCount(1, $ip_count);
$ip = '';
$banIp->banIp($ip);
$banIp->banIp($ip);
......@@ -101,7 +101,7 @@ public function testIPAddressValidation() {
$query->fields('bip', ['iid']);
$query->condition('bip.ip', $ip);
$ip_count = $query->execute()->fetchAll();
$this->assertEqual(1, count($ip_count));
$this->assertCount(1, $ip_count);
}
}
......@@ -371,7 +371,7 @@ protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholde
$expected_placeholder_replacement = '<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="' . $big_pipe_placeholder_id . '">';
$result = $this->xpath('//script[@data-big-pipe-replacement-for-placeholder-with-id=:id]', [':id' => Html::decodeEntities($big_pipe_placeholder_id)]);
if ($expected_ajax_response === NULL) {
$this->assertEqual(0, count($result));
$this->assertCount(0, $result);
$this->assertNoRaw($expected_placeholder_replacement);
continue;
}
......
......@@ -54,7 +54,7 @@ public function testProcessPlaceholders(array $placeholders, $method, $route_mat
}
}
else {
$this->assertSame(0, count($processed_placeholders));
$this->assertCount(0, $processed_placeholders);
}
}
......
......@@ -155,7 +155,7 @@ public function testAddBlockFromLibraryWithWeight() {
'theme' => $default_theme,
]);
$links = $this->xpath('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
$this->assertEqual(1, count($links), 'Found one matching link.');
$this->assertCount(1, $links, 'Found one matching link.');
$this->assertEqual(t('Place block'), $links[0]->getText(), 'Found the expected link text.');
list($path, $query_string) = explode('?', $links[0]->getAttribute('href'), 2);
......
......@@ -297,14 +297,14 @@ public function testBlockEmptyRendering() {
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']);
$this->drupalGet('');
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'));
$display = &$view->getDisplay('block_1');
$display['display_options']['block_hide_empty'] = TRUE;
$view->save();
$this->drupalGet($url);
$this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
$this->assertCount(0, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'));
// Ensure that the view cacheability metadata is propagated even, for an
// empty block.
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
......@@ -324,7 +324,7 @@ public function testBlockEmptyRendering() {
$view->save();
$this->drupalGet($url);
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'));
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
......@@ -342,7 +342,7 @@ public function testBlockEmptyRendering() {
$view->save();
$this->drupalGet($url);
$this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
$this->assertCount(0, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'));
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
......@@ -359,7 +359,7 @@ public function testBlockEmptyRendering() {
$view->save();
$this->drupalGet($url);
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'));
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
}
......
......@@ -67,7 +67,7 @@ public function testBlockFilter() {
$filter->setValue('Powered by');
$session->wait(10000, 'jQuery("#drupal-live-announce").html().indexOf("block is available") > -1');
$visible_rows = $this->filterVisibleElements($block_rows);
$this->assertEquals(1, count($visible_rows));
$this->assertCount(1, $visible_rows);
$expected_message = '1 block is available in the modified list.';
$assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
......@@ -75,7 +75,7 @@ public function testBlockFilter() {
$filter->setValue('Pan-Galactic Gargle Blaster');
$session->wait(10000, 'jQuery("#drupal-live-announce").html().indexOf("0 blocks are available") > -1');
$visible_rows = $this->filterVisibleElements($block_rows);
$this->assertEquals(0, count($visible_rows));
$this->assertCount(0, $visible_rows);
$expected_message = '0 blocks are available in the modified list.';
$assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
}
......
......@@ -242,7 +242,7 @@ public function testBlockDelete() {
$block = BlockContent::load(1);
// Test getInstances method.
$this->assertEqual(1, count($block->getInstances()));
$this->assertCount(1, $block->getInstances());
// Navigate to home page.
$this->drupalGet('');
......
......@@ -43,7 +43,7 @@ public function testListing() {
// Test the table header.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
$this->assertEqual(count($elements), 2, 'Correct number of table header cells found.');
$this->assertCount(2, $elements, 'Correct number of table header cells found.');
// Test the contents of each th cell.
$expected_items = [t('Block description'), t('Operations')];
......@@ -69,7 +69,7 @@ public function testListing() {
// Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
$this->assertEqual(count($elements), 2, 'Correct number of table row cells found.');
$this->assertCount(2, $elements, 'Correct number of table row cells found.');
// Check the contents of each row cell. The first cell contains the label,
// the second contains the machine name, and the third contains the
// operations list.
......
......@@ -50,7 +50,7 @@ public function testListing() {
// Test the table header.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
$this->assertCount(4, $elements, 'Correct number of table header cells found.');
// Test the contents of each th cell.
$expected_items = ['Block description', 'Block type', 'Updated Sort ascending', 'Operations'];
......@@ -81,7 +81,7 @@ public function testListing() {
// Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
$this->assertEqual(count($elements), 4, 'Correct number of table row cells found.');
$this->assertCount(4, $elements, 'Correct number of table row cells found.');
// Check the contents of each row cell. The first cell contains the label,
// the second contains the machine name, and the third contains the
// operations list.
......
......@@ -26,7 +26,7 @@ public function testValidation() {
// Validate the block.
$violations = $block->validate();
// Make sure we have no violations.
$this->assertEqual(count($violations), 0);
$this->assertCount(0, $violations);
// Save the block.
$block->save();
......@@ -35,7 +35,7 @@ public function testValidation() {
// Validate this block.
$violations = $block->validate();
// Make sure we have 1 violation.
$this->assertEqual(count($violations), 1);
$this->assertCount(1, $violations);
// Make sure the violation is on the info property
$this->assertEqual($violations[0]->getPropertyPath(), 'info');
// Make sure the message is correct.
......
......@@ -156,7 +156,7 @@ public function testBreadcrumbTitleUpdates() {
$got_breadcrumb[] = $link->getText();
}
// Home link and four parent book nodes should be in the breadcrumb.
$this->assertEqual(5, count($got_breadcrumb));
$this->assertCount(5, $got_breadcrumb);
$this->assertEqual($nodes[3]->getTitle(), end($got_breadcrumb));
$edit = [
'title[0][value]' => 'Updated node5 title',
......@@ -169,7 +169,7 @@ public function testBreadcrumbTitleUpdates() {
foreach ($links as $link) {
$got_breadcrumb[] = $link->getText();
}
$this->assertEqual(5, count($got_breadcrumb));
$this->assertCount(5, $got_breadcrumb);
$this->assertEqual($edit['title[0][value]'], end($got_breadcrumb));
}
......@@ -190,7 +190,7 @@ public function testBreadcrumbAccessUpdates() {
foreach ($links as $link) {
$got_breadcrumb[] = $link->getText();
}
$this->assertEqual(5, count($got_breadcrumb));
$this->assertCount(5, $got_breadcrumb);
$this->assertEqual($edit['title[0][value]'], end($got_breadcrumb));
$config = $this->container->get('config.factory')->getEditable('book_breadcrumb_test.settings');
$config->set('hide', TRUE)->save();
......@@ -200,7 +200,7 @@ public function testBreadcrumbAccessUpdates() {
foreach ($links as $link) {
$got_breadcrumb[] = $link->getText();
}
$this->assertEqual(4, count($got_breadcrumb));
$this->assertCount(4, $got_breadcrumb);
$this->assertEqual($nodes[2]->getTitle(), end($got_breadcrumb));
$this->drupalGet($nodes[3]->toUrl());
$this->assertResponse(403);
......
......@@ -88,7 +88,7 @@ public function testCommentClasses() {
// Verify the data-history-node-id attribute, which is necessary for the
// by-viewer class and the "new" indicator, see below.
$this->assertIdentical(1, count($this->xpath('//*[@data-history-node-id="' . $node->id() . '"]')), 'data-history-node-id attribute is set on node.');
$this->assertCount(1, $this->xpath('//*[@data-history-node-id="' . $node->id() . '"]'), 'data-history-node-id attribute is set on node.');
// Verify classes if the comment is visible for the current user.
if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') {
......@@ -114,7 +114,7 @@ public function testCommentClasses() {
// drupal.comment-by-viewer library to add a by-viewer when the current
// user (the viewer) was the author of the comment. We do this in Java-
// Script to prevent breaking the render cache.
$this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment") and @data-comment-user-id="' . $case['comment_uid'] . '"]')), 'data-comment-user-id attribute is set on comment.');
$this->assertCount(1, $this->xpath('//*[contains(@class, "comment") and @data-comment-user-id="' . $case['comment_uid'] . '"]'), 'data-comment-user-id attribute is set on comment.');
$this->assertRaw(drupal_get_path('module', 'comment') . '/js/comment-by-viewer.js', 'drupal.comment-by-viewer library is present.');
}
......@@ -132,7 +132,7 @@ public function testCommentClasses() {
// comment that was created or changed after the last time the current
// user read the corresponding node.
if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') {
$this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->getChangedTime() . '"]')), 'data-comment-timestamp attribute is set on comment');
$this->assertCount(1, $this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->getChangedTime() . '"]'), 'data-comment-timestamp attribute is set on comment');
$expectedJS = ($case['user'] !== 'anonymous');
$this->assertIdentical($expectedJS, isset($settings['ajaxPageState']['libraries']) && in_array('comment/drupal.comment-new-indicator', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.comment-new-indicator library is present.');
}
......
......@@ -86,13 +86,13 @@ public function testCommentFieldDelete() {
$this->drupalGet('node/' . $node->nid->value);
$elements = $this->cssSelect('.field--type-comment');
$this->assertEqual(2, count($elements), 'There are two comment fields on the node.');
$this->assertCount(2, $elements, 'There are two comment fields on the node.');
// Delete the first comment field.
FieldStorageConfig::loadByName('node', 'comment')->delete();
$this->drupalGet('node/' . $node->nid->value);
$elements = $this->cssSelect('.field--type-comment');
$this->assertEqual(1, count($elements), 'There is one comment field on the node.');
$this->assertCount(1, $elements, 'There is one comment field on the node.');
}
/**
......
......@@ -66,7 +66,7 @@ public function testCommentNewCommentsIndicator() {
// used by the drupal.node-new-comments-link library to determine whether
// a "x new comments" link might be necessary or not. We do this in
// JavaScript to prevent breaking the render cache.
$this->assertIdentical(0, count($this->xpath('//*[@data-history-node-last-comment-timestamp]')), 'data-history-node-last-comment-timestamp attribute is not set.');
$this->assertCount(0, $this->xpath('//*[@data-history-node-last-comment-timestamp]'), 'data-history-node-last-comment-timestamp attribute is not set.');
// Create a new comment. This helper function may be run with different
// comment settings so use $comment->save() to avoid complex setup.
......@@ -94,8 +94,8 @@ public function testCommentNewCommentsIndicator() {
// value, the drupal.node-new-comments-link library would determine that the
// node received a comment after the user last viewed it, and hence it would
// perform an HTTP request to render the "new comments" node link.
$this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->getChangedTime() . '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.');
$this->assertIdentical(1, count($this->xpath('//*[@data-history-node-field-name="comment"]')), 'data-history-node-field-name attribute is set to the correct value.');
$this->assertCount(1, $this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->getChangedTime() . '"]'), 'data-history-node-last-comment-timestamp attribute is set to the correct value.');
$this->assertCount(1, $this->xpath('//*[@data-history-node-field-name="comment"]'), 'data-history-node-field-name attribute is set to the correct value.');
// The data will be pre-seeded on this particular page in drupalSettings, to
// avoid the need for the client to make a separate request to the server.
$settings = $this->getDrupalSettings();
......
......@@ -113,7 +113,7 @@ public function testCommentPreviewDuplicateSubmission() {
$this->drupalPostForm(NULL, [], 'Save');
$this->assertText('Your comment has been posted.');
$elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article');
$this->assertEqual(1, count($elements));
$this->assertCount(1, $elements);
// Go back and re-submit the form.
$this->getSession()->getDriver()->back();
......@@ -121,7 +121,7 @@ public function testCommentPreviewDuplicateSubmission() {
$submit_button->click();
$this->assertText('Your comment has been posted.');
$elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article');
$this->assertEqual(2, count($elements));
$this->assertCount(2, $elements);
}
/**
......
......@@ -30,9 +30,9 @@ public function testCommentOperations() {
$this->drupalGet('test-comment-operations');
$this->assertResponse(200);
$operation = $this->cssSelect('.views-field-operations li.edit a');
$this->assertEqual(count($operation), 1, 'Found edit operation for comment.');
$this->assertCount(1, $operation, 'Found edit operation for comment.');
$operation = $this->cssSelect('.views-field-operations li.delete a');
$this->assertEqual(count($operation), 1, 'Found delete operation for comment.');
$this->assertCount(1, $operation, 'Found delete operation for comment.');
}
}
......@@ -66,7 +66,7 @@ public function testCommentRestExport() {
$contents = Json::decode($this->getSession()->getPage()->getContent());
$this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
$this->assertEqual($contents[1]['subject'], 'A lot, apparently');
$this->assertEqual(count($contents), 2);
$this->assertCount(2, $contents);
// Ensure field-level access is respected - user shouldn't be able to see
// mail or hostname fields.
......
......@@ -28,7 +28,7 @@ public function testCommentRow() {
$this->drupalGet('test-comment-row');
$result = $this->xpath('//article[contains(@class, "comment")]');
$this->assertEqual(1, count($result), 'One rendered comment found.');
$this->assertCount(1, $result, 'One rendered comment found.');
}
}
......@@ -35,7 +35,7 @@ public function testNewComments() {
$this->drupalGet('test-new-comments');
$this->assertResponse(200);
$new_comments = $this->cssSelect(".views-field-new-comments a:contains('1')");
$this->assertEqual(count($new_comments), 1, 'Found the number of new comments for a certain node.');
$this->assertCount(1, $new_comments, 'Found the number of new comments for a certain node.');
}
}
......@@ -31,7 +31,7 @@ public function testRssRow() {
// Because the response is XML we can't use the page which depends on an
// HTML tag being present.
$result = $this->getSession()->getDriver()->find('//item');
$this->assertEqual(count($result), 1, 'Just one comment was found in the rss output.');
$this->assertCount(1, $result, 'Just one comment was found in the rss output.');
$this->assertEqual($result[0]->find('xpath', '//pubDate')->getHtml(), gmdate('r', $this->comment->getCreatedTime()), 'The right pubDate appears in the rss output.');
}
......
......@@ -84,7 +84,7 @@ public function testValidation() {
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment.');
$this->assertCount(0, $violations, 'No violations when validating a default comment.');
$comment->set('subject', $this->randomString(65));
$this->assertLengthViolation($comment, 'subject', 64);
......@@ -99,7 +99,7 @@ public function testValidation() {
$comment->set('name', 'test');
$comment->set('uid', 0);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, "Violation found on author name collision");
$this->assertCount(1, $violations, "Violation found on author name collision");
$this->assertEqual($violations[0]->getPropertyPath(), "name");
$this->assertEqual($violations[0]->getMessage(), t('The name you used (%name) belongs to a registered user.', ['%name' => 'test']));
......@@ -107,7 +107,7 @@ public function testValidation() {
$comment->set('name', 'valid unused name');
$comment->set('mail', 'invalid');
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when email is invalid');
$this->assertCount(1, $violations, 'Violation found when email is invalid');
$this->assertEqual($violations[0]->getPropertyPath(), 'mail.0.value');
$this->assertEqual($violations[0]->getMessage(), t('This value is not a valid email address.'));
......@@ -117,7 +117,7 @@ public function testValidation() {
$comment->set('homepage', 'invalid');
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when homepage is invalid');
$this->assertCount(1, $violations, 'Violation found when homepage is invalid');
$this->assertEqual($violations[0]->getPropertyPath(), 'homepage.0.value');
// @todo This message should be improved in
......@@ -150,7 +150,7 @@ public function testValidation() {
'name' => '',
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when name is required, but empty and UID is anonymous.');
$this->assertCount(1, $violations, 'Violation found when name is required, but empty and UID is anonymous.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('You have to specify a valid author.'));
......@@ -163,7 +163,7 @@ public function testValidation() {
'uid' => $user->id(),
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment with an author.');
$this->assertCount(0, $violations, 'No violations when validating a default comment with an author.');
// Test specifying a wrong author name does not work.
$comment = $this->entityTypeManager->getStorage('comment')->create([
......@@ -175,7 +175,7 @@ public function testValidation() {
'name' => 'not-test',
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when author name and comment author do not match.');
$this->assertCount(1, $violations, 'Violation found when author name and comment author do not match.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('The specified author name does not match the comment author.'));
}
......@@ -192,7 +192,7 @@ public function testValidation() {
*/
protected function assertLengthViolation(CommentInterface $comment, $field_name, $length) {
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, "Violation found when $field_name is too long.");
$this->assertCount(1, $violations, "Violation found when $field_name is too long.");
$this->assertEqual($violations[0]->getPropertyPath(), "$field_name.0.value");
$field_label = $comment->get($field_name)->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', ['%name' => $field_label, '@max' => $length]));
......
......@@ -164,7 +164,7 @@ protected function doTestFilters($display_id) {
$this->assertField('langcode');
$elements = $this->cssSelect('input[type="checkbox"]');
$this->assertEquals(2, count($elements), 'There are two comments on the page.');
$this->assertCount(2, $elements, 'There are two comments on the page.');
$this->assertText($comment->label());
$this->assertText($comment_anonymous->label());
$executable->destroy();
......@@ -176,7 +176,7 @@ protected function doTestFilters($display_id) {
$this->verbose($this->getRawContent());
$elements = $this->cssSelect('input[type="checkbox"]');
$this->assertEquals(1, count($elements), 'Only anonymous comment is visible.');
$this->assertCount(1,