/**
  * Tests `Collection::rewind` and `Collection::current`.
  */
 public function testNextRewindCurrent()
 {
     $collection = new DocumentSet(array('data' => array('title' => 'Lorem Ipsum', 'value' => 42, 'foo' => 'bar')));
     $this->assertEqual('Lorem Ipsum', $collection->current());
     $this->assertEqual(42, $collection->next());
     $this->assertEqual('bar', $collection->next());
     $this->assertEqual('Lorem Ipsum', $collection->rewind());
     $this->assertEqual(42, $collection->next());
 }
Exemple #2
0
 public function testPopulateResourceClose()
 {
     $resource = new MockResult();
     $doc = new DocumentSet(array('model' => $this->_model, 'result' => $resource));
     $model = $this->_model;
     $result = $doc->rewind();
     $this->assertTrue($result instanceof Document);
     $this->assertTrue(is_object($result['_id']));
     $expected = array('_id' => '4c8f86167675abfabdbf0300', 'title' => 'bar');
     $this->assertEqual($expected, $result->data());
     $expected = array('_id' => '5c8f86167675abfabdbf0301', 'title' => 'foo');
     $this->assertEqual($expected, $doc->next()->data());
     $expected = array('_id' => '6c8f86167675abfabdbf0302', 'title' => 'dib');
     $result = $doc->next()->data();
     $this->assertEqual($expected, $result);
     $this->assertNull($doc->next());
 }
Exemple #3
0
 public function testRewindData()
 {
     $doc = new DocumentSet(array('model' => $this->_model, 'data' => array(array('id' => 1, 'name' => 'One'), array('id' => 2, 'name' => 'Two'), array('id' => 3, 'name' => 'Three'))));
     $expected = array('id' => 1, 'name' => 'One');
     $result = $doc->rewind()->data();
     $this->assertEqual($expected, $result);
 }
 public function testPopulateResourceClose()
 {
     $result = new MockResult(array('data' => array(array('_id' => '4c8f86167675abfabdbf0300', 'title' => 'bar'), array('_id' => '5c8f86167675abfabdbf0301', 'title' => 'foo'), array('_id' => '6c8f86167675abfabdbf0302', 'title' => 'dib'))));
     $doc = new DocumentSet(array('model' => $this->_model, 'result' => $result));
     $result = $doc->rewind();
     $this->assertInstanceOf('lithium\\data\\entity\\Document', $result);
     $this->assertInternalType('string', $result['_id']);
     $expected = array('_id' => '4c8f86167675abfabdbf0300', 'title' => 'bar');
     $this->assertEqual($expected, $result->data());
     $expected = array('_id' => '5c8f86167675abfabdbf0301', 'title' => 'foo');
     $this->assertEqual($expected, $doc->next()->data());
     $expected = array('_id' => '6c8f86167675abfabdbf0302', 'title' => 'dib');
     $result = $doc->next()->data();
     $this->assertEqual($expected, $result);
     $this->assertFalse($doc->next());
 }
Exemple #5
0
 public function testPopulateResourceClose()
 {
     $resource = new MockDocumentSource();
     $resource->read();
     $doc = new DocumentSet(array('model' => 'lithium\\tests\\mocks\\data\\model\\MockDocumentPost', 'handle' => new MockDocumentSource(), 'result' => $resource));
     $result = $doc->rewind();
     $this->assertTrue(is_a($result, '\\lithium\\data\\entity\\Document'));
     $expected = array('id' => 2, 'name' => 'Moe');
     $result = $doc->next()->data();
     $this->assertEqual($expected, $result);
     $expected = array('id' => 3, 'name' => 'Roe');
     $result = $doc->next()->data();
     $this->assertEqual($expected, $result);
     $result = $doc->next();
     $this->assertNull($result);
 }