3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Trait CRMTraits_Page_PageTestTrait
31 * Trait for testing quickform pages in unit tests.
33 trait CRMTraits_Page_PageTestTrait
{
36 * Content from the rendered page.
40 protected $pageContent;
53 * Variables assigned to smarty.
57 protected $smartyVariables = [];
62 * @param string $content
63 * @param string $context
64 * @param string $tplName
65 * @param CRM_Core_Page $object
67 public function checkPageContent(&$content, $context, $tplName, &$object) {
68 $this->pageContent
= $content;
69 $this->tplName
= $tplName;
70 $this->page
= $object;
71 $this->context
= $context;
72 // Ideally we would validate $content as valid html here.
73 // Suppress console output.
75 $this->smartyVariables
= CRM_Core_Smarty
::singleton()->get_template_vars();
79 * Assert that the page output contains the expected strings.
81 * @param $expectedStrings
83 protected function assertPageContains($expectedStrings) {
84 unset($this->smartyVariables
['config']);
85 unset($this->smartyVariables
['session']);
86 foreach ($expectedStrings as $expectedString) {
87 $this->assertContains($expectedString, $this->pageContent
, print_r($this->contributions
, TRUE) . print_r($this->smartyVariables
, TRUE));
92 * Assert that the expected variables have been assigned to Smarty.
94 * @param $expectedVariables
96 protected function assertSmartyVariables($expectedVariables) {
97 foreach ($expectedVariables as $variableName => $expectedValue) {
98 $this->assertEquals($expectedValue, $this->smartyVariables
[$variableName]);
103 * Check an array assigned to smarty for the inclusion of the expected variables.
105 * @param string $variableName
109 protected function assertSmartyVariableArrayIncludes($variableName, $index, $expected) {
110 $smartyVariable = $this->smartyVariables
[$variableName];
111 if ($index !== NULL) {
112 $smartyVariable = $smartyVariable[$index];
114 foreach ($expected as $key => $value) {
115 $this->assertEquals($value, $smartyVariable[$key], 'Checking ' . $key);
120 * Set up environment to listen for page content.
122 protected function listenForPageContent() {
123 $this->hookClass
->setHook('civicrm_alterContent', [