From: demeritcowboy <demeritcowboy@hotmail.com> Date: Sat, 14 Mar 2020 17:35:30 +0000 (-0400) Subject: fatal error when assigning account to financial type X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6048ed09b4c6af2b402f38b8622629e68b717637;p=civicrm-core.git fatal error when assigning account to financial type --- diff --git a/tests/phpunit/CRM/Core/FormTest.php b/tests/phpunit/CRM/Core/FormTest.php index 39dc9fa13c..fd7d695fb4 100644 --- a/tests/phpunit/CRM/Core/FormTest.php +++ b/tests/phpunit/CRM/Core/FormTest.php @@ -12,26 +12,51 @@ class CRM_Core_FormTest extends CiviUnitTestCase { * So no assertions required. * * @param string $classname + * @param callable $additionalSetup + * Function that performs some additional setup steps specific to the form + * * @dataProvider formClassList */ - public function testOpeningForms(string $classname) { + public function testOpeningForms(string $classname, callable $additionalSetup) { $form = $this->getFormObject($classname); + + // call the callable parameter we were passed in + $additionalSetup($form); + + // typical quickform/smarty flow $form->preProcess(); $form->buildQuickForm(); $form->setDefaultValues(); - $form->assign('action', CRM_Core_Action::UPDATE); + $form->assign('action', $form->_action ?? CRM_Core_Action::UPDATE); $form->getTemplate()->fetch($form->getTemplateFileName()); } /** * Dataprovider for testOpeningForms(). - * TODO: Add more forms! Use a descriptive array key so when it fails - * it will make it clearer what form it is, although you'll see the class - * anyway. + * TODO: Add more forms! + * + * @return array + * See first one below for description. */ public function formClassList() { return [ - 'Add New Tag' => ['CRM_Tag_Form_Edit'], + // Array key is descriptive term to make it clearer which form it is when it fails. + 'Add New Tag' => [ + // classname + 'CRM_Tag_Form_Edit', + // Function that performs some class-specific additional setup steps. + // If there's a lot of complex steps then that suggests it should have + // its own test elsewhere and doesn't fit well here. + function(CRM_Core_Form $form) {}, + ], + 'Assign Account to Financial Type' => [ + 'CRM_Financial_Form_FinancialTypeAccount', + function(CRM_Core_Form $form) { + $form->set('id', 1); + $form->set('aid', 1); + $form->_action = CRM_Core_Action::ADD; + }, + ], ]; }