Merge branch '3.1' into 3.2

This commit is contained in:
Maxime Rainville 2022-03-17 15:20:37 +13:00
commit 228f2a3058
3 changed files with 31 additions and 4 deletions

View File

@ -9,6 +9,7 @@ use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField; use SilverStripe\Forms\FormField;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\UnsavedRelationList; use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension; use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\UserForms\Model\EditableFormField;
@ -112,8 +113,11 @@ class EditableSpamProtectionField extends EditableFormField
} }
// Get all candidates of the above types // Get all candidates of the above types
return $this $parent = $this->Parent();
->Parent() if (!$parent) {
return DataList::create(EditableFormField::class);
}
return $parent
->Fields() ->Fields()
->filter('ClassName', $typesInherit) ->filter('ClassName', $typesInherit)
->exclude('Title', ''); // Ignore this field and those without titles ->exclude('Title', ''); // Ignore this field and those without titles

View File

@ -23,7 +23,8 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.5",
"silverstripe/versioned": "^1.0", "silverstripe/versioned": "^1.0",
"squizlabs/php_codesniffer": "^3.0" "squizlabs/php_codesniffer": "^3.0",
"silverstripe/userforms": "^5"
}, },
"extra": { "extra": {
"expose": [ "expose": [
@ -39,4 +40,4 @@
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"minimum-stability": "dev", "minimum-stability": "dev",
"prefer-stable": true "prefer-stable": true
} }

View File

@ -2,6 +2,8 @@
namespace SilverStripe\SpamProtection\Tests; namespace SilverStripe\SpamProtection\Tests;
use ReflectionClass;
use SilverStripe\ORM\DataList;
use SilverStripe\UserForms\Model\UserDefinedForm; use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
@ -153,4 +155,24 @@ class EditableSpamProtectionFieldTest extends SapphireTest
return $editableFormFieldMock; return $editableFormFieldMock;
} }
public function testGetCandidateFieldsParentStatus()
{
$field = new EditableSpamProtectionField();
$field->Name = 'MyField';
$reflection = new ReflectionClass($field);
$method = $reflection->getMethod('getCandidateFields');
$method->setAccessible(true);
// Assert with no parent
$list = $method->invoke($field);
$this->assertTrue($list instanceof DataList);
// Assert with parent
$page = new UserDefinedForm();
$page->write();
$field->ParentID = $page->ID;
$field->ParentClass = get_class($page);
$field->write();
$list = $method->invoke($field);
$this->assertTrue($list instanceof DataList);
}
} }