lithium\tests\cases\data\CollectionTest::testArrayFiltering PHP Method

testArrayFiltering() public method

Tests that arrays can be used to filter objects in find() and first() methods.
public testArrayFiltering ( )
    public function testArrayFiltering()
    {
        $collection = new MockCollection(array('data' => array(new Entity(array('data' => array('id' => 1, 'name' => 'Annie', 'active' => 1))), new Entity(array('data' => array('id' => 2, 'name' => 'Zilean', 'active' => 1))), new Entity(array('data' => array('id' => 3, 'name' => 'Trynamere', 'active' => 0))), new Entity(array('data' => array('id' => 4, 'name' => 'Katarina', 'active' => 1))), new Entity(array('data' => array('id' => 5, 'name' => 'Nunu', 'active' => 0))))));
        $result = $collection->find(array('active' => 1))->data();
        $expected = array(0 => array('id' => 1, 'name' => 'Annie', 'active' => 1), 1 => array('id' => 2, 'name' => 'Zilean', 'active' => 1), 3 => array('id' => 4, 'name' => 'Katarina', 'active' => 1));
        $this->assertEqual($expected, $result);
        $result = $collection->first(array('active' => 1))->data();
        $expected = array('id' => 1, 'name' => 'Annie', 'active' => 1);
        $this->assertEqual($expected, $result);
        $result = $collection->first(array('name' => 'Nunu'))->data();
        $expected = array('id' => 5, 'name' => 'Nunu', 'active' => 0);
        $this->assertEqual($expected, $result);
    }