Inheritance: extends lithium\data\Collection
示例#1
0
 public function testValid()
 {
     $collection = new RecordSet();
     $this->assertFalse($collection->valid());
     $collection = new RecordSet(array('data' => array('value' => 42)));
     $this->assertTrue($collection->valid());
     $resource = new MockResult(array('records' => array()));
     $collection = new RecordSet(array('model' => $this->_model, 'result' => $resource));
     $this->assertFalse($collection->valid());
     $resource = new MockResult(array('records' => array(array('id' => 1, 'data' => 'data1'))));
     $collection = new RecordSet(array('model' => $this->_model, 'result' => $resource));
     $this->assertTrue($collection->valid());
 }
 /**
  * Applies a callback to a copy of all data in the collection
  * and returns the result.
  *
  * Overriden to load any data that has not yet been loaded.
  *
  * @param callback $filter The filter to apply.
  * @param array $options The available options are:
  *              - `'collect'`: If `true`, the results will be returned wrapped
  *              in a new `Collection` object or subclass.
  * @return object The filtered data.
  */
 public function map($filter, array $options = array())
 {
     $this->offsetGet(null);
     return parent::map($filter, $options);
 }
示例#3
0
	public function testRecordSet() {
		$expected = array(
			'post1' => array(
				'title' => 'My First Post',
				'content' => 'First Content...'
			),
			'post2' => array(
				'title' => 'My Second Post',
				'content' => 'Also some foobar text'
			),
			'post3' => array(
				'title' => 'My Third Post',
				'content' => 'I like to write some foobar foo too'
			)
		);
		$posts = new RecordSet(array('data' => $expected));

		$this->assertEqual($expected['post1'], $posts->first());
		$this->assertEqual($expected['post1'], $posts->current());
		$this->assertEqual($expected['post2'], $posts->next());
		$this->assertEqual($expected['post2'], $posts->current());
		$this->assertEqual($expected['post1'], $posts->prev());
		$this->assertEqual($expected['post2'], $posts->next());
		$this->assertEqual($expected['post3'], $posts->next());
		$this->assertEqual($expected['post2'], $posts->prev());
		$this->assertEqual($expected['post1'], $posts->rewind());
		$this->assertEqual($expected['post1'], $posts['post1']);
	}