You are here

public function MediaSourceTest::testGetSourceFieldValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Kernel/MediaSourceTest.php \Drupal\Tests\media\Kernel\MediaSourceTest::testGetSourceFieldValue()
  2. 10 core/modules/media/tests/src/Kernel/MediaSourceTest.php \Drupal\Tests\media\Kernel\MediaSourceTest::testGetSourceFieldValue()

Tests the getSourceFieldValue() method.

File

core/modules/media/tests/src/Kernel/MediaSourceTest.php, line 212

Class

MediaSourceTest
Tests media source plugins related logic.

Namespace

Drupal\Tests\media\Kernel

Code

public function testGetSourceFieldValue() {

  /** @var \Drupal\media\MediaInterface $media */
  $media = Media::create([
    'bundle' => $this->testMediaType
      ->id(),
    'field_media_test' => 'some_value',
  ]);
  $media
    ->save();
  $media_source = $media
    ->getSource();
  $this
    ->assertSame('some_value', $media_source
    ->getSourceFieldValue($media));

  // Test that NULL is returned if there is no value in the source field.
  $media
    ->set('field_media_test', NULL)
    ->save();
  $this
    ->assertNull($media_source
    ->getSourceFieldValue($media));
}