コード例 #1
0
$t = new lime_test(11, new lime_output_color());
$c = new xfCriteria();
$c->add(new xfCriterionTerm('foobar'));
$c->add(new xfCriterionTerm('baz'));
$t->is(count($c->getCriterions()), 2, '->add() adds criterions to the boolean query');
$t->is($c->toString(), 'BOOLEAN {[foobar] AND [baz]}', '->toString() returns a string representation');
$t->is($c->getLast()->getTerm(), 'baz', '->getLast() returns the last criterion');
$c->replaceLast(new xfCriterionTerm('foo'));
$t->is($c->getLast()->getTerm(), 'foo', '->replaceLast() changes the last criterion');
$trans = new xfCriterionTranslatorString();
$c->translate($trans);
$t->is($trans->getString(), '{{ foobar foo }}', '->translate() translates the query');
$c = new xfCriteria();
try {
    $msg = '->getLast() fails if there is no last criterion.';
    $c->getLast();
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
try {
    $msg = '->replaceLast() fails if there is no last criterion';
    $c->replaceLast(new xfCriteria());
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$c = new xfCriteria();
$t->is($c->optimize()->toString(), 'EMPTY', '->optimize() eliminates empty subqueries');
$c->add(new xfCriterionTerm('foo'));
$t->is($c->optimize()->toString(), 'foo', '->optimize() reduces itself to just the subquery if only one subquery');