Always get values incl. default from ImageItem
Closes #3319601
Merge request reports
Activity
2 3 declare(strict_types=1); 4 5 namespace Drupal\Tests\media\Functional; 6 7 use Drupal\field\Entity\FieldConfig; 8 use Drupal\file\Entity\File; 9 use Drupal\media\Entity\Media; 10 use Drupal\Tests\TestFileCreationTrait; 11 12 /** 13 * Tests the alt attribute of image media source. 14 * 15 * @group media 16 */ 17 class MediaSrcImgAltAttrTest extends MediaFunctionalTestBase { Added Functional test case as, need to hit the admin media overview page need to check whether alt tag render or not, otherwise need to load view if kernel test needs to add. Any suggestions would be greatly appreciated.
Edited by Pooja Sharmachanged this line in version 9 of the diff
added 1 commit
- daeb7f22 - Add static text case and no alt attribute case
added 1 commit
- bd3274b9 - issue/3319601: Revert back to original code as recent changes does work correctly
54 [ 55 'target_id' => $file->id(), 56 'alt' => '', 57 'title' => 'default title', 58 ], 59 ], 60 ]); 61 $media->save(); 62 63 $this->drupalGet('/admin/content/media'); 64 65 // Check if we pass empty string in alt attr, 66 // then alt attr display or not. 67 $assert_session = $this->assertSession(); 68 $row1 = $assert_session->elementExists('css', 'table tbody tr:nth-child(1)'); 69 $assert_session->elementAttributeContains('css', 'td.views-field-thumbnail__target-id img', 'alt', '', $row1); Added simple generic eg it'll compare whether alt tag is rendering on the FE or not only, At line no. 56 pass empty string to alt attr field value to test specific test scenario
Edited by Pooja Sharmachanged this line in version 9 of the diff
added 38 commits
-
8c284fb0...9490eb3e - 32 commits from branch
project:11.x
- e3f80f1e - Always get values incl. default from ImageItem
- 2dece1cb - issue/3319601: Added test coverage.
- f2c664c5 - Add static text case and no alt attribute case
- 37c7d634 - Update test case comments
- fc723abc - issue/3319601: Revert back to original code as recent changes does work correctly
- 3e3c52a8 - issue/3319601: Resolved test failures
Toggle commit list-
8c284fb0...9490eb3e - 32 commits from branch
added 1 commit
- c70e354a - issue/3319601: Added test code in MediaSourceImageTest
added 1 commit
- 1f54550a - issue/3319601: Deleted MediaSrcImgAltAttrTest as test code moved to MediaSourceImageTest.
32 32 33 /** 34 * The file id. 35 * 36 * @var int|string 37 */ 38 protected $fileId; 39 40 /** 41 * {@inheritdoc} 42 */ 43 protected function setUp(): void { 44 parent::setUp(); 33 45 $media_type = $this->createMediaType('image'); 34 $media_type_id = $media_type->id(); 46 $this->mediaTypeId = $media_type->id(); This is something not clear to me or even not getting your concerns. Can you please clarify it a bit?
Edited by Pooja Sharmachanged this line in version 12 of the diff
24 24 protected $defaultTheme = 'stark'; 25 25 26 26 /** 27 * Test that non-main properties do not trigger source field value change. 27 * The media type id. 28 * 29 * @var int|string 28 30 */ 29 public function testOnlyMainPropertiesTriggerSourceFieldChanged(): void { 30 $assert_session = $this->assertSession(); 31 $page = $this->getSession()->getPage(); 31 protected $mediaTypeId; changed this line in version 10 of the diff
27 * Test that non-main properties do not trigger source field value change. 27 * The media type id. 28 * 29 * @var int|string 28 30 */ 29 public function testOnlyMainPropertiesTriggerSourceFieldChanged(): void { 30 $assert_session = $this->assertSession(); 31 $page = $this->getSession()->getPage(); 31 protected $mediaTypeId; 32 32 33 /** 34 * The file id. 35 * 36 * @var int|string 37 */ 38 protected $fileId; changed this line in version 10 of the diff
73 95 74 96 $this->drupalGet($media->toUrl('edit-form')); 75 97 $assert_session->fieldValueEquals('name[0][value]', 'example_1.jpeg'); 98 99 } 100 101 /** 102 * Test that alt attribute of image media source display or not. 103 */ 104 public function testImgAltAttrDisplay(): void { changed this line in version 12 of the diff
added 1 commit
- 97412161 - issue/3319601: Applied suggestions MediaSourceImageTest
added 1 commit
- 6aaa19c6 - issue/3319601: Added test case in MediaOverviewPageTest
added 1 commit
- 3849c3a8 - issue/3319601: Revert back changes MediaSourceImageTest
- Resolved by Dave Long
185 190 $assert_session->linkByHrefExists('/media/' . $media3->id()); 186 191 } 187 192 193 /** 194 * Test that alt attribute of image media source display or not. 195 */ 196 public function testImgAltAttrDisplay(): void { changed this line in version 13 of the diff
201 $media_type->save(); 202 203 /** @var \Drupal\field\FieldConfigInterface $field */ 204 $field = FieldConfig::load("media.$media_type_id.field_media_image"); 205 $settings = $field->getSettings(); 206 $settings['alt_field'] = TRUE; 207 $settings['alt_field_required'] = FALSE; 208 $field->set('settings', $settings); 209 $field->save(); 210 211 $file = File::create([ 212 'uri' => $this->getTestFiles('image')[0]->uri, 213 ]); 214 $file->save(); 215 216 // Pass in alt attr empty string. changed this line in version 13 of the diff
218 'name' => 'Custom name', 219 'bundle' => $media_type_id, 220 'field_media_image' => [ 221 [ 222 'target_id' => $file->id(), 223 'alt' => '', 224 'title' => 'default title', 225 ], 226 ], 227 ]); 228 $media->save(); 229 230 $this->drupalGet('/admin/content/media'); 231 232 // Check if we pass empty string in alt attr, 233 // then alt attr display or not. changed this line in version 13 of the diff
added 1 commit
- 66f57148 - issue/3319601: Applied suggestion(s) MediaOverviewPageTest.
added 1 commit
- 3c6fe739 - issue/3319601: Added back parent::getMetadata() with condition.
220 'field_media_image' => [ 221 [ 222 'target_id' => $file->id(), 223 'alt' => '', 224 'title' => 'default title', 225 ], 226 ], 227 ]); 228 $media->save(); 229 230 $this->drupalGet('/admin/content/media'); 231 232 // Confirm that the alt text attribute is present 233 $assert_session = $this->assertSession(); 234 $row1 = $assert_session->elementExists('css', 'table tbody tr:nth-child(1)'); 235 $assert_session->elementAttributeContains('css', 'td.views-field-thumbnail__target-id img', 'alt', '', $row1); - Comment on lines +234 to +235
Checking that a string contains the empty string doesn't make much sense and doesn't confirm that we are looking at the right element. Also, this method only takes four arguments; the fifth is ignored.
I think we should use
elementAttributeExists
here and then explicitly assert the return value:234 $row1 = $assert_session->elementExists('css', 'table tbody tr:nth-child(1)'); 235 $assert_session->elementAttributeContains('css', 'td.views-field-thumbnail__target-id img', 'alt', '', $row1); 234 $element = $assert_session->elementAttributeExists('css', 'td.views-field-thumbnail__target-id img', 'alt'); 235 $this->assertSame('', (string) $element->getAttribute('alt')); Edited by Dave Long changed this line in version 16 of the diff
added 346 commits
-
92303bf8...9258113b - 331 commits from branch
project:11.x
- 9258113b...9c6bb660 - 5 earlier commits
- 2314fc5a - issue/3319601: Resolved test failures
- ac07227c - issue/3319601: Added test code in MediaSourceImageTest
- 5ae38a31 - issue/3319601: Deleted MediaSrcImgAltAttrTest as test code moved to MediaSourceImageTest.
- 756245b4 - issue/3319601: Applied suggestions MediaSourceImageTest
- d494c998 - issue/3319601: Added test case in MediaOverviewPageTest
- 29d2aa2c - issue/3319601: Revert back changes MediaSourceImageTest
- c8b31ca9 - issue/3319601: Applied suggestion(s) MediaOverviewPageTest.
- f3dc3dcb - issue/3319601: Added back parent::getMetadata() with condition.
- ff031818 - issue/3319601: Updated Image file
- 0b28bc1c - issue/3319601: Applied suggestion.
Toggle commit list-
92303bf8...9258113b - 331 commits from branch
- Resolved by quietone
- Resolved by quietone