Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to enable UserDashboard tests to all run #13147

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 65 additions & 12 deletions tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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]);
}

/**
Expand All @@ -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)',
'<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&amp;reset=1&amp;id=1&amp;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&amp;reset=1&amp;id=1&amp;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 = [];
}

}
36 changes: 35 additions & 1 deletion tests/phpunit/CRMTraits/Page/PageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,25 @@ trait CRMTraits_Page_PageTestTrait {
*/
protected $pageContent;

/**
* @var \CRM_Core_Page
*/
protected $page;

/**
* @var string
*/
protected $tplName;

/**
* Variables assigned to smarty.
*
* @var array
*/
protected $smartyVariables = [];

protected $context;

/**
* @param string $content
* @param string $context
Expand All @@ -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 = '';
Expand All @@ -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));
}
}

Expand All @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down