You are here

function _flag_hook_test_record_invocation in Flag 7.3

Store the hook name and parameters into a variable for retrieval by the test.

Hook implementations should call this with their hook name and parameters.

Parameters

string $hook_name: The name of the hook invoked.

array $function_parameters: The array of parameters the hook received.

$flagging: (optional) The flagging entity that the hook received. If this is given, then various flag API functions have their data set into the tracking variable for verification by the test case.

7 calls to _flag_hook_test_record_invocation()
flag_hook_test_entity_delete in tests/flag_hook_test/flag_hook_test.module
Implements hook_entity_delete().
flag_hook_test_entity_insert in tests/flag_hook_test/flag_hook_test.module
Implements hook_entity_insert().
flag_hook_test_entity_presave in tests/flag_hook_test/flag_hook_test.module
Implements hook_entity_presave().
flag_hook_test_entity_update in tests/flag_hook_test/flag_hook_test.module
Implements hook_entity_update().
flag_hook_test_flag_flag in tests/flag_hook_test/flag_hook_test.module
Implements hook_flag_flag().

... See full list

File

tests/flag_hook_test/flag_hook_test.module, line 22
flag_hook_test.module Test module for the hooks that Flag invokes.

Code

function _flag_hook_test_record_invocation($hook_name, $function_parameters, $flagging = NULL) {
  $variable = variable_get('flag_hook_test_hook_tracking', array());
  $variable[$hook_name] = array();
  $variable[$hook_name]['parameters'] = $function_parameters;

  // If a Flagging entity was passed in, call API functions and store their data
  // for the test case to check.
  if (isset($flagging)) {
    $flag = flag_get_flag(NULL, $flagging->fid);
    $variable[$hook_name]['api_calls'] = array();
    $variable[$hook_name]['api_calls']['flag_get_entity_flags'] = flag_get_entity_flags('node', $flagging->entity_id, $flag->name);
    $variable[$hook_name]['api_calls']['flag_get_user_flags'] = flag_get_user_flags('node', $flagging->entity_id, $flagging->uid);
    $variable[$hook_name]['api_calls']['flag_get_counts'] = flag_get_counts('node', $flagging->entity_id);
    $variable[$hook_name]['api_calls']['flag_get_flag_counts'] = flag_get_flag_counts($flag->name);
    $variable[$hook_name]['api_calls']['flag_get_entity_flag_counts'] = flag_get_entity_flag_counts($flag, 'node');
    $account = user_load($flagging->uid);
    $variable[$hook_name]['api_calls']['flag_get_user_flag_counts'] = flag_get_user_flag_counts($flag, $account);
  }
  variable_set('flag_hook_test_hook_tracking', $variable);
}