mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Merge pull request #79 from creative-commoners/pulls/3.1/write-without-parent
FIX Allow fields without parents to be programatically created
This commit is contained in:
commit
68d550b817
@ -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
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"sminnee/phpunit": "^5.7",
|
"sminnee/phpunit": "^5.7",
|
||||||
"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": [
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user