mirror of
https://github.com/cosmocode/dokuwiki-plugin-struct.git
synced 2025-08-01 15:54:34 +00:00

This mostly corrects file and class names for PSR-2. Function names have not been adjusted yet
71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace dokuwiki\plugin\struct\test;
|
|
|
|
use dokuwiki\plugin\struct\meta\QueryBuilder;
|
|
use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
|
|
|
|
/**
|
|
* @group plugin_struct
|
|
* @group plugins
|
|
*/
|
|
class QueryBuilderWhereTest extends StructTest
|
|
{
|
|
|
|
public function test_sql()
|
|
{
|
|
$QB = new QueryBuilder();
|
|
$where = new QueryBuilderWhere($QB);
|
|
|
|
$where->whereAnd('foo = foo');
|
|
$this->assertEquals(
|
|
$this->cleanWS('(foo = foo)'),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
|
|
$where->whereAnd('bar = bar');
|
|
$this->assertEquals(
|
|
$this->cleanWS('(foo = foo AND bar = bar)'),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
|
|
$sub = $where->whereSubAnd();
|
|
$this->assertEquals(
|
|
$this->cleanWS('(foo = foo AND bar = bar)'),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
|
|
$sub->whereAnd('zab = zab');
|
|
$this->assertEquals(
|
|
$this->cleanWS('(foo = foo AND bar = bar AND (zab = zab))'),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
|
|
$sub->whereOr('fab = fab');
|
|
$this->assertEquals(
|
|
$this->cleanWS('(foo = foo AND bar = bar AND (zab = zab OR fab = fab))'),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
}
|
|
|
|
public function test_orsql()
|
|
{
|
|
$QB = new QueryBuilder();
|
|
$where = new QueryBuilderWhere($QB);
|
|
|
|
$where->whereAnd("foo = ''");
|
|
$this->assertEquals(
|
|
$this->cleanWS("(foo = '')"),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
|
|
$sub = $where->whereSubOr();
|
|
$sub->whereAnd('bar = bar');
|
|
$sub->whereAnd('baz = baz');
|
|
$this->assertEquals(
|
|
$this->cleanWS("(foo = '' OR (bar = bar AND baz = baz))"),
|
|
$this->cleanWS($where->toSQL())
|
|
);
|
|
}
|
|
}
|