Issue #3450772: Media items created via the media library widget should have...
Merge request reports
Activity
added 1028 commits
Toggle commit list365 372 $assert_session->fieldValueEquals('Alternative text', '', $media_item_three); 366 373 } 367 374 375 /** 376 * Tests created medias have the same language as the edited translation. 377 */ 378 public function testWidgetUploadMediaLanguage(): void { 379 380 // Retrieve a test image file. 381 foreach ($this->getTestFiles('image') as $image) { 382 $extension = pathinfo($image->filename, PATHINFO_EXTENSION); 383 if ($extension === 'png') { 384 $png_image = $image; 385 } 386 } 387 if (!isset($png_image)) { I simply followed the approach used in the
WidgetUploadTest::testWidgetUpload()
method.I suppose this acts as a safeguard for the (admittedly rare) case where
TestFileCreationTrait::getTestFiles('image')
doesn't return a PNG file.I believe it doesn't cause any harm and provides a clearer error message for developers, rather than leading to an unexpected error later on.
What do you think?
changed this line in version 4 of the diff
433 // Press save button on node edit form page 434 $this->submitForm([], 'Save (this translation)'); 435 $this->waitForText('has been updated'); 436 437 // Check translation edit form. 438 $this->drupalGet('es/node/' . $node->id() . '/edit'); 439 // Open the media library and upload a file. 440 $this->openMediaLibraryForField('field_unlimited_media'); 441 $this->switchToMediaType('Three'); 442 $this->addMediaFileToField('Add files', $this->container->get('file_system')->realpath($png_image->uri)); 443 $this->assertMediaAdded(); 444 $this->waitForFieldExists('Alternative text')->setValue($this->randomString()); 445 $this->pressSaveButton(); 446 // Check that the created media item has the same language 447 // as the translation being edited. 448 $media_items = Media::loadMultiple(); Good point! I hadn't thought about that, as I simply followed the approach used in the
WidgetUploadTest::testWidgetUpload()
method. However, after giving it some thought, I believe this approach makes the test more robust since the retrieved media is always the most recently added.If this test evolves and additional media items are added, assuming the media ID will always be 1 could lead to errors.
changed this line in version 4 of the diff
365 372 $assert_session->fieldValueEquals('Alternative text', '', $media_item_three); 366 373 } 367 374 375 /** 376 * Tests created medias have the same language as the edited translation. 377 */ 378 public function testWidgetUploadMediaLanguage(): void { changed this line in version 4 of the diff
added 1 commit
- 7f9ed88d - Move a multilingual test to its own file so we don't install multilingual...
526 527 * The name of the media type's source field. 527 528 * @param mixed $source_field_value 528 529 * The value for the source field of the media item. 530 * @param mixed $langcode 531 * The langcode of the media item. 529 532 * 530 533 * @return \Drupal\media\MediaInterface 531 534 * An unsaved media entity. 532 535 */ 533 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value) { 536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, $langcode = NULL) { 536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, $langcode = NULL) { 536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, mixed $langcode = NULL) {
499 499 $media_type = $this->getMediaType($form_state); 500 500 $media_storage = $this->entityTypeManager->getStorage('media'); 501 501 $source_field_name = $this->getSourceFieldName($media_type); 502 $media = array_map(function ($source_field_value) use ($media_type, $media_storage, $source_field_name) { 503 return $this->createMediaFromValue($media_type, $media_storage, $source_field_name, $source_field_value); 502 $langcode = $this->getMediaLibraryState($form_state)->getOpenerParameters()['langcode'] ?? NULL;