function AjaxResponseTest::createCommandMockWithSettingsAndLibrariesAttachments

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php \Drupal\Tests\Core\Ajax\AjaxResponseTest::createCommandMockWithSettingsAndLibrariesAttachments()

Creates a mock of a provided subclass of CommandInterface.

Adds given settings and libraries to assets mock that is attached to the command mock.

Parameters

string $command_class_name: The command class name to create the mock for.

array|null $settings: The settings to attach.

array|null $libraries: The libraries to attach.

string $command_name: The command name to pass to the mock.

File

core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php, line 163

Class

AjaxResponseTest
Tests Drupal\Core\Ajax\AjaxResponse.

Namespace

Drupal\Tests\Core\Ajax

Code

private function createCommandMockWithSettingsAndLibrariesAttachments(string $command_class_name, array|null $settings, array|null $libraries, string $command_name) : CommandInterface {
  $command = $this->createMock($command_class_name);
  $command->expects($this->once())
    ->method('render')
    ->willReturn([
    'command' => $command_name,
  ]);
  $assets = $this->createMock('Drupal\\Core\\Asset\\AttachedAssetsInterface');
  $assets->expects($this->once())
    ->method('getLibraries')
    ->willReturn($libraries);
  $assets->expects($this->once())
    ->method('getSettings')
    ->willReturn($settings);
  $command->expects($this->once())
    ->method('getAttachedAssets')
    ->willReturn($assets);
  return $command;
}

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