From: demeritcowboy Date: Thu, 16 Jul 2020 14:35:18 +0000 (-0400) Subject: tests for processReportMode X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d45fdad695cc41c17a3844d1f1a3b34357cbdfdb;p=civicrm-core.git tests for processReportMode --- diff --git a/tests/phpunit/CRM/Report/Form/SampleForm.php b/tests/phpunit/CRM/Report/Form/SampleForm.php new file mode 100644 index 0000000000..f6cf4aa165 --- /dev/null +++ b/tests/phpunit/CRM/Report/Form/SampleForm.php @@ -0,0 +1,23 @@ +_outputMode; + } + + public function getAddPaging():bool { + return $this->addPaging; + } + +} diff --git a/tests/phpunit/CRM/Report/FormTest.php b/tests/phpunit/CRM/Report/FormTest.php index 0127615f6e..8ce39c5b99 100644 --- a/tests/phpunit/CRM/Report/FormTest.php +++ b/tests/phpunit/CRM/Report/FormTest.php @@ -83,4 +83,110 @@ class CRM_Report_FormTest extends CiviUnitTestCase { } } + /** + * Test the processReportMode function. + * + * @dataProvider reportModeProvider + * + * @param array $input + * @param array $expected + */ + public function testProcessReportMode($input, $expected) { + // This is a helper in the tests tree, not a real class in the main tree. + $form = new CRM_Report_Form_SampleForm(); + + $_REQUEST['output'] = $input['format']; + $_REQUEST['sendmail'] = $input['sendmail']; + + $form->processReportMode(); + + unset($_REQUEST['output']); + unset($_REQUEST['sendmail']); + + $this->assertEquals($expected, [ + $form->getOutputMode(), + $form->getAddPaging(), + $form->printOnly, + $form->_absoluteUrl, + ]); + } + + /** + * dataprovider for testProcessReportMode + * + * @return array + */ + public function reportModeProvider() { + return [ + 'print no mail' => [ + [ + 'format' => 'report_instance.print', + 'sendmail' => NULL, + ], + [ + // _outputMode + 'print', + // addPaging + FALSE, + // printOnly + TRUE, + // _absoluteUrl + FALSE, + ], + ], + 'print and mail' => [ + [ + 'format' => 'report_instance.print', + 'sendmail' => '1', + ], + ['print', FALSE, TRUE, TRUE], + ], + 'csv no mail' => [ + [ + 'format' => 'report_instance.csv', + 'sendmail' => NULL, + ], + ['csv', FALSE, TRUE, TRUE], + ], + 'csv and mail' => [ + [ + 'format' => 'report_instance.csv', + 'sendmail' => '1', + ], + ['csv', FALSE, TRUE, TRUE], + ], + 'pdf no mail' => [ + [ + 'format' => 'report_instance.pdf', + 'sendmail' => NULL, + ], + ['pdf', FALSE, TRUE, TRUE], + ], + 'pdf and mail' => [ + [ + 'format' => 'report_instance.pdf', + 'sendmail' => '1', + ], + ['pdf', FALSE, TRUE, TRUE], + ], + 'unknown format no mail' => [ + [ + 'format' => NULL, + 'sendmail' => NULL, + ], + [NULL, TRUE, FALSE, FALSE], + ], + 'unknown format and mail' => [ + [ + 'format' => NULL, + 'sendmail' => '1', + ], + // This is a bit inconsistent with the mail_report job which defaults + // to pdf when you don't specify a format. But for now this is what + // processReportMode does. + ['print', FALSE, TRUE, TRUE], + ], + ]; + } + }