You are here

public function MediaLibraryStateTest::testFromRequest in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryStateTest::testFromRequest()

Tests the hash validation when the state is created from a request.

@covers ::fromRequest @dataProvider providerFromRequest

Parameters

array $query_overrides: The query parameters to override.

bool $exception_expected: Whether an AccessDeniedHttpException is expected or not.

File

core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php, line 273

Class

MediaLibraryStateTest
Tests the media library state value object.

Namespace

Drupal\Tests\media_library\Kernel

Code

public function testFromRequest(array $query_overrides, $exception_expected) {

  // Override the query parameters and verify an exception is thrown when
  // required state parameters are changed.
  $query = MediaLibraryState::create('test', [
    'file',
    'image',
  ], 'image', 2)
    ->all();
  $query = array_merge($query, $query_overrides);
  if ($exception_expected) {
    $this
      ->expectException(BadRequestHttpException::class);
    $this
      ->expectExceptionMessage("Invalid media library parameters specified.");
  }
  $state = MediaLibraryState::fromRequest(new Request($query));
  $this
    ->assertInstanceOf(MediaLibraryState::class, $state);
}