| 1 | <?php |
| 2 | namespace Civi\Test; |
| 3 | |
| 4 | use 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 | */ |
| 11 | class ExampleHookTest extends \PHPUnit_Framework_TestCase implements HeadlessInterface, HookInterface { |
| 12 | |
| 13 | /** |
| 14 | * @var \CRM_Contact_DAO_Contact |
| 15 | */ |
| 16 | protected $contact; |
| 17 | |
| 18 | public function setUpHeadless() { |
| 19 | return \Civi\Test::headless()->apply(); |
| 20 | } |
| 21 | |
| 22 | protected function setUp() { |
| 23 | $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array( |
| 24 | 'contact_type' => 'Individual', |
| 25 | )); |
| 26 | $session = \CRM_Core_Session::singleton(); |
| 27 | $session->set('userID', $this->contact->id); |
| 28 | } |
| 29 | |
| 30 | protected function tearDown() { |
| 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 | } |