Commit 00f65542 authored by xjm's avatar xjm

Issue #2983458 by seanB, pguillard, msankhala, marcoscano: Use assertSame()...

Issue #2983458 by seanB, pguillard, msankhala, marcoscano: Use assertSame() instead of assertEquals() in Media tests
parent f5f92048
......@@ -63,7 +63,7 @@ public function testBulkForm() {
// Check that all created items are present in the test view.
$view = Views::getView('test_media_bulk_form');
$view->execute();
$this->assertEquals($view->total_rows, 5);
$this->assertSame($view->total_rows, 5);
// Check the operations are accessible to the logged in user.
$this->drupalGet('test-media-bulk-form');
......
......@@ -41,19 +41,19 @@ public function testMediaOverviewPage() {
$assert_session->selectExists('langcode');
$assert_session->buttonExists('Filter');
$header = $assert_session->elementExists('css', 'th#view-thumbnail-target-id-table-column');
$this->assertEquals('Thumbnail', $header->getText());
$this->assertSame('Thumbnail', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-name-table-column');
$this->assertEquals('Media name', $header->getText());
$this->assertSame('Media name', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-bundle-table-column');
$this->assertEquals('Type', $header->getText());
$this->assertSame('Type', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-uid-table-column');
$this->assertEquals('Author', $header->getText());
$this->assertSame('Author', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-status-table-column');
$this->assertEquals('Status', $header->getText());
$this->assertSame('Status', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-changed-table-column');
$this->assertEquals('Updated Sort ascending', $header->getText());
$this->assertSame('Updated Sort ascending', $header->getText());
$header = $assert_session->elementExists('css', 'th#view-operations-table-column');
$this->assertEquals('Operations', $header->getText());
$this->assertSame('Operations', $header->getText());
$assert_session->pageTextContains('No media available.');
// Create some content for the view.
......@@ -97,50 +97,50 @@ public function testMediaOverviewPage() {
// Media names.
$name1 = $assert_session->elementExists('css', 'td.views-field-name a', $row1);
$this->assertEquals($media1->label(), $name1->getText());
$this->assertSame($media1->label(), $name1->getText());
$name2 = $assert_session->elementExists('css', 'td.views-field-name a', $row2);
$this->assertEquals($media2->label(), $name2->getText());
$this->assertSame($media2->label(), $name2->getText());
$name3 = $assert_session->elementExists('css', 'td.views-field-name a', $row3);
$this->assertEquals($media3->label(), $name3->getText());
$this->assertSame($media3->label(), $name3->getText());
$assert_session->linkByHrefExists('/media/' . $media1->id());
$assert_session->linkByHrefExists('/media/' . $media2->id());
$assert_session->linkByHrefExists('/media/' . $media3->id());
// Media types.
$type_element1 = $assert_session->elementExists('css', 'td.views-field-bundle', $row1);
$this->assertEquals($media_type1->label(), $type_element1->getText());
$this->assertSame($media_type1->label(), $type_element1->getText());
$type_element2 = $assert_session->elementExists('css', 'td.views-field-bundle', $row2);
$this->assertEquals($media_type2->label(), $type_element2->getText());
$this->assertSame($media_type2->label(), $type_element2->getText());
$type_element3 = $assert_session->elementExists('css', 'td.views-field-bundle', $row3);
$this->assertEquals($media_type1->label(), $type_element3->getText());
$this->assertSame($media_type1->label(), $type_element3->getText());
// Media authors.
$author_element1 = $assert_session->elementExists('css', 'td.views-field-uid', $row1);
$this->assertEquals($this->adminUser->getDisplayName(), $author_element1->getText());
$this->assertSame($this->adminUser->getDisplayName(), $author_element1->getText());
$author_element2 = $assert_session->elementExists('css', 'td.views-field-uid', $row2);
$this->assertEquals($this->adminUser->getDisplayName(), $author_element2->getText());
$this->assertSame($this->adminUser->getDisplayName(), $author_element2->getText());
$author_element3 = $assert_session->elementExists('css', 'td.views-field-uid', $row3);
$this->assertEquals($this->nonAdminUser->getDisplayName(), $author_element3->getText());
$this->assertSame($this->nonAdminUser->getDisplayName(), $author_element3->getText());
// Media publishing status.
$status_element1 = $assert_session->elementExists('css', 'td.views-field-status', $row1);
$this->assertEquals('Published', $status_element1->getText());
$this->assertSame('Published', $status_element1->getText());
$status_element2 = $assert_session->elementExists('css', 'td.views-field-status', $row2);
$this->assertEquals('Unpublished', $status_element2->getText());
$this->assertSame('Unpublished', $status_element2->getText());
$status_element3 = $assert_session->elementExists('css', 'td.views-field-status', $row3);
$this->assertEquals('Published', $status_element3->getText());
$this->assertSame('Published', $status_element3->getText());
// Timestamp.
$expected = \Drupal::service('date.formatter')->format($media1->getChangedTime(), 'short');
$changed_element1 = $assert_session->elementExists('css', 'td.views-field-changed', $row1);
$this->assertEquals($expected, $changed_element1->getText());
$this->assertSame($expected, $changed_element1->getText());
// Operations.
$edit_link1 = $assert_session->elementExists('css', 'td.views-field-operations li.edit a', $row1);
$this->assertEquals('Edit', $edit_link1->getText());
$this->assertSame('Edit', $edit_link1->getText());
$assert_session->linkByHrefExists('/media/' . $media1->id() . '/edit');
$delete_link1 = $assert_session->elementExists('css', 'td.views-field-operations li.delete a', $row1);
$this->assertEquals('Delete', $delete_link1->getText());
$this->assertSame('Delete', $delete_link1->getText());
$assert_session->linkByHrefExists('/media/' . $media1->id() . '/delete');
}
......
......@@ -39,7 +39,7 @@ public function testMediaThemeHookSuggestions() {
$variables['elements'] = $build;
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_media', [$variables]);
$this->assertEquals($suggestions, ['media__full', 'media__' . $media_type->id(), 'media__' . $media_type->id() . '__full', 'media__source_' . $media_type->getSource()->getPluginId()], 'Found expected media suggestions.');
$this->assertSame($suggestions, ['media__full', 'media__' . $media_type->id(), 'media__' . $media_type->id() . '__full', 'media__source_' . $media_type->getSource()->getPluginId()], 'Found expected media suggestions.');
}
}
......@@ -69,8 +69,8 @@ public function testMediaWithOnlyOneMediaType() {
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
$this->assertEquals($media->getRevisionLogMessage(), $revision_log_message);
$this->assertEquals($media->getName(), $media_name);
$this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
$this->assertSame($media->getName(), $media_name);
$assert_session->titleEquals($media_name . ' | Drupal');
// Tests media edit form.
......@@ -86,7 +86,7 @@ public function testMediaWithOnlyOneMediaType() {
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
$this->assertEquals($media->getName(), $media_name2);
$this->assertSame($media->getName(), $media_name2);
$assert_session->titleEquals($media_name2 . ' | Drupal');
// Test that there is no empty vertical tabs element, if the container is
......@@ -118,7 +118,7 @@ public function testMediaWithOnlyOneMediaType() {
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
$this->assertEquals($media->getRevisionLogMessage(), $revision_log_message);
$this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
$this->assertNotEquals($previous_revision_id, $media->getRevisionId());
// Test the status checkbox.
......@@ -486,7 +486,7 @@ protected function assertHelpLink(NodeElement $element, $text, array $attributes
$this->assertNotEmpty($link);
foreach ($attributes as $attribute => $value) {
$this->assertEquals($link->getAttribute($attribute), $value);
$this->assertSame($link->getAttribute($attribute), $value);
}
}
......
......@@ -63,7 +63,7 @@ public function testMediaDisplay() {
// Verify the name is present, and its text matches what is expected.
$assert_session->elementExists('css', '.field--name-name');
$name_field = $page->find('css', '.field--name-name .field__item');
$this->assertEquals($media->label(), $name_field->getText());
$this->assertSame($media->label(), $name_field->getText());
// In the standard profile, there are some pre-cooked types. Make sure the
// elements configured on their displays are the expected ones.
......@@ -85,14 +85,14 @@ public function testMediaDisplay() {
// Here we expect to see only the image, nothing else.
// Assert only one element in the content region.
$this->assertEquals(1, count($page->findAll('css', '.media--type-image > div')));
$this->assertSame(1, count($page->findAll('css', '.media--type-image > div')));
// Assert the image is present inside the media element.
$media_item = $assert_session->elementExists('css', '.media--type-image > div');
$assert_session->elementExists('css', 'img', $media_item);
// Assert that the image src is the original image and not an image style.
$media_image = $assert_session->elementExists('css', '.media--type-image img');
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/example_1.jpeg')));
$this->assertEquals($expected_image_src, $media_image->getAttribute('src'));
$this->assertSame($expected_image_src, $media_image->getAttribute('src'));
$test_filename = $this->randomMachineName() . '.txt';
$test_filepath = 'public://' . $test_filename;
......@@ -106,11 +106,11 @@ public function testMediaDisplay() {
// Here we expect to see only the linked filename.
// Assert only one element in the content region.
$this->assertEquals(1, count($page->findAll('css', 'article.media--type-file > div')));
$this->assertSame(1, count($page->findAll('css', 'article.media--type-file > div')));
// Assert the file link is present, and its text matches the filename.
$assert_session->elementExists('css', 'article.media--type-file .field--name-field-media-file a');
$link = $page->find('css', 'article.media--type-file .field--name-field-media-file a');
$this->assertEquals($test_filename, $link->getText());
$this->assertSame($test_filename, $link->getText());
// Create a node type "page" to use as host entity.
$node_type = NodeType::create([
......@@ -170,7 +170,7 @@ public function testMediaDisplay() {
$assert_session->elementNotExists('css', '.field--name-name');
$assert_session->pageTextNotContains($image_media_name);
// Only one element is present inside the media container.
$this->assertEquals(1, count($page->findAll('css', '.field--name-field-related-media article.media--type-image > div')));
$this->assertSame(1, count($page->findAll('css', '.field--name-field-related-media article.media--type-image > div')));
// Assert the image is present.
$assert_session->elementExists('css', '.field--name-field-related-media article.media--type-image img');
}
......
......@@ -49,7 +49,7 @@ public function testFieldCreationHelpText() {
$page->selectFieldOption('edit-new-storage-type', $field_name);
$field_description_element = $assert_session->elementExists('css', '#edit-description-' . Html::cleanCssIdentifier($field_name));
$this->assertTrue($field_description_element->isVisible());
$this->assertEquals($help_text, $field_description_element->getText());
$this->assertSame($help_text, $field_description_element->getText());
}
}
......
......@@ -69,9 +69,9 @@ public function testMediaFileSource() {
// Load the media and check that all the fields are properly populated.
$media = Media::load(1);
$this->assertEquals($test_filename, $media->getName());
$this->assertEquals('8', $media->get('field_string_file_size')->value);
$this->assertEquals('text/plain', $media->get('field_string_mime_type')->value);
$this->assertSame($test_filename, $media->getName());
$this->assertSame('8', $media->get('field_string_file_size')->value);
$this->assertSame('text/plain', $media->get('field_string_mime_type')->value);
// Test the MIME type icon.
$icon_base = \Drupal::config('media.settings')->get('icon_base_uri');
......
......@@ -59,9 +59,9 @@ public function testMediaImageSource() {
// Load the media and check that all fields are properly populated.
$media = Media::load(1);
$this->assertEquals('example_1.jpeg', $media->getName());
$this->assertEquals('200', $media->get('field_string_width')->value);
$this->assertEquals('89', $media->get('field_string_height')->value);
$this->assertSame('example_1.jpeg', $media->getName());
$this->assertSame('200', $media->get('field_string_width')->value);
$this->assertSame('89', $media->get('field_string_height')->value);
}
}
......@@ -160,15 +160,15 @@ public function testMediaTypes() {
$loaded_media_type = $this->container->get('entity_type.manager')
->getStorage('media_type')
->load($this->testMediaType->id());
$this->assertEquals($loaded_media_type->id(), $this->testMediaType->id());
$this->assertEquals($loaded_media_type->label(), $new_name);
$this->assertEquals($loaded_media_type->getDescription(), $new_description);
$this->assertEquals($loaded_media_type->getSource()->getPluginId(), 'test');
$this->assertEquals($loaded_media_type->getSource()->getConfiguration()['test_config_value'], 'This is new config value.');
$this->assertSame($loaded_media_type->id(), $this->testMediaType->id());
$this->assertSame($loaded_media_type->label(), $new_name);
$this->assertSame($loaded_media_type->getDescription(), $new_description);
$this->assertSame($loaded_media_type->getSource()->getPluginId(), 'test');
$this->assertSame($loaded_media_type->getSource()->getConfiguration()['test_config_value'], 'This is new config value.');
$this->assertTrue($loaded_media_type->shouldCreateNewRevision());
$this->assertTrue($loaded_media_type->thumbnailDownloadsAreQueued());
$this->assertFalse($loaded_media_type->getStatus());
$this->assertEquals($loaded_media_type->getFieldMap(), ['attribute_1' => 'name']);
$this->assertSame($loaded_media_type->getFieldMap(), ['attribute_1' => 'name']);
// We need to clear the statically cached field definitions to account for
// fields that have been created by API calls in this test, since they exist
......
......@@ -34,19 +34,19 @@ public function testMediaWizard() {
$page->checkField('page[create]');
$page->fillField('page[path]', $this->randomMachineName(16));
$page->pressButton('Save and edit');
$this->assertEquals($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);
$this->assertSame($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);
$view = Views::getView($view_id);
$view->initHandlers();
$row = $view->display_handler->getOption('row');
$this->assertEquals($row['type'], 'fields');
$this->assertSame($row['type'], 'fields');
// Check for the default filters.
$this->assertEquals($view->filter['status']->table, 'media_field_data');
$this->assertEquals($view->filter['status']->field, 'status');
$this->assertSame($view->filter['status']->table, 'media_field_data');
$this->assertSame($view->filter['status']->field, 'status');
$this->assertTrue($view->filter['status']->value);
// Check for the default fields.
$this->assertEquals($view->field['name']->table, 'media_field_data');
$this->assertEquals($view->field['name']->field, 'name');
$this->assertSame($view->field['name']->table, 'media_field_data');
$this->assertSame($view->field['name']->field, 'name');
}
......@@ -67,23 +67,23 @@ public function testMediaRevisionWizard() {
$page->checkField('page[create]');
$page->fillField('page[path]', $this->randomMachineName(16));
$page->pressButton('Save and edit');
$this->assertEquals($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);
$this->assertSame($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);
$view = Views::getView($view_id);
$view->initHandlers();
$row = $view->display_handler->getOption('row');
$this->assertEquals($row['type'], 'fields');
$this->assertSame($row['type'], 'fields');
// Check for the default filters.
$this->assertEquals($view->filter['status']->table, 'media_field_revision');
$this->assertEquals($view->filter['status']->field, 'status');
$this->assertSame($view->filter['status']->table, 'media_field_revision');
$this->assertSame($view->filter['status']->field, 'status');
$this->assertTrue($view->filter['status']->value);
// Check for the default fields.
$this->assertEquals($view->field['name']->table, 'media_field_revision');
$this->assertEquals($view->field['name']->field, 'name');
$this->assertEquals($view->field['changed']->table, 'media_field_revision');
$this->assertEquals($view->field['changed']->field, 'changed');
$this->assertSame($view->field['name']->table, 'media_field_revision');
$this->assertSame($view->field['name']->field, 'name');
$this->assertSame($view->field['changed']->table, 'media_field_revision');
$this->assertSame($view->field['changed']->field, 'changed');
}
}
......@@ -28,13 +28,13 @@ public function testMediaTypeCreation() {
$this->container->get('module_installer')->install(['media_test_type']);
$test_media_type = $media_type_storage->load('test');
$this->assertInstanceOf(MediaTypeInterface::class, $test_media_type, 'The media type from default configuration has not been created in the database.');
$this->assertEquals('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.');
$this->assertEquals('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.');
$this->assertEquals('test', $test_media_type->get('source'), 'Could not assure the correct media source.');
$this->assertSame('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.');
$this->assertSame('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.');
$this->assertSame('test', $test_media_type->get('source'), 'Could not assure the correct media source.');
// Source field is not set on the media source, but it should never
// be created automatically when a config is being imported.
$this->assertEquals(['source_field' => '', 'test_config_value' => 'Kakec'], $test_media_type->get('source_configuration'), 'Could not assure the correct media source configuration.');
$this->assertEquals(['metadata_attribute' => 'field_attribute_config_test'], $test_media_type->get('field_map'), 'Could not assure the correct field map.');
$this->assertSame(['source_field' => '', 'test_config_value' => 'Kakec'], $test_media_type->get('source_configuration'), 'Could not assure the correct media source configuration.');
$this->assertSame(['metadata_attribute' => 'field_attribute_config_test'], $test_media_type->get('field_map'), 'Could not assure the correct field map.');
// Check the Media Type access handler behavior.
// We grant access to the 'view label' operation to all users having
// permission to 'view media'.
......@@ -72,10 +72,10 @@ public function testMediaEntityCreation() {
$this->assertNotInstanceOf(MediaInterface::class, Media::load(rand(1000, 9999)), 'Failed asserting a non-existent media.');
$this->assertInstanceOf(MediaInterface::class, Media::load($media->id()), 'The new media item has not been created in the database.');
$this->assertEquals($this->testMediaType->id(), $media->bundle(), 'The media item was not created with the correct type.');
$this->assertEquals('Unnamed', $media->getName(), 'The media item was not created with the correct name.');
$this->assertSame($this->testMediaType->id(), $media->bundle(), 'The media item was not created with the correct type.');
$this->assertSame('Unnamed', $media->getName(), 'The media item was not created with the correct name.');
$source_field_name = $media->bundle->entity->getSource()->getSourceFieldDefinition($media->bundle->entity)->getName();
$this->assertEquals('Nation of sheep, ruled by wolves, owned by pigs.', $media->get($source_field_name)->value, 'Source returns incorrect source field value.');
$this->assertSame('Nation of sheep, ruled by wolves, owned by pigs.', $media->get($source_field_name)->value, 'Source returns incorrect source field value.');
}
}
......@@ -18,7 +18,7 @@ public function testFileExtensionConstraint() {
$media = $this->generateMedia('test.patch', $mediaType);
$result = $media->validate();
$this->assertCount(1, $result);
$this->assertEquals('field_media_file.0', $result->get(0)->getPropertyPath());
$this->assertSame('field_media_file.0', $result->get(0)->getPropertyPath());
$this->assertContains('Only files with the following extensions are allowed:', (string) $result->get(0)->getMessage());
// Create a random file that should pass.
......
......@@ -31,7 +31,7 @@ public function testNameBaseField() {
// Ensure media name is configurable on manage display.
$this->assertTrue($field_definitions['name']->isDisplayConfigurable('view'));
// Ensure it is not visible by default.
$this->assertEquals($field_definitions['name']->getDisplayOptions('view'), ['region' => 'hidden']);
$this->assertSame($field_definitions['name']->getDisplayOptions('view'), ['region' => 'hidden']);
}
}
......@@ -93,10 +93,10 @@ public function testTranslatableFieldSaveLoad() {
$result = $result && $item['value'] == $media_translation->{$source_field_definition->getName()}[$delta]->value;
}
$this->assertTrue($result, new FormattableMarkup('%language translation field value not correct.', ['%language' => $langcode]));
$this->assertEquals('public://' . $langcode . '.png', $media_translation->getSource()->getMetadata($media_translation, 'thumbnail_uri'), new FormattableMarkup('%language translation thumbnail metadata attribute is not correct.', ['%language' => $langcode]));
$this->assertEquals('public://' . $langcode . '.png', $media_translation->get('thumbnail')->entity->getFileUri(), new FormattableMarkup('%language translation thumbnail value is not correct.', ['%language' => $langcode]));
$this->assertSame('public://' . $langcode . '.png', $media_translation->getSource()->getMetadata($media_translation, 'thumbnail_uri'), new FormattableMarkup('%language translation thumbnail metadata attribute is not correct.', ['%language' => $langcode]));
$this->assertSame('public://' . $langcode . '.png', $media_translation->get('thumbnail')->entity->getFileUri(), new FormattableMarkup('%language translation thumbnail value is not correct.', ['%language' => $langcode]));
$this->assertEquals('Test Thumbnail ' . $langcode, $media_translation->getSource()->getMetadata($media_translation, 'test_thumbnail_alt'), new FormattableMarkup('%language translation thumbnail alt metadata attribute is not correct.', ['%language' => $langcode]));
$this->assertEquals('Test Thumbnail ' . $langcode, $media_translation->get('thumbnail')->alt, new FormattableMarkup('%language translation thumbnail alt value is not correct.', ['%language' => $langcode]));
$this->assertSame('Test Thumbnail ' . $langcode, $media_translation->get('thumbnail')->alt, new FormattableMarkup('%language translation thumbnail alt value is not correct.', ['%language' => $langcode]));
}
}
......
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