Tests hook invocations for CRUD operations on comments.
public function testCommentHooks() {
$account = $this
->createUser();
$node = entity_create('node', array(
'uid' => $account->uid,
'type' => 'article',
'title' => 'Test node',
'status' => 1,
'comment' => 2,
'promote' => 0,
'sticky' => 0,
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
));
$node
->save();
$nid = $node->nid;
$_SESSION['entity_crud_hook_test'] = array();
$comment = entity_create('comment', array(
'node_type' => 'node_type_' . $node
->bundle(),
'cid' => NULL,
'pid' => 0,
'nid' => $nid,
'uid' => $account->uid,
'subject' => 'Test comment',
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
'status' => 1,
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_comment_create called',
'entity_crud_hook_test_entity_create called for type comment',
));
$_SESSION['entity_crud_hook_test'] = array();
$comment
->save();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_comment_presave called',
'entity_crud_hook_test_entity_presave called for type comment',
'entity_crud_hook_test_comment_insert called',
'entity_crud_hook_test_entity_insert called for type comment',
));
$_SESSION['entity_crud_hook_test'] = array();
$comment = comment_load($comment
->id());
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_entity_load called for type comment',
'entity_crud_hook_test_comment_load called',
));
$_SESSION['entity_crud_hook_test'] = array();
$comment->subject->value = 'New subject';
$comment
->save();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_comment_presave called',
'entity_crud_hook_test_entity_presave called for type comment',
'entity_crud_hook_test_comment_update called',
'entity_crud_hook_test_entity_update called for type comment',
));
$_SESSION['entity_crud_hook_test'] = array();
$comment
->delete();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_comment_predelete called',
'entity_crud_hook_test_entity_predelete called for type comment',
'entity_crud_hook_test_comment_delete called',
'entity_crud_hook_test_entity_delete called for type comment',
));
}