Merge pull request #15248 from MegaphoneJon/reporting-19
[civicrm-core.git] / tests / phpunit / CRMTraits / Page / PageTestTrait.php
index 150582e7c59084b239e82605ce07f19a97113b72..2de7e00883eece3b20abc1de26f8851f097bbada 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2020                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -39,6 +39,16 @@ trait CRMTraits_Page_PageTestTrait {
    */
   protected $pageContent;
 
+  /**
+   * @var \CRM_Core_Page
+   */
+  protected $page;
+
+  /**
+   * @var string
+   */
+  protected $tplName;
+
   /**
    * Variables assigned to smarty.
    *
@@ -46,6 +56,8 @@ trait CRMTraits_Page_PageTestTrait {
    */
   protected $smartyVariables = [];
 
+  protected $context;
+
   /**
    * @param string $content
    * @param string $context
@@ -54,6 +66,9 @@ trait CRMTraits_Page_PageTestTrait {
    */
   public function checkPageContent(&$content, $context, $tplName, &$object) {
     $this->pageContent = $content;
+    $this->tplName = $tplName;
+    $this->page = $object;
+    $this->context = $context;
     // Ideally we would validate $content as valid html here.
     // Suppress console output.
     $content = '';
@@ -66,8 +81,10 @@ trait CRMTraits_Page_PageTestTrait {
    * @param $expectedStrings
    */
   protected function assertPageContains($expectedStrings) {
+    unset($this->smartyVariables['config']);
+    unset($this->smartyVariables['session']);
     foreach ($expectedStrings as $expectedString) {
-      $this->assertContains($expectedString, $this->pageContent);
+      $this->assertContains($expectedString, $this->pageContent, print_r($this->contributions, TRUE) . print_r($this->smartyVariables, TRUE));
     }
   }
 
@@ -82,13 +99,30 @@ trait CRMTraits_Page_PageTestTrait {
     }
   }
 
+  /**
+   * Check an array assigned to smarty for the inclusion of the expected variables.
+   *
+   * @param string $variableName
+   * @param $index
+   * @param $expected
+   */
+  protected function assertSmartyVariableArrayIncludes($variableName, $index, $expected) {
+    $smartyVariable = $this->smartyVariables[$variableName];
+    if ($index !== NULL) {
+      $smartyVariable = $smartyVariable[$index];
+    }
+    foreach ($expected as $key => $value) {
+      $this->assertEquals($value, $smartyVariable[$key], 'Checking ' . $key);
+    }
+  }
+
   /**
    * Set up environment to listen for page content.
    */
   protected function listenForPageContent() {
     $this->hookClass->setHook('civicrm_alterContent', [
       $this,
-      'checkPageContent'
+      'checkPageContent',
     ]);
   }