MDL-39956 Use the new events in library functions.

HACK HACK HACK - userid and contextid are not validated
MDL-39956 cohort: add tests for new events