ComputedFileUrl example

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

  /** * @covers ::setValue */
Home | Imprint | This part of the site doesn't use cookies.