3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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;
43 * Variables assigned to smarty.
47 protected $smartyVariables = [];
50 * @param string $content
51 * @param string $context
52 * @param string $tplName
53 * @param CRM_Core_Page $object
55 public function checkPageContent(&$content, $context, $tplName, &$object) {
56 $this->pageContent
= $content;
57 // Ideally we would validate $content as valid html here.
58 // Suppress console output.
60 $this->smartyVariables
= CRM_Core_Smarty
::singleton()->get_template_vars();
64 * Assert that the page output contains the expected strings.
66 * @param $expectedStrings
68 protected function assertPageContains($expectedStrings) {
69 foreach ($expectedStrings as $expectedString) {
70 $this->assertContains($expectedString, $this->pageContent
);
75 * Assert that the expected variables have been assigned to Smarty.
77 * @param $expectedVariables
79 protected function assertSmartyVariables($expectedVariables) {
80 foreach ($expectedVariables as $variableName => $expectedValue) {
81 $this->assertEquals($expectedValue, $this->smartyVariables
[$variableName]);
86 * Set up environment to listen for page content.
88 protected function listenForPageContent() {
89 $this->hookClass
->setHook('civicrm_alterContent', [