3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Trait CRMTraits_Page_PageTestTrait
15 * Trait for testing quickform pages in unit tests.
17 trait CRMTraits_Page_PageTestTrait
{
20 * Content from the rendered page.
24 protected $pageContent;
37 * Variables assigned to smarty.
41 protected $smartyVariables = [];
46 * @param string $content
47 * @param string $context
48 * @param string $tplName
49 * @param CRM_Core_Page $object
51 public function checkPageContent(&$content, $context, $tplName, &$object) {
52 $this->pageContent
= $content;
53 $this->tplName
= $tplName;
54 $this->page
= $object;
55 $this->context
= $context;
56 // Ideally we would validate $content as valid html here.
57 // Suppress console output.
59 $this->smartyVariables
= CRM_Core_Smarty
::singleton()->get_template_vars();
63 * Assert that the page output contains the expected strings.
65 * @param $expectedStrings
67 protected function assertPageContains($expectedStrings) {
68 unset($this->smartyVariables
['config']);
69 unset($this->smartyVariables
['session']);
70 foreach ($expectedStrings as $expectedString) {
71 $this->assertContains($expectedString, $this->pageContent
, print_r($this->contributions
, TRUE) . print_r($this->smartyVariables
, TRUE));
76 * Assert that the expected variables have been assigned to Smarty.
78 * @param $expectedVariables
80 protected function assertSmartyVariables($expectedVariables) {
81 foreach ($expectedVariables as $variableName => $expectedValue) {
82 $this->assertEquals($expectedValue, $this->smartyVariables
[$variableName]);
87 * Check an array assigned to smarty for the inclusion of the expected variables.
89 * @param string $variableName
93 protected function assertSmartyVariableArrayIncludes($variableName, $index, $expected) {
94 $smartyVariable = $this->smartyVariables
[$variableName];
95 if ($index !== NULL) {
96 $smartyVariable = $smartyVariable[$index];
98 foreach ($expected as $key => $value) {
99 $this->assertEquals($value, $smartyVariable[$key], 'Checking ' . $key);
104 * Set up environment to listen for page content.
106 protected function listenForPageContent() {
107 $this->hookClass
->setHook('civicrm_alterContent', [