public function ViewsHooksTest::testHooks

Tests the hooks.

File

drupal/core/modules/views/lib/Drupal/views/Tests/ViewsHooksTest.php, line 71
Contains \Drupal\views\Tests\ViewsHooksTest.

Class

ViewsHooksTest
Tests that views hooks are registered when defined in $module.views.inc.

Namespace

Drupal\views\Tests

Code

public function testHooks() {
  $view = views_get_view('test_view');

  // Test each hook is found in the implementations array and is invoked.
  foreach (static::$hooks as $hook => $type) {
    $this
      ->assertTrue($this->moduleHandler
      ->implementsHook('views_test_data', $hook), format_string('The hook @hook was registered.', array(
      '@hook' => $hook,
    )));
    switch ($type) {
      case 'view':
        $this->moduleHandler
          ->invoke('views_test_data', $hook, array(
          $view,
        ));
        break;
      case 'alter':
        $data = array();
        $this->moduleHandler
          ->invoke('views_test_data', $hook, array(
          $data,
        ));
        break;
      default:
        $this->moduleHandler
          ->invoke('views_test_data', $hook);
    }
    $this
      ->assertTrue($this->container
      ->get('state')
      ->get('views_hook_test_' . $hook), format_string('The %hook hook was invoked.', array(
      '%hook' => $hook,
    )));

    // Reset the module implementations cache, so we ensure that the
    // .views.inc file is loaded actively.
    $this->moduleHandler
      ->resetImplementations();
  }
}