You are here

public function FileDownloadUrlTest::testUrlField in JSON:API 8

Test the URL computed field.

File

tests/src/Kernel/Field/FileDownloadUrlTest.php, line 65

Class

FileDownloadUrlTest
@coversDefaultClass \Drupal\jsonapi\Field\FileDownloadUrl @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Field

Code

public function testUrlField() {
  $url_field = $this->file
    ->get('url');

  // Test all the different ways to access a field item.
  $values = [
    $url_field->value,
    $url_field
      ->getValue()[0]['value'],
    $url_field
      ->get(0)
      ->toArray()['value'],
    $url_field
      ->first()
      ->getValue()['value'],
  ];
  array_walk($values, function ($value) {
    $this
      ->assertContains('simpletest', $value);
    $this
      ->assertContains($this->filename, $value);
  });
  $violationList = $this->file
    ->validate();
  $this
    ->assertEquals(0, $violationList
    ->count());
}