lithium\tests\integration\data\FieldsTest::testSingleField PHP Method

testSingleField() public method

public testSingleField ( )
    public function testSingleField()
    {
        $new = Galleries::create(array('name' => 'People'));
        $key = Galleries::meta('key');
        $new->save();
        $id = is_object($new->{$key}) ? (string) $new->{$key} : $new->{$key};
        $entity = Galleries::first($id);
        $this->assertInstanceOf('lithium\\data\\Entity', $entity);
        $expected = array($key => $id, 'name' => 'People', 'active' => true);
        $result = $entity->data();
        $this->assertEqual($expected, array_filter($result));
        $entity = Galleries::first(array('conditions' => array($key => $id), 'fields' => array($key)));
        $this->assertInstanceOf('lithium\\data\\Entity', $entity);
        $expected = array($key => $id);
        $result = $entity->data();
        $this->assertEqual($expected, $result);
        $entity = Galleries::find('first', array('conditions' => array($key => $id), 'fields' => array($key, 'name')));
        $this->assertInstanceOf('lithium\\data\\Entity', $entity);
        $entity->name = 'Celebrities';
        $result = $entity->save();
        $this->assertTrue($result);
        $entity = Galleries::find('first', array('conditions' => array($key => $id), 'fields' => array($key, 'name')));
        $this->assertEqual($entity->name, 'Celebrities');
        $new->delete();
    }