fb310e7b |
1 | <?php |
2 | |
3 | /** |
4 | * @group headless |
5 | */ |
6 | class CRM_Core_FormTest extends CiviUnitTestCase { |
7 | |
8 | /** |
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. |
13 | * |
14 | * @param string $classname |
6048ed09 |
15 | * @param callable $additionalSetup |
16 | * Function that performs some additional setup steps specific to the form |
17 | * |
fb310e7b |
18 | * @dataProvider formClassList |
19 | */ |
6048ed09 |
20 | public function testOpeningForms(string $classname, callable $additionalSetup) { |
fb310e7b |
21 | $form = $this->getFormObject($classname); |
6048ed09 |
22 | |
23 | // call the callable parameter we were passed in |
24 | $additionalSetup($form); |
25 | |
26 | // typical quickform/smarty flow |
fb310e7b |
27 | $form->preProcess(); |
28 | $form->buildQuickForm(); |
29 | $form->setDefaultValues(); |
6048ed09 |
30 | $form->assign('action', $form->_action ?? CRM_Core_Action::UPDATE); |
fb310e7b |
31 | $form->getTemplate()->fetch($form->getTemplateFileName()); |
32 | } |
33 | |
34 | /** |
35 | * Dataprovider for testOpeningForms(). |
6048ed09 |
36 | * TODO: Add more forms! |
37 | * |
38 | * @return array |
39 | * See first one below for description. |
fb310e7b |
40 | */ |
41 | public function formClassList() { |
42 | return [ |
6048ed09 |
43 | // Array key is descriptive term to make it clearer which form it is when it fails. |
44 | 'Add New Tag' => [ |
45 | // classname |
46 | 'CRM_Tag_Form_Edit', |
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) {}, |
51 | ], |
52 | 'Assign Account to Financial Type' => [ |
53 | 'CRM_Financial_Form_FinancialTypeAccount', |
54 | function(CRM_Core_Form $form) { |
55 | $form->set('id', 1); |
56 | $form->set('aid', 1); |
57 | $form->_action = CRM_Core_Action::ADD; |
58 | }, |
59 | ], |
9611f1f2 |
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. |
62 | 'Find Contacts' => [ |
63 | 'CRM_Contact_Form_Search_Basic', |
64 | function(CRM_Core_Form $form) { |
65 | $form->_action = CRM_Core_Action::BASIC; |
66 | }, |
67 | ], |
2f8f4f9c |
68 | 'New Price Field' => [ |
69 | 'CRM_Price_Form_Field', |
70 | function(CRM_Core_Form $form) { |
71 | $form->set('sid', 1); |
72 | $form->_action = CRM_Core_Action::ADD; |
73 | }, |
74 | ], |
fb310e7b |
75 | ]; |
76 | } |
77 | |
78 | } |