function MediaSourceTest::testGetSourceFieldValue

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Kernel/MediaSourceTest.php \Drupal\Tests\media\Kernel\MediaSourceTest::testGetSourceFieldValue()
  2. 8.9.x core/modules/media/tests/src/Kernel/MediaSourceTest.php \Drupal\Tests\media\Kernel\MediaSourceTest::testGetSourceFieldValue()
  3. 11.x 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 217

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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.