Eileen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243118
Change subject: Add test class for reports
......................................................................
Add test class for reports
(not yet working but this is how we can at least get the tests to run over some
of the report code
Change-Id: I46db64bdd92a78c25c70ed21b55e697f4a9ca400
---
M sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
M sites/all/modules/wmf_reports/CRM/Report/Form/Contribute/WmfLybunt.php
A sites/all/modules/wmf_reports/tests/phpunit/WMFReportsTest.php
3 files changed, 278 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/18/243118/1
diff --git
a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
b/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
index 64433f0..e8e5089 100644
---
a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
+++
b/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
@@ -27,4 +27,64 @@
exchange_rate_cache_set( $currency, $timestamp, $rate );
}
}
+
+ /**
+ * API wrapper function from core (more or less).
+ *
+ * so we can ensure they succeed & throw exceptions without littering the
test with checks.
+ *
+ * This is not the full function but it we think it'w worth keeping a copy
it should maybe
+ * go in the parent.
+ *
+ * @param string $entity
+ * @param string $action
+ * @param array $params
+ * @param mixed $checkAgainst
+ * Optional value to check result against, implemented for getvalue,.
+ * getcount, getsingle. Note that for getvalue the type is checked
rather than the value
+ * for getsingle the array is compared against an array passed in - the
id is not compared (for
+ * better or worse )
+ *
+ * @return array|int
+ */
+ public function callAPISuccess($entity, $action, $params, $checkAgainst =
NULL) {
+ $params = array_merge(array(
+ 'version' => 3,
+ 'debug' => 1,
+ ),
+ $params
+ );
+ try {
+ $result = civicrm_api3($entity, $action, $params);
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ $this->assertEquals(0, $e->getMessage() .
print_r($e->getExtraParams(), TRUE));
+ }
+ $this->assertAPISuccess($result, "Failure in api call for $entity
$action");
+ return $result;
+ }
+
+ /**
+ * Check that api returned 'is_error' => 0.
+ *
+ * @param array $apiResult
+ * Api result.
+ * @param string $prefix
+ * Extra test to add to message.
+ */
+ public function assertAPISuccess($apiResult, $prefix = '') {
+ if (!empty($prefix)) {
+ $prefix .= ': ';
+ }
+ $errorMessage = empty($apiResult['error_message']) ? '' : " " .
$apiResult['error_message'];
+
+ if (!empty($apiResult['debug_information'])) {
+ $errorMessage .= "\n " . print_r($apiResult['debug_information'],
TRUE);
+ }
+ if (!empty($apiResult['trace'])) {
+ $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE);
+ }
+ $this->assertEquals(0, $apiResult['is_error'], $prefix .
$errorMessage);
+ }
+
}
diff --git
a/sites/all/modules/wmf_reports/CRM/Report/Form/Contribute/WmfLybunt.php
b/sites/all/modules/wmf_reports/CRM/Report/Form/Contribute/WmfLybunt.php
index 1597af7..8c69625 100644
--- a/sites/all/modules/wmf_reports/CRM/Report/Form/Contribute/WmfLybunt.php
+++ b/sites/all/modules/wmf_reports/CRM/Report/Form/Contribute/WmfLybunt.php
@@ -228,7 +228,10 @@
function select() {
$this->_columnHeaders = $select = array();
- $current_year = $this->_params['yid_value'];
+ if (!isset($params['yid_value'])) {
+ $this->_params['yid_value'] = date('Y');
+ }
+ $current_year = !empty($this->_params['yid_value']) ?
$this->_params['yid_value'] : date('Y');
$previous_year = $current_year - 1;
diff --git a/sites/all/modules/wmf_reports/tests/phpunit/WMFReportsTest.php
b/sites/all/modules/wmf_reports/tests/phpunit/WMFReportsTest.php
new file mode 100644
index 0000000..fc33f0f
--- /dev/null
+++ b/sites/all/modules/wmf_reports/tests/phpunit/WMFReportsTest.php
@@ -0,0 +1,214 @@
+<?php
+
+/**
+ * @group WMFReports
+ */
+class WMFReportsTest extends BaseWmfDrupalPhpUnitTestCase {
+
+ /**
+ * Tet api to get rows from reports.
+ *
+ * This test doesn't check what is retrieved - just that the reports can
be run
+ * without error.
+ *
+ * @dataProvider getReportTemplates
+ *
+ * @param $reportID
+ *
+ * @throws \PHPUnit_Framework_IncompleteTestError
+ */
+ public function testReportTemplateGetRowsAllReports($reportID) {
+ civicrm_initialize();
+
+ $this->_sethtmlGlobals();
+ if (stristr($reportID, 'has existing issues')) {
+ $this->markTestIncomplete($reportID);
+ }
+ $this->callAPISuccess('report_template', 'getrows', array(
+ 'report_id' => $reportID,
+ ));
+ }
+
+ /**
+ * Data provider function for getting report templates to test.
+ */
+ public static function getReportTemplates() {
+ return array(array('contribute/wmf_lybunt'),
array('contribute/reconciliation'), array('contribute/trends'),
array('contribute/recur'), array('contribute/detail'));
+ }
+
+ /**
+ * Ported function from core that prevents enotices & allows tests to
complete.
+ *
+ * FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules']
when the tests are ran all together
+ * (NB unclear if this is still required)
+ */
+ public function _sethtmlGlobals() {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
+ 'required' => array(
+ 'html_quickform_rule_required',
+ 'HTML/QuickForm/Rule/Required.php',
+ ),
+ 'maxlength' => array(
+ 'html_quickform_rule_range',
+ 'HTML/QuickForm/Rule/Range.php',
+ ),
+ 'minlength' => array(
+ 'html_quickform_rule_range',
+ 'HTML/QuickForm/Rule/Range.php',
+ ),
+ 'rangelength' => array(
+ 'html_quickform_rule_range',
+ 'HTML/QuickForm/Rule/Range.php',
+ ),
+ 'email' => array(
+ 'html_quickform_rule_email',
+ 'HTML/QuickForm/Rule/Email.php',
+ ),
+ 'regex' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'lettersonly' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'alphanumeric' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'numeric' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'nopunctuation' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'nonzero' => array(
+ 'html_quickform_rule_regex',
+ 'HTML/QuickForm/Rule/Regex.php',
+ ),
+ 'callback' => array(
+ 'html_quickform_rule_callback',
+ 'HTML/QuickForm/Rule/Callback.php',
+ ),
+ 'compare' => array(
+ 'html_quickform_rule_compare',
+ 'HTML/QuickForm/Rule/Compare.php',
+ ),
+ );
+ // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
+ $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
+ 'group' => array(
+ 'HTML/QuickForm/group.php',
+ 'HTML_QuickForm_group',
+ ),
+ 'hidden' => array(
+ 'HTML/QuickForm/hidden.php',
+ 'HTML_QuickForm_hidden',
+ ),
+ 'reset' => array(
+ 'HTML/QuickForm/reset.php',
+ 'HTML_QuickForm_reset',
+ ),
+ 'checkbox' => array(
+ 'HTML/QuickForm/checkbox.php',
+ 'HTML_QuickForm_checkbox',
+ ),
+ 'file' => array(
+ 'HTML/QuickForm/file.php',
+ 'HTML_QuickForm_file',
+ ),
+ 'image' => array(
+ 'HTML/QuickForm/image.php',
+ 'HTML_QuickForm_image',
+ ),
+ 'password' => array(
+ 'HTML/QuickForm/password.php',
+ 'HTML_QuickForm_password',
+ ),
+ 'radio' => array(
+ 'HTML/QuickForm/radio.php',
+ 'HTML_QuickForm_radio',
+ ),
+ 'button' => array(
+ 'HTML/QuickForm/button.php',
+ 'HTML_QuickForm_button',
+ ),
+ 'submit' => array(
+ 'HTML/QuickForm/submit.php',
+ 'HTML_QuickForm_submit',
+ ),
+ 'select' => array(
+ 'HTML/QuickForm/select.php',
+ 'HTML_QuickForm_select',
+ ),
+ 'hiddenselect' => array(
+ 'HTML/QuickForm/hiddenselect.php',
+ 'HTML_QuickForm_hiddenselect',
+ ),
+ 'text' => array(
+ 'HTML/QuickForm/text.php',
+ 'HTML_QuickForm_text',
+ ),
+ 'textarea' => array(
+ 'HTML/QuickForm/textarea.php',
+ 'HTML_QuickForm_textarea',
+ ),
+ 'fckeditor' => array(
+ 'HTML/QuickForm/fckeditor.php',
+ 'HTML_QuickForm_FCKEditor',
+ ),
+ 'tinymce' => array(
+ 'HTML/QuickForm/tinymce.php',
+ 'HTML_QuickForm_TinyMCE',
+ ),
+ 'dojoeditor' => array(
+ 'HTML/QuickForm/dojoeditor.php',
+ 'HTML_QuickForm_dojoeditor',
+ ),
+ 'link' => array(
+ 'HTML/QuickForm/link.php',
+ 'HTML_QuickForm_link',
+ ),
+ 'advcheckbox' => array(
+ 'HTML/QuickForm/advcheckbox.php',
+ 'HTML_QuickForm_advcheckbox',
+ ),
+ 'date' => array(
+ 'HTML/QuickForm/date.php',
+ 'HTML_QuickForm_date',
+ ),
+ 'static' => array(
+ 'HTML/QuickForm/static.php',
+ 'HTML_QuickForm_static',
+ ),
+ 'header' => array(
+ 'HTML/QuickForm/header.php',
+ 'HTML_QuickForm_header',
+ ),
+ 'html' => array(
+ 'HTML/QuickForm/html.php',
+ 'HTML_QuickForm_html',
+ ),
+ 'hierselect' => array(
+ 'HTML/QuickForm/hierselect.php',
+ 'HTML_QuickForm_hierselect',
+ ),
+ 'autocomplete' => array(
+ 'HTML/QuickForm/autocomplete.php',
+ 'HTML_QuickForm_autocomplete',
+ ),
+ 'xbutton' => array(
+ 'HTML/QuickForm/xbutton.php',
+ 'HTML_QuickForm_xbutton',
+ ),
+ 'advmultiselect' => array(
+ 'HTML/QuickForm/advmultiselect.php',
+ 'HTML_QuickForm_advmultiselect',
+ ),
+ );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/243118
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I46db64bdd92a78c25c70ed21b55e697f4a9ca400
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: civi-4.6.9
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits