Skip to content
Snippets Groups Projects

Always get values incl. default from ImageItem

10 unresolved threads

Closes #3319601

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 1 commit

    • daeb7f22 - Add static text case and no alt attribute case

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • bd3274b9 - issue/3319601: Revert back to original code as recent changes does work correctly

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 8c284fb0 - issue/3319601: Resolved test failures

    Compare with previous version

  • 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);
  • Pooja Sharma added 38 commits

    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

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • c70e354a - issue/3319601: Added test code in MediaSourceImageTest

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 1f54550a - issue/3319601: Deleted MediaSrcImgAltAttrTest as test code moved to MediaSourceImageTest.

    Compare with previous version

  • 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();
  • 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;
  • 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;
  • 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 {
  • Pooja Sharma added 1 commit

    added 1 commit

    • 97412161 - issue/3319601: Applied suggestions MediaSourceImageTest

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 6aaa19c6 - issue/3319601: Added test case in MediaOverviewPageTest

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 3849c3a8 - issue/3319601: Revert back changes MediaSourceImageTest

    Compare with previous version

  • quietone
  • 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 {
  • 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.
  • 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.
  • Pooja Sharma added 1 commit

    added 1 commit

    • 66f57148 - issue/3319601: Applied suggestion(s) MediaOverviewPageTest.

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 3c6fe739 - issue/3319601: Added back parent::getMetadata() with condition.

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • ce9ab126 - issue/3319601: Updated Image file

    Compare with previous version

  • 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:

      Suggested change
      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
    • Pooja Sharma changed this line in version 16 of the diff

      changed this line in version 16 of the diff

    • Please register or sign in to reply
  • Pooja Sharma added 1 commit

    added 1 commit

    • 92303bf8 - issue/3319601: Applied suggestion.

    Compare with previous version

  • Pooja Sharma added 346 commits

    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.

    Compare with previous version

  • quietone
  • quietone
  • quietone added 1 commit

    added 1 commit

    • 0062e431 - Apply 2 suggestion(s) to 1 file(s)

    Compare with previous version

  • closed

  • Please register or sign in to reply
    Loading