/** * Ensures that the data returned from the `data()` method matches the * internal state of the object. */ public function testEnsureArrayExportFidelity() { $data = array('department_3' => 0, 4 => 0, 5 => 0, 6 => 0, '6x' => 0, 7 => 0, 8 => 0, 10 => 0, 12 => 0); $doc = new Document(compact('data')); $this->assertIdentical($data, $doc->data()); }
public function testUnset() { $doc = new Document(array('data' => array('title' => 'Post', 'content' => 'Lorem Ipsum', 'parsed' => null, 'permanent' => false))); $expected = array('title' => 'Post', 'content' => 'Lorem Ipsum', 'parsed' => null, 'permanent' => false); $result = $doc->data(); $this->assertEqual($expected, $result); unset($expected['title']); unset($doc->title); $result = $doc->data(); $this->assertEqual($expected, $result); unset($expected['parsed']); unset($doc->parsed); $result = $doc->data(); $this->assertEqual($expected, $result); unset($expected['permanent']); unset($doc->permanent); $result = $doc->data(); $this->assertEqual($expected, $result); unset($doc->none); }
public function testUpdatingArraysAndExporting() { $new = new Document(array('data' => array('name' => 'Acme, Inc.', 'active' => true))); $expected = array('name' => 'Acme, Inc.', 'active' => true); $result = $new->data(); $this->assertEqual($expected, $result); $new->foo = new DocumentSet(array('data' => array('bar'))); $expected = array('name' => 'Acme, Inc.', 'active' => true, 'foo' => array('bar')); $result = $new->data(); $this->assertEqual($expected, $result); $expected = 'bar'; $result = $new->foo[0]; $this->assertEqual($expected, $result); $new->foo[1] = 'baz'; $expected = 'baz'; $result = $new->data(); $this->assertEqual($expected, $result['foo'][1]); }
/** * Tests that a nested key on a previously saved document gets updated properly. */ public function testExistingNestedKeyOverwrite() { $doc = new Document(array('model' => $this->_model)); $doc->{'this.that'} = 'value1'; $this->assertEqual(array('this' => array('that' => 'value1')), $doc->data()); $result = Exporter::get('create', $doc->export()); $this->assertEqual(array('create' => array('this' => array('that' => 'value1'))), $result); $doc->sync(); $doc->{'this.that'} = 'value2'; $this->assertEqual(array('this' => array('that' => 'value2')), $doc->data()); $result = Exporter::get('update', $doc->export()); $this->assertEqual(array('update' => array('this.that' => 'value2')), $result); }
public function testWithArraySchema() { $model = $this->_model; $model::schema(array('_id' => array('type' => 'id'), 'list' => array('array' => true), 'list.foo' => array('type' => 'string'), 'list.bar' => array('type' => 'string'))); $doc = new Document(compact('model')); $doc->list[] = array('foo' => '!!', 'bar' => '??'); $data = array('list' => array(array('foo' => '!!', 'bar' => '??'))); $this->assertEqual($data, $doc->data()); $result = Exporter::get('create', $doc->export()); $this->assertEqual($data, $result['create']); $result = Exporter::get('update', $doc->export()); $this->assertEqual($data, $result['update']); $doc = new Document(compact('model')); $doc->list = array(); $doc->list[] = array('foo' => '!!', 'bar' => '??'); $data = array('list' => array(array('foo' => '!!', 'bar' => '??'))); $this->assertEqual($data, $doc->data()); $result = Exporter::get('create', $doc->export()); $this->assertEqual($result['create'], $data); $result = Exporter::get('update', $doc->export()); $this->assertEqual($result['update'], $data); }
public function testWithArraySchemaReusedName() { $model = $this->_model; $schema = array( '_id' => array('type' => 'id'), 'bar' => array('array' => true), 'foo' => array('type' => 'object', 'array' => true), 'foo.foo' => array('type' => 'integer'), 'foo.bar' => array('type' => 'integer') ); $doc = new Document(compact('model', 'schema')); $doc->foo[] = array('foo' => 1, 'bar' => 100); $expected = array('foo' => array(array('foo' => 1, 'bar' => 100))); $this->assertEqual($expected, $doc->data()); }
public function testInitializationWithNestedFields() { $doc = new Document(array('model' => $this->_model, 'data' => array('simple' => 'value', 'nested.foo' => 'first', 'nested.bar' => 'second', 'really.nested.key' => 'value'))); $this->assertEqual('value', $doc->simple); $this->assertEqual('first', $doc->nested->foo); $this->assertEqual('second', $doc->nested->bar); $this->assertEqual('value', $doc->really->nested->key); $result = array_keys($doc->data()); sort($result); $this->assertEqual(array('nested', 'really', 'simple'), $result); }