6 class CRM_Core_FormTest
extends CiviUnitTestCase
{
9 * Simulate opening various forms. All we're looking to do here is
10 * see if any warnings or notices come up, the equivalent of red boxes
11 * on the screen, but which are hidden when using popup forms.
12 * So no assertions required.
14 * @param string $classname
15 * @param callable $additionalSetup
16 * Function that performs some additional setup steps specific to the form
18 * @dataProvider formClassList
20 public function testOpeningForms(string $classname, callable
$additionalSetup) {
21 $form = $this->getFormObject($classname);
23 // call the callable parameter we were passed in
24 $additionalSetup($form);
26 // typical quickform/smarty flow
28 $form->buildQuickForm();
29 $form->setDefaultValues();
30 $form->assign('action', $form->_action ?? CRM_Core_Action
::UPDATE
);
31 $form->getTemplate()->fetch($form->getTemplateFileName());
35 * Dataprovider for testOpeningForms().
36 * TODO: Add more forms!
39 * See first one below for description.
41 public function formClassList() {
43 // Array key is descriptive term to make it clearer which form it is when it fails.
47 // Function that performs some class-specific additional setup steps.
48 // If there's a lot of complex steps then that suggests it should have
49 // its own test elsewhere and doesn't fit well here.
50 function(CRM_Core_Form
$form) {},
52 'Assign Account to Financial Type' => [
53 'CRM_Financial_Form_FinancialTypeAccount',
54 function(CRM_Core_Form
$form) {
57 $form->_action
= CRM_Core_Action
::ADD
;
60 // This one is a bit flawed but the only point of this test is to catch
61 // simple stuff. This will catch e.g. "undefined index" and similar.
63 'CRM_Contact_Form_Search_Basic',
64 function(CRM_Core_Form
$form) {
65 $form->_action
= CRM_Core_Action
::BASIC
;