logInWithPermission('SITETREE_EDIT_ALL'); $udf = UserDefinedForm::create(['Title' => 'MyUDF']); $udfID = $udf->write(); // Set the current controller to CMSMain to satisfy EditableFormField::getCanCreateContext() /** @var CMSMain $controller */ $controller = Injector::inst()->get(CMSMain::class); $request = new HTTPRequest('GET', '/'); $request->setSession(new Session([])); $controller->setRequest($request); $controller->setCurrentPageID($udf->ID); $controller->pushCurrent(); $list = new DataList(EditableFormField::class); $field = EditableTextField::create([ 'ParentClass' => UserDefinedForm::class, 'ParentID' => $udfID, 'Title' => 'MyTitle', ]); $fieldID = $field->write(); $list->add($field); $gridField = new GridField('MyName', 'MyTitle', $list); $button = new GridFieldAddClassesButton([EditableTextField::class]); $request = new HTTPRequest('POST', 'url', [], [ 'Fields' => [ GridFieldEditableColumns::POST_KEY => [ $fieldID => [ 'ClassName' => EditableDateField::class, 'Title' => 'UpdatedTitle' ] ] ] ]); $gridField->setRequest($request); $button->handleAdd($gridField); $field = EditableFormField::get()->byID($fieldID); $this->assertSame(EditableDateField::class, $field->ClassName); $this->assertSame('UpdatedTitle', $field->Title); } }