*/
protected $contactID;
+ /**
+ * Contributions created for the test.
+ *
+ * @var array
+ */
+ protected $contributions = [];
+
/**
* Prepare for test
*/
$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]);
}
/**
/**
* 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)',
- '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th>',
- '</tr><tr id=\'rowid1\'class="odd-row"><td>$ 100.00 </td><td>Donation</td>',
- '</td><td></td><td>Completed</td></tr></table>',
+ '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th><th></th>',
+ '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&reset=1&id=1&cid=' . $this->contactID . '"><i class="crm-i fa-print"></i><span>Print Invoice</span></a></td></tr><tr id=\'rowid2\'',
];
+
$this->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)',
- '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th><th></th>',
- '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&reset=1&id=1&cid=' . $this->contactID . '"><i class="crm-i fa-print"></i><span>Print Invoice</span></a></td></tr></table>',
+ '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th>',
+ '<td>$ 100.00 </td><td>Donation</td>',
+ '<td>Completed</td>',
];
$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 = [];
}
}
*/
protected $pageContent;
+ /**
+ * @var \CRM_Core_Page
+ */
+ protected $page;
+
+ /**
+ * @var string
+ */
+ protected $tplName;
+
/**
* Variables assigned to smarty.
*
*/
protected $smartyVariables = [];
+ protected $context;
+
/**
* @param string $content
* @param string $context
*/
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 = '';
* @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));
}
}
}
}
+ /**
+ * 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.
*/