function ComputedFileUrlTest::testGetValue

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/ComputedFileUrlTest.php \Drupal\Tests\file\Kernel\ComputedFileUrlTest::testGetValue()
  2. 10 core/modules/file/tests/src/Kernel/ComputedFileUrlTest.php \Drupal\Tests\file\Kernel\ComputedFileUrlTest::testGetValue()
  3. 11.x core/modules/file/tests/src/Kernel/ComputedFileUrlTest.php \Drupal\Tests\file\Kernel\ComputedFileUrlTest::testGetValue()

@covers ::getValue

File

core/modules/file/tests/src/Kernel/ComputedFileUrlTest.php, line 28

Class

ComputedFileUrlTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21file%21src%21ComputedFileUrl.php/class/ComputedFileUrl/8.9.x" title="Computed file URL property class." class="local">\Drupal\file\ComputedFileUrl</a>

Namespace

Drupal\Tests\file\Kernel

Code

public function testGetValue() {
    $entity = $this->prophesize(FileInterface::class);
    $entity->getFileUri()
        ->willReturn($this->testUrl);
    $parent = $this->prophesize(FieldItemInterface::class);
    $parent->getEntity()
        ->shouldBeCalledTimes(2)
        ->willReturn($entity->reveal());
    $definition = $this->prophesize(DataDefinitionInterface::class);
    $typed_data = new ComputedFileUrl($definition->reveal(), $this->randomMachineName(), $parent->reveal());
    $expected = base_path() . $this->siteDirectory . '/files/druplicon.txt';
    $this->assertSame($expected, $typed_data->getValue());
    // Do this a second time to confirm the same value is returned but the value
    // isn't retrieved from the parent entity again.
    $this->assertSame($expected, $typed_data->getValue());
}

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