diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 9979e0d7f..ef114865b 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -124,14 +124,14 @@ public function index(HTTPRequest $request = null) { $form = $this->Form(); if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) { - $hasLocation = stristr($this->Content, '$UserDefinedForm'); + $hasLocation = stristr($this->Content ?? '', '$UserDefinedForm'); if ($hasLocation) { /** @see Requirements_Backend::escapeReplacement */ - $formEscapedForRegex = addcslashes($form->forTemplate(), '\\$'); + $formEscapedForRegex = addcslashes($form->forTemplate() ?? '', '\\$'); $content = preg_replace( '/(
]*>)?\\$UserDefinedForm(<\\/p>)?/i',
- $formEscapedForRegex,
- $this->Content
+ $formEscapedForRegex ?? '',
+ $this->Content ?? ''
);
return [
'Content' => DBField::create_field('HTMLText', $content),
@@ -260,7 +260,7 @@ public function process($data, $form)
$submittedField->Displayed = $field->isDisplayed($data);
if (!empty($data[$field->Name])) {
- if (in_array(EditableFileField::class, $field->getClassAncestry())) {
+ if (in_array(EditableFileField::class, $field->getClassAncestry() ?? [])) {
if (!empty($_FILES[$field->Name]['name'])) {
$foldername = $field->getFormField()->getFolderName();
@@ -371,15 +371,15 @@ public function process($data, $form)
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
if ($submittedFormField && $submittedFormField->Value && is_string($submittedFormField->Value)) {
- $email->setReplyTo(explode(',', $submittedFormField->Value));
+ $email->setReplyTo(explode(',', $submittedFormField->Value ?? ''));
}
} elseif ($recipient->EmailReplyTo) {
- $email->setReplyTo(explode(',', $recipient->EmailReplyTo));
+ $email->setReplyTo(explode(',', $recipient->EmailReplyTo ?? ''));
}
// check for a specified from; otherwise fall back to server defaults
if ($recipient->EmailFrom) {
- $email->setFrom(explode(',', $recipient->EmailFrom));
+ $email->setFrom(explode(',', $recipient->EmailFrom ?? ''));
}
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
@@ -390,12 +390,12 @@ public function process($data, $form)
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
if ($submittedFormField && is_string($submittedFormField->Value)) {
- $email->setTo(explode(',', $submittedFormField->Value));
+ $email->setTo(explode(',', $submittedFormField->Value ?? ''));
} else {
- $email->setTo(explode(',', $recipient->EmailAddress));
+ $email->setTo(explode(',', $recipient->EmailAddress ?? ''));
}
} else {
- $email->setTo(explode(',', $recipient->EmailAddress));
+ $email->setTo(explode(',', $recipient->EmailAddress ?? ''));
}
} catch (Swift_RfcComplianceException $e) {
// The sending address is empty and/or invalid. Log and skip sending.
@@ -415,7 +415,7 @@ public function process($data, $form)
if ($emailSubject && $emailSubject->exists()) {
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
- if ($submittedFormField && trim($submittedFormField->Value)) {
+ if ($submittedFormField && trim($submittedFormField->Value ?? '')) {
$email->setSubject($submittedFormField->Value);
} else {
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
@@ -428,7 +428,7 @@ public function process($data, $form)
if ((bool)$recipient->SendPlain) {
// decode previously encoded html tags because the email is being sent as text/plain
- $body = html_entity_decode($emailData['Body']) . "\n";
+ $body = html_entity_decode($emailData['Body'] ?? '') . "\n";
if (isset($emailData['Fields']) && !$emailData['HideFormData']) {
foreach ($emailData['Fields'] as $field) {
if ($field instanceof SubmittedFileField) {
@@ -474,7 +474,7 @@ public function process($data, $form)
// to allow us to get through the finshed method
if (!$this->Form()->getSecurityToken()->isEnabled()) {
$randNum = rand(1, 1000);
- $randHash = md5($randNum);
+ $randHash = md5($randNum ?? '');
$session->set('FormProcessed', $randHash);
$session->set('FormProcessedNum', $randNum);
}
@@ -531,7 +531,7 @@ public function finished()
// make sure the session matches the SecurityID and is not left over from another form
if ($formProcessed != $securityID) {
// they may have disabled tokens on the form
- $securityID = md5($this->getRequest()->getSession()->get('FormProcessedNum'));
+ $securityID = md5($this->getRequest()->getSession()->get('FormProcessedNum') ?? '');
if ($formProcessed != $securityID) {
return $this->redirect($this->Link() . $referrer);
}
@@ -571,7 +571,7 @@ protected function buildWatchJS($watch)
$operations = implode(" {$conjunction} ", $rule['operations']);
$target = $rule['targetFieldID'];
$holder = $rule['holder'];
- $isFormStep = strpos($target, 'EditableFormStep') !== false;
+ $isFormStep = strpos($target ?? '', 'EditableFormStep') !== false;
$result .= <<
";
$query = "ALTER TABLE $db DROP COLUMN $column";
DB::query($query);
diff --git a/code/UserForm.php b/code/UserForm.php
index e3632776f..2909959c8 100644
--- a/code/UserForm.php
+++ b/code/UserForm.php
@@ -255,7 +255,7 @@ public function getCMSFields()
$columns = array();
foreach (DB::query($columnSQL)->map() as $name => $title) {
- $columns[$name] = trim(strtr($title, '.', ' '));
+ $columns[$name] = trim(strtr($title ?? '', '.', ' '));
}
$config = GridFieldConfig::create();
diff --git a/tests/php/Control/UserDefinedFormAdminTest.php b/tests/php/Control/UserDefinedFormAdminTest.php
index 1effe7520..80dadf7f2 100644
--- a/tests/php/Control/UserDefinedFormAdminTest.php
+++ b/tests/php/Control/UserDefinedFormAdminTest.php
@@ -106,7 +106,7 @@ public function testConfirmfolderformFields()
null,
['X-FormSchema-Request' => 'auto,schema,state,errors']
);
- $schemaData = json_decode($response->getBody(), true);
+ $schemaData = json_decode($response->getBody() ?? '', true);
$this->assertEquals('ConfirmFolderForm', $schemaData['schema']['name']);
$this->assertField($schemaData, 'FolderOptions', ['component' => 'OptionsetField']);
@@ -128,7 +128,7 @@ public function testConfirmfolderformDefaultFolder()
null,
['X-FormSchema-Request' => 'auto,schema,state,errors']
);
- $schemaData = json_decode($response->getBody(), true);
+ $schemaData = json_decode($response->getBody() ?? '', true);
$this->assertEquals('ConfirmFolderForm', $schemaData['schema']['name']);
$this->assertField($schemaData, 'FolderOptions', ['component' => 'OptionsetField']);
diff --git a/tests/php/Control/UserDefinedFormControllerTest.php b/tests/php/Control/UserDefinedFormControllerTest.php
index a198f4134..f0acfbe0d 100644
--- a/tests/php/Control/UserDefinedFormControllerTest.php
+++ b/tests/php/Control/UserDefinedFormControllerTest.php
@@ -96,7 +96,7 @@ public function testProcess()
// submitted html tags are escaped for the html value
$value = 'class="readonly">My body html Basic Value <b>HTML</b>';
- $this->assertTrue(strpos($email['Content'], $value) !== false, 'Email contains the merge field value');
+ $this->assertTrue(strpos($email['Content'] ?? '', $value ?? '') !== false, 'Email contains the merge field value');
$value = $parser->getBySelector('dd');
$this->assertEquals('Basic Value HTML', (string) $value[0], 'Email contains the value');
@@ -198,14 +198,14 @@ public function testForm()
$this->assertEquals($controller->Form()->getName(), 'Form_' . $form->ID, 'The form is referenced as Form');
$this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
$this->assertEquals($controller->Form()->Actions()->Count(), 1);
- $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired() ?? []), 0);
$requiredForm = $this->objFromFixture(UserDefinedForm::class, 'validation-form');
$controller = new UserDefinedFormController($requiredForm);
$this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
$this->assertEquals($controller->Form()->Actions()->Count(), 1);
- $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired() ?? []), 1);
}
public function testGetFormFields()
@@ -413,7 +413,7 @@ public function testImageThumbnailCreated()
'type' => 'image/jpeg',
'tmp_name' => $path,
'error' => 0,
- 'size' => filesize($path),
+ 'size' => filesize($path ?? ''),
]
];
$_FILES[$field->Name] = $data[$field->Name];
@@ -449,7 +449,7 @@ public function testRecipientAttachment()
'type' => 'image/jpeg',
'tmp_name' => $path,
'error' => 0,
- 'size' => filesize($path),
+ 'size' => filesize($path ?? ''),
]
];
$_FILES[$field->Name] = $data[$field->Name];
diff --git a/tests/php/FormField/UserFormsCheckboxSetFieldTest.php b/tests/php/FormField/UserFormsCheckboxSetFieldTest.php
index be36f0064..85738e677 100644
--- a/tests/php/FormField/UserFormsCheckboxSetFieldTest.php
+++ b/tests/php/FormField/UserFormsCheckboxSetFieldTest.php
@@ -46,6 +46,6 @@ public function testCustomErrorMessageValidationAttributesHTML()
$userFormsCheckboxSetField = $editableCheckboxGroupField->getFormField();
$html = $userFormsCheckboxSetField->renderWith(UserFormsCheckboxSetField::class)->getValue();
$attributesHTML = 'data-rule-required="true" data-msg-required="My custom error message with 'single' and "double" quotes"';
- $this->assertTrue(strpos($html, $attributesHTML) > 0);
+ $this->assertTrue(strpos($html ?? '', $attributesHTML ?? '') > 0);
}
}
diff --git a/tests/php/FormField/UserFormsOptionSetFieldTest.php b/tests/php/FormField/UserFormsOptionSetFieldTest.php
index abd27164a..9d7096140 100644
--- a/tests/php/FormField/UserFormsOptionSetFieldTest.php
+++ b/tests/php/FormField/UserFormsOptionSetFieldTest.php
@@ -19,6 +19,6 @@ public function testCustomErrorMessageValidationAttributesHTML()
$userFormsOptionSetField = $radio->getFormField();
$html = $userFormsOptionSetField->renderWith(UserFormsOptionSetField::class)->getValue();
$attributesHTML = 'data-rule-required="true" data-msg-required="My custom error message with 'single' and "double" quotes"';
- $this->assertTrue(strpos($html, $attributesHTML) > 0);
+ $this->assertTrue(strpos($html ?? '', $attributesHTML ?? '') > 0);
}
}
diff --git a/tests/php/Model/UserDefinedFormTest.php b/tests/php/Model/UserDefinedFormTest.php
index 6f040f487..d78c1a1b1 100644
--- a/tests/php/Model/UserDefinedFormTest.php
+++ b/tests/php/Model/UserDefinedFormTest.php
@@ -100,8 +100,8 @@ public function testGetCMSFieldsShowInSummary()
$summaryFields = $gridFieldDataColumns->getDisplayFields($submissionsgrid);
- $this->assertContains('SummaryShow', array_keys($summaryFields), 'Summary field not showing displayed field');
- $this->assertNotContains('SummaryHide', array_keys($summaryFields), 'Summary field showing displayed field');
+ $this->assertContains('SummaryShow', array_keys($summaryFields ?? []), 'Summary field not showing displayed field');
+ $this->assertNotContains('SummaryHide', array_keys($summaryFields ?? []), 'Summary field showing displayed field');
}
public function testEmailRecipientPopup()
@@ -177,13 +177,13 @@ public function testGetEmailTemplateDropdownValues()
// Installation path can be as a project when testing in Travis, so check partial match
$foundKey = false;
- foreach (array_keys($result) as $key) {
- if (strpos($key, 'email' . DIRECTORY_SEPARATOR . 'SubmittedFormEmail') !== false) {
+ foreach (array_keys($result ?? []) as $key) {
+ if (strpos($key ?? '', 'email' . DIRECTORY_SEPARATOR . 'SubmittedFormEmail') !== false) {
$foundKey = true;
}
}
$this->assertTrue($foundKey);
- $this->assertTrue(in_array('SubmittedFormEmail', array_values($result)));
+ $this->assertTrue(in_array('SubmittedFormEmail', array_values($result ?? [])));
}
public function testEmailTemplateExists()
@@ -195,7 +195,7 @@ public function testEmailTemplateExists()
$recipient->EmailAddress = 'test@example.com';
// Set the default template
- $recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));
+ $recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues() ?? []));
$recipient->write();
// The default template exists