You are here

public function ViewDataEventTest::testViewsDataEventMultipleAdds in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/views_event_dispatcher/tests/src/Unit/Views/ViewDataEventTest.php \Drupal\Tests\views_event_dispatcher\Unit\Views\ViewDataEventTest::testViewsDataEventMultipleAdds()

ViewsDataEvent multiple adds test.

File

modules/views_event_dispatcher/tests/src/Unit/Views/ViewDataEventTest.php, line 64

Class

ViewDataEventTest
Class ViewDataEventTest.

Namespace

Drupal\Tests\views_event_dispatcher\Unit\Views

Code

public function testViewsDataEventMultipleAdds() : void {
  $data1 = [
    'test' => [
      'test_array_data',
    ],
  ];
  $data2 = [
    'test' => [
      'other_test_array_data',
    ],
  ];
  $data3 = [
    'some' => [
      'other_data',
    ],
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::VIEWS_DATA => static function (ViewsDataEvent $event) use ($data1, $data2, $data3) {
      $event
        ->addData($data1);
      $event
        ->addData($data2);
      $event
        ->addData($data3);
    },
  ]);
  $result = views_event_dispatcher_views_data();
  $expectedResult = [
    'test' => [
      'test_array_data',
      'other_test_array_data',
    ],
    'some' => [
      'other_data',
    ],
  ];
  self::assertSame($expectedResult, $result);
}