From 007eb259e0c1e80e370cfb4e2f09e93fa289734c Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 29 Aug 2011 09:33:22 +0200 Subject: [PATCH] MINOR Added DataDifferencerTest, starting by testing array-based values (AIR-39) --- tests/model/DataDifferencerTest.php | 57 +++++++++++++++++++++++++++++ tests/model/DataDifferencerTest.yml | 3 ++ 2 files changed, 60 insertions(+) create mode 100644 tests/model/DataDifferencerTest.php create mode 100644 tests/model/DataDifferencerTest.yml diff --git a/tests/model/DataDifferencerTest.php b/tests/model/DataDifferencerTest.php new file mode 100644 index 000000000..7d80a18e7 --- /dev/null +++ b/tests/model/DataDifferencerTest.php @@ -0,0 +1,57 @@ +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('a a,b', $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); + } + +} \ No newline at end of file diff --git a/tests/model/DataDifferencerTest.yml b/tests/model/DataDifferencerTest.yml new file mode 100644 index 000000000..7da6dc710 --- /dev/null +++ b/tests/model/DataDifferencerTest.yml @@ -0,0 +1,3 @@ +DataDifferencerTest_Object: + obj1: + Choices: a,b \ No newline at end of file