Merge pull request #19806 from eileenmcnaughton/msg_compat
[civicrm-core.git] / tests / phpunit / Civi / Test / ExampleHookTest.php
CommitLineData
09e1f1e3
TO
1<?php
2namespace Civi\Test;
3
4use Civi\Angular\Page\Main;
5
6/**
7 * This is an example of a barebones test which uses a hook (based on CiviTestListener).
8 *
9 * @group headless
10 */
a6439b6a 11class ExampleHookTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface {
09e1f1e3
TO
12
13 /**
14 * @var \CRM_Contact_DAO_Contact
15 */
16 protected $contact;
17
18 public function setUpHeadless() {
728bbd5b 19 return \Civi\Test::headless()->apply();
09e1f1e3
TO
20 }
21
cacd9d67 22 protected function setUp(): void {
9099cab3 23 $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', [
09e1f1e3 24 'contact_type' => 'Individual',
9099cab3 25 ]);
09e1f1e3
TO
26 $session = \CRM_Core_Session::singleton();
27 $session->set('userID', $this->contact->id);
28 }
29
cacd9d67 30 protected function tearDown(): void {
09e1f1e3
TO
31 $this->contact->delete();
32 }
33
34 /**
35 * @see \CRM_Utils_Hook::alterContent
36 */
37 public function hook_civicrm_alterContent(&$content, $context, $tplName, &$object) {
38 $content .= "zzzyyyxxx";
39 }
40
41 public function testPageOutput() {
42 ob_start();
43 $p = new Main();
44 $p->run();
45 $content = ob_get_contents();
46 ob_end_clean();
47 $this->assertRegExp(';zzzyyyxxx;', $content);
48 }
49
50}