Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing merge issues in `Document` test.

  • Loading branch information...
commit c9cc84df17f9858cf580e1eb655bf2ca662dcda7 1 parent f46b51a
@nateabele nateabele authored
View
29 data/collection/DocumentSet.php
@@ -39,6 +39,35 @@ public function sync($id = null, array $data = array(), array $options = array()
}
/**
+ * Determines if the `DocumentSet` has been modified since it was last saved
+ *
+ * @return boolean
+ */
+ public function modified() {
+ if (count($this->_original) !== count($this->_data)) {
+ return true;
+ }
+ foreach ($this->_original as $key => $doc) {
+ $updated = $this->_data[$key];
+ if (!isset($updated)) {
+ return true;
+ }
+ if ($doc !== $updated) {
+ return true;
+ }
+ if (!is_object($updated) || !method_exists($updated, 'modified')) {
+ continue;
+ }
+ $modified = $this->_data[$key]->modified();
+
+ if (in_array(true, $modified)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Adds conversions checks to ensure certain class types and embedded values are properly cast.
*
* @param string $format Currently only `array` is supported.
View
57 tests/cases/data/entity/DocumentTest.php
@@ -93,6 +93,34 @@ public function testSetField() {
}
public function testSyncModified() {
+ $doc = new Document();
+ $doc->_id = 4;
+ $doc->name = 'Four';
+ $doc->content = 'Lorem ipsum four';
+
+ $expected = array(
+ '_id' => true,
+ 'name' => true,
+ 'content' => true
+ );
+
+ $this->assertEqual($expected, $doc->modified());
+ $doc->sync();
+
+ $this->assertEqual(array_fill_keys(array_keys($expected), false), $doc->modified());
+
+ $doc->_id = 5;
+ $doc->content = null;
+ $doc->new = null;
+ $expected = array(
+ '_id' => true,
+ 'name' => false,
+ 'content' => true,
+ 'new' => true
+ );
+
+ $this->assertEqual($expected, $doc->modified());
+
$doc = new Document(array('model' => $this->_model));
$doc->id = 4;
$doc->name = 'Four';
@@ -101,25 +129,18 @@ public function testSyncModified() {
$doc->subdoc = array(
'setting' => 'something',
'foo' => 'bar',
- 'sub' => array(
- 'name' => 'A sub sub doc'
- )
+ 'sub' => array('name' => 'A sub sub doc')
);
$doc->subdocs = array(
- array(
- 'id' => 1
- ),
- array(
- 'id' => 2
- ),
- array(
- 'id' => 3
- ),
- array(
- 'id' => 4
- )
+ array('id' => 1),
+ array('id' => 2),
+ array('id' => 3),
+ array('id' => 4)
);
+ $fields = array('id', 'name', 'content', 'array', 'subdoc', 'subdocs');
+ $expected = array_fill_keys($fields, true);
+
$this->assertEqual($expected, $doc->modified());
$doc->sync();
@@ -149,11 +170,7 @@ public function testSyncModified() {
$this->assertEqual($expected, $doc->modified());
$doc->sync();
- $expected = array_fill_keys($fields, false);
-
- $doc->array[1] = array(
- 'foo' => 'bar'
- );
+ $doc->array[1] = array('foo' => 'bar');
$expected['array'] = true;
$this->assertEqual($expected, $doc->modified());
Please sign in to comment.
Something went wrong with that request. Please try again.