-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
dev/core#534 fix failure of print invoice to display on settings page #13137
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9886779
Add test for user dashboard
eileenmcnaughton 8d33433
Use onToggle feature for setting user_dashboard_options when toggling…
eileenmcnaughton d0df87f
Use function to determinie if invoicing is enabled which accounts for…
eileenmcnaughton e0001b1
Test fixes, better cleanup
eileenmcnaughton b3e69c9
Remove static var from env function.
eileenmcnaughton 97724d9
Disable function that doesn't work on jenkins (but does locally) for not
eileenmcnaughton f885761
Fix missing Pay now link
eileenmcnaughton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2018 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2018 | ||
*/ | ||
class CRM_Invoicing_Utils { | ||
|
||
/** | ||
* Function to call when invoicing is toggled on or off. | ||
* | ||
* We add or remove invoicing from the user dashboard here. | ||
* | ||
* @param bool $oldValue | ||
* @param bool $newValue | ||
* @param array $metadata | ||
*/ | ||
public static function onToggle($oldValue, $newValue, $metadata) { | ||
if ($oldValue == $newValue) { | ||
return; | ||
} | ||
$existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config::domainID()]['user_dashboard_options']; | ||
$optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values']; | ||
$invoiceKey = array_search('Invoices / Credit Notes', $optionValues); | ||
$existingIndex = in_array($invoiceKey, $existingUserViewOptions); | ||
|
||
if ($newValue && $existingIndex === FALSE) { | ||
$existingUserViewOptions[] = $invoiceKey; | ||
} | ||
elseif (!$newValue && $existingIndex !== FALSE) { | ||
unset($existingUserViewOptions[$existingIndex]); | ||
} | ||
civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]); | ||
} | ||
|
||
/** | ||
* Function to call to determine if invoicing is enabled. | ||
* | ||
* Historically the invoicing was declared as a setting but actually | ||
* set within contribution_invoice_settings (which stores multiple settings | ||
* as an array in a non-standard way). | ||
* | ||
* We check both here. But will deprecate the latter in time. | ||
*/ | ||
public static function isInvoicingEnabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattwire it's really only the second part of these 2 functions that wouldn't be needed without the historical weirdness - but I'm inclined to think a Utils class for invoicing is a good thing to have - part of the dream of one day moving invoicing back out of core :-) |
||
if (Civi::settings()->get('invoicing')) { | ||
return TRUE; | ||
} | ||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | ||
return CRM_Utils_Array::value('invoicing', $invoiceSettings); | ||
} | ||
|
||
/** | ||
* Function to call to determine default invoice page. | ||
* | ||
* Historically the invoicing was declared as a setting but actually | ||
* set within contribution_invoice_settings (which stores multiple settings | ||
* as an array in a non-standard way). | ||
* | ||
* We check both here. But will deprecate the latter in time. | ||
*/ | ||
public static function getDefaultPaymentPage() { | ||
$value = Civi::settings()->get('default_invoice_page'); | ||
if (is_numeric($value)) { | ||
return $value; | ||
} | ||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | ||
return CRM_Utils_Array::value('default_invoice_page', $invoiceSettings); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2018 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Test class for CRM_Contact_Page_View_UserDashBoard | ||
* | ||
* @package CiviCRM | ||
* @group headless | ||
*/ | ||
class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { | ||
|
||
use CRMTraits_Page_PageTestTrait; | ||
|
||
/** | ||
* Contact ID of logged in user. | ||
* | ||
* @var int | ||
*/ | ||
protected $contactID; | ||
|
||
/** | ||
* Prepare for test | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
$this->contactID = $this->createLoggedInUser(); | ||
$this->listenForPageContent(); | ||
} | ||
|
||
/** | ||
* Clean up after each test. | ||
*/ | ||
public function tearDown() { | ||
$this->quickCleanUpFinancialEntities(); | ||
$this->quickCleanup(['civicrm_uf_match']); | ||
CRM_Utils_Hook::singleton()->reset(); | ||
} | ||
|
||
/** | ||
* Test the content of the dashboard. | ||
*/ | ||
public function testDashboardContentEmptyContact() { | ||
$this->runUserDashboard(); | ||
$expectedStrings = [ | ||
'You are not currently subscribed to any Groups', | ||
'There are no contributions on record for you.', | ||
'There are no Pledges for your record.', | ||
'You are not registered for any current or upcoming Events.', | ||
'There are no memberships on record for you.', | ||
'You do not have any active Personal Campaign pages.', | ||
]; | ||
$this->assertPageContains($expectedStrings); | ||
} | ||
|
||
/** | ||
* Test the content of the dashboard. | ||
*/ | ||
public function testDashboardContentContributions() { | ||
$this->contributionCreate(['contact_id' => $this->contactID]); | ||
$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>', | ||
]; | ||
$this->assertPageContains($expectedStrings); | ||
$this->assertSmartyVariables(['invoicing' => NULL]); | ||
} | ||
|
||
/** | ||
* 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'); | ||
$this->contributionCreate(['contact_id' => $this->contactID]); | ||
$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><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>', | ||
]; | ||
$this->assertPageContains($expectedStrings); | ||
$this->assertSmartyVariables(['invoicing' => TRUE]); | ||
} | ||
|
||
/** | ||
* Run the user dashboard. | ||
*/ | ||
protected function runUserDashboard() { | ||
$dashboard = new CRM_Contact_Page_View_UserDashBoard(); | ||
$dashboard->run(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enotice fix for test to pass