function ComputedFileUrlTest::testSetValue

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

@covers ::setValue

File

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

Class

ComputedFileUrlTest
@coversDefaultClass \Drupal\file\ComputedFileUrl

Namespace

Drupal\Tests\file\Kernel

Code

public function testSetValue() {
    $name = $this->randomMachineName();
    $parent = $this->prophesize(FieldItemInterface::class);
    $parent->onChange($name)
        ->shouldBeCalled();
    $definition = $this->prophesize(DataDefinitionInterface::class);
    $typed_data = new ComputedFileUrl($definition->reveal(), $name, $parent->reveal());
    // Setting the value explicitly should mean the parent entity is never
    // called into.
    $typed_data->setValue($this->testUrl);
    $this->assertSame($this->testUrl, $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($this->testUrl, $typed_data->getValue());
}

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