Permalink
Browse files

MINOR Added DataDifferencerTest, starting by testing array-based valu…

…es (AIR-39)
  • Loading branch information...
1 parent 8cc1b4c commit 007eb259e0c1e80e370cfb4e2f09e93fa289734c @chillu chillu committed Aug 29, 2011
Showing with 60 additions and 0 deletions.
  1. +57 −0 tests/model/DataDifferencerTest.php
  2. +3 −0 tests/model/DataDifferencerTest.yml
@@ -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);
+ }
+
+}
@@ -0,0 +1,3 @@
+DataDifferencerTest_Object:
+ obj1:
+ Choices: a,b

0 comments on commit 007eb25

Please sign in to comment.