mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
Merge pull request #91 from open-sausages/pulls/4.0/compat
BUG Fix issue with initial save
This commit is contained in:
commit
57bf2c15ce
@ -327,8 +327,7 @@ class TagField extends DropdownField
|
||||
if (!$values) {
|
||||
$values = array();
|
||||
}
|
||||
|
||||
if (empty($record) || empty($source) || empty($titleField)) {
|
||||
if (empty($record) || empty($titleField)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -313,6 +313,32 @@ class TagFieldTest extends SapphireTest
|
||||
$record
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test you can save without a source set
|
||||
*/
|
||||
public function testSaveEmptySource()
|
||||
{
|
||||
$record = new TagFieldTestBlogPost();
|
||||
$record->write();
|
||||
|
||||
// Clear database of tags
|
||||
TagFieldTestBlogTag::get()->removeAll();
|
||||
|
||||
$field = new TagField('Tags', '', TagFieldTestBlogTag::get());
|
||||
$field->setValue(['New Tag']);
|
||||
$field->setCanCreate(true);
|
||||
$field->saveInto($record);
|
||||
|
||||
$tag = TagFieldTestBlogTag::get()->first();
|
||||
$this->assertNotEmpty($tag);
|
||||
$this->assertEquals('New Tag', $tag->Title);
|
||||
$record = TagFieldTestBlogPost::get()->byID($record->ID);
|
||||
$this->assertEquals(
|
||||
$tag->ID,
|
||||
$record->Tags()->first()->ID
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TagFieldTestBlogTag extends DataObject implements TestOnly
|
||||
|
Loading…
Reference in New Issue
Block a user