Skip to content
Snippets Groups Projects

Always get values incl. default from ImageItem

Merged Sven Schüring requested to merge issue/drupal-3319601:3319601-media-image-thumbnail into 11.x

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.
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading