diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
index 395cec106df..facc2fc7c9e 100644
--- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
+++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
@@ -42,6 +42,13 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
*/
protected $contactID;
+ /**
+ * Contributions created for the test.
+ *
+ * @var array
+ */
+ protected $contributions = [];
+
/**
* Prepare for test
*/
@@ -58,6 +65,9 @@ public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_uf_match']);
CRM_Utils_Hook::singleton()->reset();
+ CRM_Core_Session::singleton()->reset();
+ CRM_Core_Smarty::singleton()->clearTemplateVars();
+ $this->callAPISuccess('Contact', 'delete', ['id' => $this->contactID]);
}
/**
@@ -79,42 +89,85 @@ public function testDashboardContentEmptyContact() {
/**
* Test the content of the dashboard.
*/
- public function testDashboardContentContributions() {
- $this->contributionCreate(['contact_id' => $this->contactID]);
+ public function testDashboardContentContributionsWithInvoicingEnabled() {
+ $this->contributions[] = $this->contributionCreate([
+ 'contact_id' => $this->contactID,
+ 'receive_date' => '2018-11-21',
+ 'receipt_date' => '2018-11-22',
+ ]);
+ $this->contributions[] = $this->contributionCreate([
+ 'contact_id' => $this->contactID,
+ 'receive_date' => '2018-11-21',
+ 'receipt_date' => '2018-11-22',
+ 'trxn_id' => '',
+ 'invoice_id' => '',
+ ]);
+ $recur = $this->callAPISuccess('ContributionRecur', 'create', [
+ 'contact_id' => $this->contactID,
+ 'frequency_interval' => 1,
+ 'amount' => 5,
+ ]);
+ $this->contributions[] = $this->contributionCreate([
+ 'contact_id' => $this->contactID,
+ 'receive_date' => '2018-11-21',
+ 'amount_level' => 'high',
+ 'contribution_status_id' => 'Cancelled',
+ 'invoice_id' => NULL,
+ 'trxn_id' => NULL,
+ 'contribution_recur_id' => $recur['id'],
+ ]);
+ $this->callAPISuccess('Setting', 'create', ['invoicing' => 1]);
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
- '
Total Amount | Financial Type | Received date | Receipt Sent | Status | ',
- '
---|
$ 100.00 | Donation | ',
- ' | Completed |
',
+ 'Total Amount | Financial Type | Received date | Receipt Sent | Status | | ',
+ 'Completed | |
---|
assertPageContains($expectedStrings);
- $this->assertSmartyVariables(['invoicing' => NULL]);
+ $this->assertSmartyVariableArrayIncludes('contribute_rows', 0, [
+ 'contact_id' => $this->contactID,
+ 'contribution_id' => '1',
+ 'total_amount' => '100.00',
+ 'financial_type' => 'Donation',
+ 'contribution_source' => 'SSF',
+ 'receive_date' => '2018-11-21 00:00:00',
+ 'contribution_status' => 'Completed',
+ 'currency' => 'USD',
+ //'receipt_date' => '2018-11-22 00:00:00',
+ ]);
+
}
/**
* Test the content of the dashboard.
*/
- public function testDashboardContentContributionsWithInvoicingEnabled() {
- $this->markTestIncomplete('some issue on jenkins but not locally - disabling to investigage on master as this is an rc patch');
+ public function testDashboardContentContributions() {
$this->contributionCreate(['contact_id' => $this->contactID]);
- $this->callAPISuccess('Setting', 'create', ['invoicing' => 1]);
+ $this->contributions[] = civicrm_api3('Contribution', 'get', [
+ 'contact_id' => $this->contactID,
+ 'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
+ 'sequential' => 1,
+ ])['values'];
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
- 'Total Amount | Financial Type | Received date | Receipt Sent | Status | | ',
- 'Completed | |
---|
',
+ 'Total Amount | Financial Type | Received date | Receipt Sent | Status | ',
+ '$ 100.00 | Donation | ',
+ 'Completed | ',
];
$this->assertPageContains($expectedStrings);
- $this->assertSmartyVariables(['invoicing' => TRUE]);
}
/**
* Run the user dashboard.
*/
protected function runUserDashboard() {
+ $_REQUEST = ['reset' => 1, 'id' => $this->contactID];
$dashboard = new CRM_Contact_Page_View_UserDashBoard();
+ $dashboard->_contactId = $this->contactID;
$dashboard->run();
+ $_REQUEST = [];
}
}
diff --git a/tests/phpunit/CRMTraits/Page/PageTestTrait.php b/tests/phpunit/CRMTraits/Page/PageTestTrait.php
index 150582e7c59..493369af68d 100644
--- a/tests/phpunit/CRMTraits/Page/PageTestTrait.php
+++ b/tests/phpunit/CRMTraits/Page/PageTestTrait.php
@@ -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 @@ public function checkPageContent(&$content, $context, $tplName, &$object) {
* @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,6 +99,23 @@ protected function assertSmartyVariables($expectedVariables) {
}
}
+ /**
+ * 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.
*/
diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php
index 5e7f2479e80..0a9529957c2 100644
--- a/tests/phpunit/api/v3/ContributionPageTest.php
+++ b/tests/phpunit/api/v3/ContributionPageTest.php
@@ -1798,7 +1798,7 @@ public function testSubmitContributionPageWithPriceSet($thousandSeparator) {
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccessGetSingle('contribution', array(
'contribution_page_id' => $this->_ids['contribution_page'],
- 'contribution_status_id' => 2,
+ 'contribution_status_id' => 'Pending',
));
$this->assertEquals(80, $contribution['total_amount']);
$lineItems = $this->callAPISuccess('LineItem', 'get', array(
---|