mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Added DataDifferencerTest, starting by testing array-based values (AIR-39)
This commit is contained in:
parent
8cc1b4c852
commit
007eb259e0
57
tests/model/DataDifferencerTest.php
Normal file
57
tests/model/DataDifferencerTest.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class DataDifferencerTest extends SapphireTest {
|
||||
|
||||
static $fixture_file = 'sapphire/tests/model/DataDifferencerTest.yml';
|
||||
|
||||
protected $extraDataObjects = array('DataDifferencerTest_Object');
|
||||
|
||||
function testArrayValues() {
|
||||
$obj1 = $this->objFromFixture('DataDifferencerTest_Object', 'obj1');
|
||||
// create a new version
|
||||
$obj1->Choices = array('a');
|
||||
$obj1->write();
|
||||
$obj1v1 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, 1);
|
||||
$obj1v2 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, 2);
|
||||
$differ = new DataDifferencer($obj1v1, $obj1v2);
|
||||
$obj1Diff = $differ->diffedData();
|
||||
// TODO Using getter would split up field again, bug only caused by simulating
|
||||
// an array-based value in the first place.
|
||||
$this->assertContains('<ins>a</ins> <del>a,b</del>', $obj1Diff->getField('Choices'));
|
||||
}
|
||||
}
|
||||
|
||||
class DataDifferencerTest_Object extends DataObject implements TestOnly {
|
||||
|
||||
static $extensions = array('Versioned("Stage", "Live")');
|
||||
|
||||
static $db = array(
|
||||
'Choices' => "Varchar",
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
$choices = array(
|
||||
'a' => 'a',
|
||||
'b' => 'b',
|
||||
'c' => 'c',
|
||||
);
|
||||
$listField = new ListboxField('Choices', 'Choices', $choices);
|
||||
$fields->push($listField);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function getChoices() {
|
||||
return explode(',', $this->getField('Choices'));
|
||||
}
|
||||
|
||||
function setChoices($val) {
|
||||
$this->setField('Choices', (is_array($val)) ? implode(',', $val) : $val);
|
||||
}
|
||||
|
||||
}
|
3
tests/model/DataDifferencerTest.yml
Normal file
3
tests/model/DataDifferencerTest.yml
Normal file
@ -0,0 +1,3 @@
|
||||
DataDifferencerTest_Object:
|
||||
obj1:
|
||||
Choices: a,b
|
Loading…
x
Reference in New Issue
Block a user