Commit a0500293 authored by catch's avatar catch
Browse files

Issue #3135538 by mondrake, longwave, jungle: Replace remaining assert*...

Issue #3135538 by mondrake, longwave, jungle: Replace remaining assert* involving use of count() where relevant
parent c71e7e4e
......@@ -387,14 +387,14 @@ protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholde
$placeholders = array_map(function (NodeElement $element) {
return $element->getAttribute('data-big-pipe-placeholder-id');
}, $this->cssSelect('[data-big-pipe-placeholder-id]'));
$this->assertEqual(count($expected_big_pipe_placeholders), count(array_unique($placeholders)));
$this->assertSame(count($expected_big_pipe_placeholders), count(array_unique($placeholders)));
$expected_big_pipe_placeholders_with_replacements = [];
foreach ($expected_big_pipe_placeholder_stream_order as $big_pipe_placeholder_id) {
$expected_big_pipe_placeholders_with_replacements[$big_pipe_placeholder_id] = $expected_big_pipe_placeholders[$big_pipe_placeholder_id];
}
$this->assertEqual($expected_big_pipe_placeholders_with_replacements, array_filter($expected_big_pipe_placeholders));
$this->assertSetsEqual(array_keys($expected_big_pipe_placeholders_with_replacements), array_values($placeholder_replacement_positions));
$this->assertEqual(count($expected_big_pipe_placeholders_with_replacements), preg_match_all('/' . preg_quote('<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="', '/') . '/', $this->getSession()->getPage()->getContent()));
$this->assertSame(count($expected_big_pipe_placeholders_with_replacements), preg_match_all('/' . preg_quote('<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="', '/') . '/', $this->getSession()->getPage()->getContent()));
$this->pass('Verifying BigPipe start/stop signals…', 'Debug');
$this->assertRaw(BigPipe::START_SIGNAL, 'BigPipe start signal present.');
......
......@@ -63,7 +63,7 @@ public function testNewDefaultThemeBlocks() {
$new_blocks = $block_storage->getQuery()
->condition('theme', $new_theme)
->execute();
$this->assertEquals(count($default_block_names), count($new_blocks));
$this->assertSame(count($default_block_names), count($new_blocks));
foreach ($default_block_names as $default_block_name) {
// Remove the matching block from the list of blocks in the new theme.
......
......@@ -326,16 +326,14 @@ public function testGetTableOfContents() {
/** @var \Drupal\book\BookManagerInterface $manager */
$manager = $this->container->get('book.manager');
$options = $manager->getTableOfContents($book->id(), 3);
// Verify that all expected option keys are present.
$expected_nids = [$book->id(), $nodes[0]->id(), $nodes[1]->id(), $nodes[2]->id(), $nodes[3]->id(), $nodes[6]->id(), $nodes[4]->id()];
$this->assertEqual(count($options), count($expected_nids));
$diff = array_diff($expected_nids, array_keys($options));
$this->assertTrue(empty($diff), 'Found all expected option keys');
$this->assertEquals($expected_nids, array_keys($options));
// Exclude Node 3.
$options = $manager->getTableOfContents($book->id(), 3, [$nodes[3]->id()]);
// Verify that expected option keys are present after excluding Node 3.
$expected_nids = [$book->id(), $nodes[0]->id(), $nodes[1]->id(), $nodes[2]->id(), $nodes[4]->id()];
$this->assertEqual(count($options), count($expected_nids));
$diff = array_diff($expected_nids, array_keys($options));
$this->assertTrue(empty($diff), 'Found all expected option keys after excluding Node 3');
$this->assertEquals($expected_nids, array_keys($options));
}
/**
......
......@@ -136,7 +136,7 @@ public function testBlockDisplay() {
$this->assertIdenticalResultset($view, $expected_result, $map);
// Check the number of results given by the display is the expected.
$this->assertEqual(count($view->result), $this->blockDisplayResults,
$this->assertCount($this->blockDisplayResults, $view->result,
new FormattableMarkup('There are exactly @results comments. Expected @expected',
['@results' => count($view->result), '@expected' => $this->blockDisplayResults]
)
......
......@@ -101,7 +101,7 @@ public function testContactLink() {
*/
public function assertContactLinks(array $accounts, array $names) {
$result = $this->xpath('//div[contains(@class, "views-field-contact")]//a');
$this->assertEqual(count($result), count($names));
$this->assertSame(count($names), count($result));
foreach ($names as $name) {
$account = $accounts[$name];
......
......@@ -64,7 +64,7 @@ public function checkHooksInvocations($expected_hooks, $actual_hooks) {
$actual_invocations = $actual_hooks[$hook];
// Check that the number of invocations is correct.
$this->assertEqual(count($actual_invocations), count($invocations), "$hook() was called the expected number of times.");
$this->assertSame(count($invocations), count($actual_invocations), "$hook() was called the expected number of times.");
// Check that the hook was called for each expected argument.
foreach ($invocations as $argument) {
......@@ -336,7 +336,7 @@ public function testPurgeField() {
->condition('type', $bundle)
->condition($field_name . '.deleted', 1)
->execute();
$this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2');
$this->assertCount($count, $found, 'Correct number of entities found after purging 2');
}
// Check hooks invocations.
......
......@@ -52,7 +52,7 @@ public function testFieldAttachSaveLoad() {
$entity = $storage->load($entity_id);
// Confirm current revision loads the correct data.
// Number of values per field loaded equals the field cardinality.
$this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, 'Current revision: expected number of values');
$this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, 'Current revision: expected number of values');
for ($delta = 0; $delta < $cardinality; $delta++) {
// The field value loaded matches the one inserted or updated.
$this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$current_revision][$delta]['value'], new FormattableMarkup('Current revision: expected value %delta was found.', ['%delta' => $delta]));
......@@ -62,7 +62,7 @@ public function testFieldAttachSaveLoad() {
foreach (array_keys($values) as $revision_id) {
$entity = $storage->loadRevision($revision_id);
// Number of values per field loaded equals the field cardinality.
$this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id]));
$this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id]));
for ($delta = 0; $delta < $cardinality; $delta++) {
// The field value loaded matches the one inserted or updated.
$this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], new FormattableMarkup('Revision %revision_id: expected value %delta was found.', ['%revision_id' => $revision_id, '%delta' => $delta]));
......@@ -256,7 +256,7 @@ public function testFieldAttachDelete() {
// Confirm each revision loads
foreach ($vids as $vid) {
$revision = $controller->loadRevision($vid);
$this->assertEqual(count($revision->{$this->fieldTestData->field_name}), $cardinality, "The test entity revision $vid has $cardinality values.");
$this->assertCount($cardinality, $revision->{$this->fieldTestData->field_name}, "The test entity revision $vid has $cardinality values.");
}
// Delete revision 1, confirm the other two still load.
......@@ -265,13 +265,13 @@ public function testFieldAttachDelete() {
foreach ([0, 2] as $key) {
$vid = $vids[$key];
$revision = $controller->loadRevision($vid);
$this->assertEqual(count($revision->{$this->fieldTestData->field_name}), $cardinality, "The test entity revision $vid has $cardinality values.");
$this->assertCount($cardinality, $revision->{$this->fieldTestData->field_name}, "The test entity revision $vid has $cardinality values.");
}
// Confirm the current revision still loads
$controller->resetCache();
$current = $controller->load($entity->id());
$this->assertEqual(count($current->{$this->fieldTestData->field_name}), $cardinality, "The test entity current revision has $cardinality values.");
$this->assertCount($cardinality, $current->{$this->fieldTestData->field_name}, "The test entity current revision has $cardinality values.");
// Delete all field data, confirm nothing loads
$entity->delete();
......@@ -308,7 +308,7 @@ public function testEntityCreateBundle() {
// Verify the field data is present on load.
$entity = $this->entitySaveReload($entity);
$this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, "Data is retrieved for the new bundle");
$this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, "Data is retrieved for the new bundle");
}
/**
......
......@@ -139,7 +139,7 @@ public function testEntityCountAndHasData() {
$storage = $this->container->get('entity_type.manager')->getStorage($entity_type);
$entity = $storage->loadRevision($first_revision);
$this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision]));
$this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name_2}, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision]));
}
/**
......
......@@ -194,6 +194,8 @@ protected function _generateTestFieldValues($cardinality) {
* (Optional) The name of the column to check. Defaults to 'value'.
*/
protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
$expected_values_count = count($expected_values);
// Re-load the entity to make sure we have the latest changes.
$storage = $this->container->get('entity_type.manager')
->getStorage($entity->getEntityTypeId());
......@@ -204,7 +206,7 @@ protected function assertFieldValues(EntityInterface $entity, $field_name, $expe
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();
$values = $field->getValue();
$this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
$this->assertCount($expected_values_count, $values, 'Expected number of values were saved.');
foreach ($expected_values as $key => $value) {
$this->assertEqual($values[$key][$column], $value, new FormattableMarkup('Value @value was saved correctly.', ['@value' => $value]));
}
......
......@@ -361,7 +361,7 @@ public function testDeleteNoData() {
$entity = $this->entitySaveReload($entity);
// Verify the field is present on load
$this->assertIdentical(count($entity->{$field_storage->getName()}), count($values), "Data in previously deleted field saves and loads correctly");
$this->assertCount(1, $entity->{$field_storage->getName()}, "Data in previously deleted field saves and loads correctly");
foreach ($values as $delta => $value) {
$this->assertEqual($entity->{$field_storage->getName()}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
}
......@@ -452,7 +452,7 @@ public function testUpdate() {
}
// Load back and assert there are $cardinality number of values.
$entity = $this->entitySaveReload($entity);
$this->assertEqual(count($entity->field_update), $field_storage->getCardinality());
$this->assertCount($field_storage->getCardinality(), $entity->field_update);
// Now check the values themselves.
for ($delta = 0; $delta < $cardinality; $delta++) {
$this->assertEqual($entity->field_update[$delta]->value, $delta + 1);
......
......@@ -221,24 +221,24 @@ public function testMultiValuedWidget() {
$client->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $edit);
$node = $node_storage->loadUnchanged($nid);
$this->assertEqual(count($node->{$field_name}), $cardinality, 'More files than allowed could not be saved to node.');
$this->assertCount($cardinality, $node->{$field_name}, 'More files than allowed could not be saved to node.');
$upload_files_node_creation = [$test_file, $test_file];
// Try to upload multiple files, but fewer than the maximum.
$nid = $this->uploadNodeFiles($upload_files_node_creation, $field_name, $type_name, TRUE, []);
$node = $node_storage->loadUnchanged($nid);
$this->assertEqual(count($node->{$field_name}), count($upload_files_node_creation), 'Node was successfully saved with multiple files.');
$this->assertSame(count($upload_files_node_creation), count($node->{$field_name}), 'Node was successfully saved with multiple files.');
// Try to upload exactly the allowed number of files on revision.
$this->uploadNodeFile($test_file, $field_name, $node->id(), 1, [], TRUE);
$node = $node_storage->loadUnchanged($nid);
$this->assertEqual(count($node->{$field_name}), $cardinality, 'Node was successfully revised to maximum number of files.');
$this->assertCount($cardinality, $node->{$field_name}, 'Node was successfully revised to maximum number of files.');
// Try to upload exactly the allowed number of files, new node.
$upload_files = [$test_file, $test_file, $test_file];
$nid = $this->uploadNodeFiles($upload_files, $field_name, $type_name, TRUE, []);
$node = $node_storage->loadUnchanged($nid);
$this->assertEqual(count($node->{$field_name}), $cardinality, 'Node was successfully saved with maximum number of files.');
$this->assertCount($cardinality, $node->{$field_name}, 'Node was successfully saved with maximum number of files.');
}
/**
......
......@@ -58,7 +58,7 @@ protected function assertEntity($id, $label, array $expected_effect_plugins, arr
// Check the number of effects associated with the style.
$effects = $style->getEffects();
$this->assertIdentical(count($effects), count($expected_effect_plugins));
$this->assertSame(count($expected_effect_plugins), count($effects));
$index = 0;
foreach ($effects as $effect) {
......
......@@ -64,6 +64,7 @@ public function testBlockFilter() {
// Get all blocks, for assertions later.
$blocks = $page->findAll('css', '.js-layout-builder-block-link');
$blocks_count = count($blocks);
$categories = $page->findAll('css', '.js-layout-builder-category');
$filter = $assert_session->elementExists('css', '.js-layout-builder-filter');
......@@ -75,7 +76,7 @@ public function testBlockFilter() {
$filter->setValue('a');
$this->assertAnnounceContains($init_message);
$visible_rows = $this->filterVisibleElements($blocks);
$this->assertEquals(count($blocks), count($visible_rows));
$this->assertCount($blocks_count, $visible_rows);
// Get the Content Fields category, which will be closed before filtering.
$contentFieldsCategory = $page->find('named', ['content', 'Content fields']);
......
......@@ -107,7 +107,7 @@ public function testFileParsing() {
$this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, $message);
}
$this->assertEqual(count($source_strings), count($test_strings), 'Found correct number of source strings.');
$this->assertSame(count($test_strings), count($source_strings), 'Found correct number of source strings.');
}
}
......
......@@ -58,7 +58,7 @@ public function testEmbeddedData() {
$this->assertIdentical($results, $data_rows);
// Validate the public APIs.
$this->assertIdentical($source->count(), count($data_rows));
$this->assertSame(count($data_rows), $source->count());
$this->assertIdentical($source->getIds(), $ids);
$expected_fields = [
'key' => 'key',
......
......@@ -404,7 +404,7 @@ public function testProcessRow() {
foreach ($expected as $key => $value) {
$this->assertSame($row->getDestinationProperty($key), $value);
}
$this->assertSame(count($row->getDestination()), count($expected));
$this->assertSame(count($expected), count($row->getDestination()));
}
/**
......
......@@ -98,7 +98,7 @@ public function testMigrationState() {
foreach ($this->stateFileRequired as $module) {
$this->assertArrayHasKey($module, $has_state_file, sprintf("Module '%s' should have a migrate_drupal.yml file", $module));
}
$this->assertEquals(count($this->stateFileRequired), count($has_state_file));
$this->assertSame(count($this->stateFileRequired), count($has_state_file));
}
}
......@@ -129,7 +129,7 @@ public function checkRecords($count, $langcode = 'hu') {
->condition('na.gid', 8888, '=');
$records = $select->execute()->fetchAll();
// Check that the expected record count is returned.
$this->assertEquals(count($records), $count);
$this->assertCount($count, $records);
// The fallback value is 'hu' and should be set to 1. For other languages,
// it should be set to 0. Casting to boolean lets us run that comparison.
foreach ($records as $record) {
......
......@@ -143,7 +143,7 @@ public function testNodeEdit() {
$this->assertRaw('<details class="node-form-author js-form-wrapper form-wrapper" data-drupal-selector="edit-author" id="edit-author" open="open">');
// Only one extra details element should now be open.
$open_details_elements++;
$this->assertEqual(count($this->cssSelect('details[open="open"]')), $open_details_elements, 'Exactly one extra open &lt;details&gt; element found.');
$this->assertCount($open_details_elements, $this->cssSelect('details[open="open"]'), 'Exactly one extra open &lt;details&gt; element found.');
// Edit the same node, save it and verify it's unpublished after unchecking
// the 'Published' boolean_checkbox and clicking 'Save'.
......
......@@ -445,7 +445,7 @@ protected function doUninstallTest() {
$language_count = count(\Drupal::configFactory()->listAll('language.content_settings.'));
\Drupal::service('module_installer')->uninstall(['content_translation']);
$this->rebuildContainer();
$this->assertEqual($language_count, count(\Drupal::configFactory()->listAll('language.content_settings.')), 'Languages have been fixed rather than deleted during content_translation uninstall.');
$this->assertCount($language_count, \Drupal::configFactory()->listAll('language.content_settings.'), 'Languages have been fixed rather than deleted during content_translation uninstall.');
}
/**
......
Supports Markdown
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