Skip to content

Commit

Permalink
Issue #3126965 by jungle, quietone, longwave, mondrake, dww, sja112, …
Browse files Browse the repository at this point in the history
…xjm: [backport] Replace assert* involving count() and an integer literal with assertCount()
  • Loading branch information
catch committed May 21, 2020
1 parent 7c5bfa0 commit b07660b
Show file tree
Hide file tree
Showing 243 changed files with 817 additions and 816 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions modules/aggregator/tests/src/Kernel/FeedValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testValidation() {
]);

$violations = $feed->validate();
$this->assertEqual(count($violations), 0);
$this->assertCount(0, $violations);

$feed->save();

Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions modules/ban/tests/src/Functional/IpAddressBlockingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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);
$query = $connection->select('ban_ip', 'bip');
$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);
}

}
2 changes: 1 addition & 1 deletion modules/big_pipe/tests/src/Functional/BigPipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testProcessPlaceholders(array $placeholders, $method, $route_mat
}
}
else {
$this->assertSame(0, count($processed_placeholders));
$this->assertCount(0, $processed_placeholders);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/block/tests/src/Functional/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions modules/block/tests/src/Functional/Views/DisplayBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand All @@ -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']);

Expand All @@ -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']);

Expand All @@ -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']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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);

// Test Drupal.announce() message when no matches are expected.
$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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,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('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')];
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testDisabledBundle() {

// Make sure that only a single row was inserted into the block table.
$rows = Database::getConnection()->query('SELECT * FROM {block_content_field_data} WHERE id = :id', [':id' => $enabled_block_content->id()])->fetchAll();
$this->assertEqual(1, count($rows));
$this->assertCount(1, $rows);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions modules/block_place/tests/src/Functional/BlockPlaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function testPlacingBlocksAdmin() {
foreach ($visible_regions as $region => $name) {
$block_library_url->setOption('query', ['region' => $region]);
$links = $this->xpath('//a[contains(@href, :href)]', [':href' => $block_library_url->toString()]);
$this->assertEquals(1, count($links));
$this->assertCount(1, $links);

list(, $query_string) = explode('?', $links[0]->getAttribute('href'), 2);
parse_str($query_string, $query_parts);
$this->assertNotEmpty($query_parts['destination']);

// Get the text inside the div->a->span->em.
$demo_block = $this->xpath('//div[@class="block-place-region"]/a/span[text()="Place block in the "]/em[text()="' . $name . '"]');
$this->assertEquals(1, count($demo_block));
$this->assertCount(1, $demo_block);
}
}

Expand Down
8 changes: 4 additions & 4 deletions modules/book/tests/src/Functional/BookBreadcrumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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));
}

Expand All @@ -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();
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions modules/comment/tests/src/Functional/CommentCSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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.');
}

Expand All @@ -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.');
}
Expand Down
4 changes: 2 additions & 2 deletions modules/comment/tests/src/Functional/CommentFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions modules/comment/tests/src/Functional/CommentPreviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ 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();
$submit_button = $this->assertSession()->buttonExists('Save');
$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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b07660b

Please sign in to comment.