Merge pull request #91 from open-sausages/pulls/4.0/compat

BUG Fix issue with initial save
This commit is contained in:
Daniel Hensby 2017-01-26 09:07:54 +00:00 committed by GitHub
commit 57bf2c15ce
2 changed files with 27 additions and 2 deletions

View File

@ -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;
}

View File

@ -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