Skip to content

Commit

Permalink
Merge pull request #21725 from demeritcowboy/maxfilesize2
Browse files Browse the repository at this point in the history
[NFC] Unit test fixes for the problem of quickform rules going missing
  • Loading branch information
eileenmcnaughton authored Oct 5, 2021
2 parents 57fd536 + a332e21 commit 30b363b
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 216 deletions.
2 changes: 0 additions & 2 deletions tests/phpunit/CRM/Batch/Form/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ public function setUp(): void {

$session = CRM_Core_Session::singleton();
$session->set('dateTypes', 1);
$this->_sethtmlGlobals();

}

/**
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,6 @@ public function testGetRelatedCases() {

/**
* Test various things after a case is closed.
*
* This annotation is not ideal, but without it there is some kind of
* messup that happens to quickform that persists between tests, e.g.
* it can't add maxfilesize validation rules.
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testCaseClosure() {
$loggedInUser = $this->createLoggedInUser();
Expand Down
5 changes: 0 additions & 5 deletions tests/phpunit/CRM/Contact/Form/Task/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public function testPostProcessWithSignature(): void {

$form->_allContactIds = $form->_toContactIds = $form->_contactIds;
$form->_fromEmails = [$loggedInEmail['id'] => '[email protected]'];
// This rule somehow disappears if there's a form-related test before us,
// so register it again. See packages/HTML/QuickForm/file.php.
// update - actually - it's never registered. Even in form made
// I can see it missing - It's really weird.
$form->registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');
$form->isSearchContext = FALSE;
$form->buildForm();
$form->submit(array_merge($form->_defaultValues, [
Expand Down
29 changes: 7 additions & 22 deletions tests/phpunit/CRM/Core/DAOConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,21 @@
/**
* Class for testing new DAO meet required standards.
*
* Class CRM_Core_DAOTest
* @group headless
*/
class CRM_Core_DAOConformanceTest extends CiviUnitTestCase {

/**
* Check all fields have defined titles.
*
* @dataProvider getAllDAO
*/
public function testFieldsHaveTitles($class) {
$dao = new $class();
$fields = $dao->fields();
foreach ($fields as $name => $field) {
$this->assertArrayHasKey('title', $field, "A title must be defined for $name in $class");
public function testFieldsHaveTitles() {
foreach (CRM_Core_DAO_AllCoreTables::getClasses() as $class) {
$dao = new $class();
$fields = $dao->fields();
foreach ($fields as $name => $field) {
$this->assertArrayHasKey('title', $field, "A title must be defined for $name in $class");
}
}
}

/**
* Get all DAO classes.
*/
public function getAllDAO() {
// Ugh. Need full bootstrap to enumerate classes.
$this->setUp();
$classList = CRM_Core_DAO_AllCoreTables::getClasses();
$return = [];
foreach ($classList as $class) {
$return[] = [$class];
}
return $return;
}

}
4 changes: 0 additions & 4 deletions tests/phpunit/CRM/Core/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public function testOpeningForms(string $url) {
$_REQUEST[$param] = $value;
}

require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm();
$form->registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');

$item = CRM_Core_Invoke::getItem([$_GET['q']]);
ob_start();
CRM_Core_Invoke::runItem($item);
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/CRM/Core/I18n/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ public function testUiLanguages() {

/**
* Quirk in strtolower does not handle "I" as expected, compared to mb_strtolower.
* I think setting locale messes up something that I don't know how to reset,
* so see if these help:
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testInsertTurkish() {
CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS foo");
Expand Down
173 changes: 0 additions & 173 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ protected function setUp(): void {
error_reporting(E_ALL);

$this->renameLabels();
$this->_sethtmlGlobals();
$this->ensureMySQLMode(['IGNORE_SPACE', 'ERROR_FOR_DIVISION_BY_ZERO', 'STRICT_TRANS_TABLES']);
}

Expand Down Expand Up @@ -2248,178 +2247,6 @@ public function financialAccountDelete($name) {
}
}

/**
* 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() {
$GLOBALS['_HTML_QuickForm_registered_rules'] = [
'required' => [
'html_quickform_rule_required',
'HTML/QuickForm/Rule/Required.php',
],
'maxlength' => [
'html_quickform_rule_range',
'HTML/QuickForm/Rule/Range.php',
],
'minlength' => [
'html_quickform_rule_range',
'HTML/QuickForm/Rule/Range.php',
],
'rangelength' => [
'html_quickform_rule_range',
'HTML/QuickForm/Rule/Range.php',
],
'email' => [
'html_quickform_rule_email',
'HTML/QuickForm/Rule/Email.php',
],
'regex' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'lettersonly' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'alphanumeric' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'numeric' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'nopunctuation' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'nonzero' => [
'html_quickform_rule_regex',
'HTML/QuickForm/Rule/Regex.php',
],
'callback' => [
'html_quickform_rule_callback',
'HTML/QuickForm/Rule/Callback.php',
],
'compare' => [
'html_quickform_rule_compare',
'HTML/QuickForm/Rule/Compare.php',
],
];
// FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = [
'group' => [
'HTML/QuickForm/group.php',
'HTML_QuickForm_group',
],
'hidden' => [
'HTML/QuickForm/hidden.php',
'HTML_QuickForm_hidden',
],
'reset' => [
'HTML/QuickForm/reset.php',
'HTML_QuickForm_reset',
],
'checkbox' => [
'HTML/QuickForm/checkbox.php',
'HTML_QuickForm_checkbox',
],
'file' => [
'HTML/QuickForm/file.php',
'HTML_QuickForm_file',
],
'image' => [
'HTML/QuickForm/image.php',
'HTML_QuickForm_image',
],
'password' => [
'HTML/QuickForm/password.php',
'HTML_QuickForm_password',
],
'radio' => [
'HTML/QuickForm/radio.php',
'HTML_QuickForm_radio',
],
'button' => [
'HTML/QuickForm/button.php',
'HTML_QuickForm_button',
],
'submit' => [
'HTML/QuickForm/submit.php',
'HTML_QuickForm_submit',
],
'select' => [
'HTML/QuickForm/select.php',
'HTML_QuickForm_select',
],
'hiddenselect' => [
'HTML/QuickForm/hiddenselect.php',
'HTML_QuickForm_hiddenselect',
],
'text' => [
'HTML/QuickForm/text.php',
'HTML_QuickForm_text',
],
'textarea' => [
'HTML/QuickForm/textarea.php',
'HTML_QuickForm_textarea',
],
'fckeditor' => [
'HTML/QuickForm/fckeditor.php',
'HTML_QuickForm_FCKEditor',
],
'tinymce' => [
'HTML/QuickForm/tinymce.php',
'HTML_QuickForm_TinyMCE',
],
'dojoeditor' => [
'HTML/QuickForm/dojoeditor.php',
'HTML_QuickForm_dojoeditor',
],
'link' => [
'HTML/QuickForm/link.php',
'HTML_QuickForm_link',
],
'advcheckbox' => [
'HTML/QuickForm/advcheckbox.php',
'HTML_QuickForm_advcheckbox',
],
'date' => [
'HTML/QuickForm/date.php',
'HTML_QuickForm_date',
],
'static' => [
'HTML/QuickForm/static.php',
'HTML_QuickForm_static',
],
'header' => [
'HTML/QuickForm/header.php',
'HTML_QuickForm_header',
],
'html' => [
'HTML/QuickForm/html.php',
'HTML_QuickForm_html',
],
'hierselect' => [
'HTML/QuickForm/hierselect.php',
'HTML_QuickForm_hierselect',
],
'autocomplete' => [
'HTML/QuickForm/autocomplete.php',
'HTML_QuickForm_autocomplete',
],
'xbutton' => [
'HTML/QuickForm/xbutton.php',
'HTML_QuickForm_xbutton',
],
'advmultiselect' => [
'HTML/QuickForm/advmultiselect.php',
'HTML_QuickForm_advmultiselect',
],
];
}

/**
* Set up an acl allowing contact to see 2 specified groups
* - $this->_permissionedGroup & $this->_permissionedDisabledGroup
Expand Down

0 comments on commit 30b363b

Please sign in to comment.