You are here

public function FileLinkValidationTest::testWithExtension in File Link 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/FileLinkValidationTest.php \Drupal\Tests\file_link\Kernel\FileLinkValidationTest::testWithExtension()

Tests file_link field metadata storage with extension.

File

tests/src/Kernel/FileLinkValidationTest.php, line 57

Class

FileLinkValidationTest
Provides kernel tests for 'file_link' field type.

Namespace

Drupal\Tests\file_link\Kernel

Code

public function testWithExtension() {
  $this->entity
    ->set('url_with_extension', [
    'uri' => static::getFullUrl(''),
  ]);
  $violations = $this->entity
    ->get('url_with_extension')
    ->validate();
  $this
    ->assertSame(static::getViolationMessage('Provided file URL has no extension: @uri', ''), (string) $violations
    ->get(0)
    ->getMessage());
  $this->entity
    ->set('url_with_extension', [
    'uri' => static::getFullUrl('/'),
  ]);
  $violations = $this->entity
    ->get('url_with_extension')
    ->validate();
  $this
    ->assertSame(static::getViolationMessage('Provided file URL has no extension: @uri', '/'), (string) $violations
    ->get(0)
    ->getMessage());
  $this->entity
    ->set('url_with_extension', [
    'uri' => static::getFullUrl('/foo'),
  ]);
  $violations = $this->entity
    ->get('url_with_extension')
    ->validate();
  $this
    ->assertSame(static::getViolationMessage('Provided file URL has no extension: @uri', '/foo'), (string) $violations
    ->get(0)
    ->getMessage());
  $this->entity
    ->set('url_with_extension', [
    'uri' => static::getFullUrl('/foo.pdf'),
  ]);
  $violations = $this->entity
    ->get('url_with_extension')
    ->validate();
  $this
    ->assertSame(static::getViolationMessage('Provided file URL has no valid extension: @uri', '/foo.pdf'), (string) $violations
    ->get(0)
    ->getMessage());
  $this->entity
    ->set('url_with_extension', [
    'uri' => static::getFullUrl('/foo.md'),
  ]);
  $violations = $this->entity
    ->get('url_with_extension')
    ->validate();
  $this
    ->assertSame(0, $violations
    ->count());
}