lithium\tests\cases\data\model\QueryTest::testWithAssociation PHP Method

testWithAssociation() public method

public testWithAssociation ( )
    public function testWithAssociation()
    {
        $model = $this->_model;
        $model::meta('source', 'foo');
        $model::bind('hasMany', 'MockQueryComment');
        $query = new Query(array('type' => 'read', 'model' => $model, 'with' => 'MockQueryComment'));
        $export = $query->export(new MockDatabase());
        $expected = array('MockQueryComment' => array('type' => 'hasMany', 'model' => 'lithium\\tests\\mocks\\data\\model\\MockQueryComment', 'fieldName' => 'mock_query_comments', 'alias' => 'MockQueryComment'));
        $this->assertArrayHasKey('relationships', $export);
        $this->skipIf(!isset($export['relationships']));
        $this->assertEqual($expected, $export['relationships']);
        $query = new Query(compact('model') + array('type' => 'read', 'with' => 'MockQueryComment', 'limit' => 3, 'order' => array('author_id', 'id'), 'group' => 'author_id'));
        $expected = 'SELECT * FROM {foo} AS {MockQueryPost} LEFT JOIN {mock_query_comments} AS ';
        $expected .= '{MockQueryComment} ON {MockQueryPost}.{id} = {MockQueryComment}';
        $expected .= '.{mock_query_post_id} GROUP BY {MockQueryPost}.{author_id} ORDER BY ';
        $expected .= '{MockQueryPost}.{author_id} ASC, {MockQueryPost}.{id} ASC LIMIT 3;';
        $this->assertEqual($expected, $this->_db->renderCommand($query));
    }