Пример #1
0
 public function testUpdateWithMultipleKeys()
 {
     $model = 'lithium\\tests\\mocks\\data\\model\\MockDocumentMultipleKey';
     $model::config(array('key' => array('id', 'rev'), 'foo' => true));
     $doc = new Document(compact('model'));
     $result = $model::meta('key');
     $this->assertEqual(array('id', 'rev'), $result);
     $doc->id = 3;
     $this->assertFalse($doc->exists());
     $doc->update(array(12, '1-2'));
     $this->assertTrue($doc->exists());
     $this->assertEqual(12, $doc->id);
     $this->assertEqual('1-2', $doc->rev);
 }
Пример #2
0
	/**
	 * Tests that documents nested within existing documents also exist, and vice versa.
	 */
	public function testNestedObjectExistence() {
		$model = $this->_model;
		$data = array('foo' => array('bar' => 'bar', 'baz' => 'dib'));
		$doc = new Document(compact('model', 'data') + array('exists' => false));

		$this->assertFalse($doc->exists());
		$this->assertFalse($doc->foo->exists());

		$doc = new Document(compact('model', 'data') + array('exists' => true));

		$this->assertTrue($doc->exists());
		$this->assertTrue($doc->foo->exists());
	}
Пример #3
0
 /**
  * Tests that documents nested within existing documents also exist, and vice versa.
  */
 public function testNestedObjectExistence()
 {
     $model = $this->_model;
     $data = array('foo' => array('bar' => 'bar', 'baz' => 'dib'), 'deeply' => array('nested' => array('object' => array('should' => 'exist'))));
     $doc = new Document(compact('model', 'data') + array('exists' => false));
     $this->assertFalse($doc->exists());
     $this->assertFalse($doc->foo->exists());
     $doc = new Document(compact('model', 'data') + array('exists' => true));
     $this->assertTrue($doc->exists());
     $this->assertTrue($doc->foo->exists());
     $this->assertTrue($doc->deeply->nested->object->exists());
     $doc = new Document(compact('model', 'data') + array('exists' => true));
     $subDoc = new Document(array('data' => array('bar' => 'stuff')));
     $this->assertTrue($doc->foo->exists());
     $this->assertFalse($subDoc->exists());
     $doc->foo = $subDoc;
     $this->assertTrue($doc->exists());
     $this->assertFalse($doc->foo->exists());
     $doc->sync();
     $this->assertTrue($doc->foo->exists());
 }
Пример #4
0
 public function testUpdateWithMultipleKeys()
 {
     $doc = new Document(array('model' => 'lithium\\tests\\mocks\\data\\model\\MockDocumentMultipleKey'));
     $expected = array('id', 'rev');
     $result = MockDocumentMultipleKey::meta('key');
     $this->assertEqual($expected, $result);
     $doc->id = 3;
     $this->assertFalse($doc->exists());
     $doc->update(array(12, '1-2'));
     $this->assertTrue($doc->exists());
     $expected = 12;
     $result = $doc->id;
     $this->assertEqual($expected, $result);
     $expected = '1-2';
     $result = $doc->rev;
     $this->assertEqual($expected, $result);
 }