ExampleHookTest
extends TestCase
in package
implements
HeadlessInterface, HookInterface
This is an example of a barebones test which implements `HookInterface`. Methods are automatically scanned to find event-listeners based on a naming convention:
-
function hook_*($arg1, &$arg2, ...)
: Bind to eponymous hook. Receive a list of ordered parameters. - 'function on_*($event)`: Bind to eponymous Symfony event. Receive an event object.
The underlying mechanism behind this is:
- When booting headless Civi,
CRM_Utils_System_UnitTests::initialize()
looks up the active test object. - It uses
EventScanner
to check the interfaces & methods for any listeners.
Tags
Table of Contents
Interfaces
- HeadlessInterface
- Interface HeadlessInterface
- HookInterface
Properties
- $contact : CRM_Contact_DAO_Contact
- $tracker : mixed
Methods
- hook_civicrm_alterContent() : mixed
- Listen to hook_civicrm_alterContent in traditional hook format.
- on_civi_api_prepare() : void
- Listen to `civi.api.resolve` in Symfony event format.
- on_civi_api_resolve() : void
- Listen to `civi.api.resolve` in Symfony event format.
- on_hook_civicrm_alterContent() : void
- Listen to hook_civicrm_alterContent in Symfony event format.
- setUpHeadless() : mixed
- The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
- testGetFields() : void
- Test getfields calls hooks.
- testPageOutput() : void
- Basic run test.
- setUp() : void
- tearDown() : void
Properties
$contact
protected
CRM_Contact_DAO_Contact
$contact
$tracker
protected
mixed
$tracker
Methods
hook_civicrm_alterContent()
Listen to hook_civicrm_alterContent in traditional hook format.
public
hook_civicrm_alterContent(mixed &$content, mixed $context, mixed $tplName, mixed &$object) : mixed
Parameters
- $content : mixed
- $context : mixed
- $tplName : mixed
- $object : mixed
Tags
on_civi_api_prepare()
Listen to `civi.api.resolve` in Symfony event format.
public
on_civi_api_prepare(PrepareEvent $event) : void
Parameters
- $event : PrepareEvent
Tags
on_civi_api_resolve()
Listen to `civi.api.resolve` in Symfony event format.
public
on_civi_api_resolve(ResolveEvent $event) : void
Parameters
- $event : ResolveEvent
Tags
on_hook_civicrm_alterContent()
Listen to hook_civicrm_alterContent in Symfony event format.
public
on_hook_civicrm_alterContent(GenericHookEvent $event) : void
Parameters
- $event : GenericHookEvent
Tags
setUpHeadless()
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
public
setUpHeadless() : mixed
It should perform any necessary steps required for putting the database in a consistent baseline -- such as loading schema and extensions.
The utility \Civi\Test::headless()
provides a number of helper functions
for managing this setup, and it includes optimizations to avoid redundant
setup work.
testGetFields()
Test getfields calls hooks.
public
testGetFields() : void
Tags
testPageOutput()
Basic run test.
public
testPageOutput() : void
setUp()
protected
setUp() : void
tearDown()
protected
tearDown() : void