lithium\tests\cases\data\source\DatabaseTest::testCustomField PHP Метод

testCustomField() публичный Метод

public testCustomField ( )
    public function testCustomField()
    {
        $field = "(CASE `title` WHEN 'Lotus Flower' THEN 'Found' ELSE 'Not Found' END) as extra";
        $query = new Query(array('type' => 'read', 'model' => $this->_gallery, 'fields' => array('*', $field)));
        $result = $this->_db->read($query);
        $expected = 'SELECT (CASE `title` WHEN \'Lotus Flower\' THEN \'Found\' ELSE \'Not Found\' ';
        $expected .= 'END) as extra, {Gallery}.* FROM {mock_gallery} AS {Gallery};';
        $this->assertEqual($expected, $this->_db->sql);
        $map = array('' => array('extra', 'id', 'title'));
        $this->assertEqual($map, $query->map());
        $query = new Query(array('type' => 'read', 'model' => $this->_gallery, 'fields' => array('*', (object) $field)));
        $result = $this->_db->read($query);
        $this->assertEqual($expected, $this->_db->sql);
        $this->assertEqual($map, $query->map());
        $query = new Query(array('type' => 'read', 'model' => $this->_gallery, 'fields' => array('*', array($field))));
        $result = $this->_db->read($query);
        $this->assertEqual($expected, $this->_db->sql);
        $this->assertEqual($map, $query->map());
        $query = new Query(array('type' => 'read', 'model' => $this->_gallery, 'fields' => array((object) 'count(Image.id) as count', 'Image'), 'group' => 'Gallery.id', 'with' => array('Image')));
        $result = $this->_db->read($query);
        $expected = 'SELECT count(Image.id) as count, {Gallery}.{id}, {Image}.* FROM ';
        $expected .= '{mock_gallery} AS {Gallery} LEFT JOIN {mock_image} AS {Image} ON ';
        $expected .= '{Gallery}.{id} = {Image}.{gallery_id} GROUP BY {Gallery}.{id};';
        $this->assertEqual($expected, $this->_db->sql);
        $map = array('' => array('count', 'id'), 'Image' => array('id', 'title', 'image', 'gallery_id'));
        $this->assertEqual($map, $query->map());
    }
DatabaseTest