9 require_once
'PU_testcase_dcp_commonfamily.php';
17 'PU_data_dcp_TestSearchGetOriginalQuery.ods'
33 $s->addFilter($criteria,
$arg);
34 $s->setObjectReturn(
true);
38 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
82 foreach ($fruits as $socTitle) {
83 foreach ($socTitle as $k =>
$title) {
89 $this->assertEmpty(
$err,
"Cannot create data");
92 if (
$title ===
"__delete__") {
95 $this->assertEmpty(
$err,
"Cannot delete data");
100 $this->assertEmpty(
$err,
"Cannot update data");
121 if ($criteria)
$s->addFilter($criteria,
$arg);
122 $s->setObjectReturn(
true);
125 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
127 $this->assertEquals($count,
$s->count() , sprintf(
"Count must be %d (found %d) error %s %s", $count,
$s->count() , $criteria,
$arg));
144 if ($criteria)
$s->addFilter($criteria,
$arg);
145 $s->setObjectReturn(
true);
147 $s->distinct = $distinct;
151 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
153 $returnTitles = $this->getReturnTitles(
$s);
156 $this->assertEquals(count($expectTitles) ,
$s->count() , sprintf(
"Count error %s %s \nFound: %s %s", $criteria,
$arg, implode(
",", $returnTitles) , print_r(
$s->getSearchInfo() ,
true)));
157 $this->assertEquals($expectTitles, $returnTitles, sprintf(
"Not expected result %s %s \nFound : %s %s", $criteria,
$arg, implode(
", ", $returnTitles) , print_r(
$s->getSearchInfo() ,
true)));
164 foreach ($dl as
$doc) {
166 $titles[] = $doc->getTitle();
189 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
191 $this->assertEquals($count, $s->
count() , sprintf(
"Count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
217 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
219 $this->assertEquals($count, $s->
count() , sprintf(
"Count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
220 $this->assertEquals($count,
$c, sprintf(
"Return count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
245 $this->assertContains($error,
$err, sprintf(
"No good error %s", print_r($s->
getSearchInfo() ,
true)));
247 $this->assertEquals($count, $s->
count() , sprintf(
"Count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
248 $this->assertEquals($count,
$c, sprintf(
"Return count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
266 $exceptionError =
'';
271 $exceptionError = $e->getMessage();
274 $this->assertContains($error, $exceptionError, sprintf(
"Exception error '%s' does not contains '%s' (%s)", $exceptionError, $getError, print_r($s->
getSearchInfo() ,
true)));
275 $this->assertContains($error, $getError, sprintf(
"getError() '%s' does not contains '%s' (%s)", $getError, $getError, print_r($s->
getSearchInfo() ,
true)));
277 $this->assertEquals($count, $s->
count() , sprintf(
"count() must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
289 if (isset(
$data[
'import'])) {
293 $this->assertTrue(isset(
$data[
'tests']) , sprintf(
"Missing 'tests'."));
296 if (isset(
$test[
'sudo'])) {
301 $this->assertTrue($fam->isAlive() , sprintf(
"test#%s> Family '%s' not found.", $i,
$test[
'search:family']));
304 $s->setObjectReturn();
306 if (isset(
$test[
'search:noviewcontrol']) &&
$test[
'search:noviewcontrol']) {
307 $s->overrideViewControl();
310 $count = $s->onlyCount();
314 $this->assertEquals($count,
$test[
'expect:count'], sprintf(
"test#%s> Result size is %s while expecting %s. [%s]", $i, $count,
$test[
'expect:count'], print_r($s->getSearchInfo() ,
true)));
316 if (isset(
$test[
'sudo'])) {
333 if (isset(
$data[
'import'])) {
337 $this->assertTrue(isset(
$data[
'tests']) , sprintf(
"Missing 'tests'."));
340 if (isset(
$test[
'sudo'])) {
345 $this->assertTrue($fam->isAlive() , sprintf(
"test#%s> Family '%s' not found.", $i,
$test[
'search:family']));
348 $s->setObjectReturn();
349 if (isset(
$test[
'search:noviewcontrol']) &&
$data[
'search:noviewcontrol']) {
350 $s->overrideViewControl();
352 if (isset(
$test[
'search:filters']) && is_array(
$test[
'search:filters'])) {
354 $s->addFilter($filter);
357 $count = $s->onlyCount();
358 $this->assertEquals($count,
$test[
'expect:count'], sprintf(
"test#%s> Result size is %s while expecting %s. [%s]", $i, $count,
$test[
'expect:count'], print_r($s->getSearchInfo() ,
true)));
360 if (isset(
$test[
'sudo'])) {
384 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
385 $this->assertLessThanOrEqual(2,
$c);
412 $cstart = $s->
count();
414 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
415 $this->assertLessThanOrEqual($call, $cstart);
427 if (isset(
$data[
'collection'])) {
436 $err = $e->getMessage();
438 $this->assertFalse(
$err ==
"", sprintf(
"Need detect Search error %s %s",
$data[
'criteria'],
$data[
'arg']));
439 foreach (
$data[
'expectErrors'] as $error) {
440 $this->assertContains($error,
$err, sprintf(
"no good error code"));
463 $this->assertEmpty(
$err, sprintf(
"Search error %s %s", $criteria,
$arg));
465 $this->assertEquals($count, $s->
count() , sprintf(
"Count must be %d (found %d) error %s %s", $count, $s->
count() , $criteria,
$arg));
466 $this->assertEquals($count, count($t) , sprintf(
"Count must be %d (found %d) search mode error %s %s", $count, count($t) , $criteria,
$arg));
475 $fam = empty(
$test[
'search:family']) ?
'' :
$test[
'search:family'];
477 if (isset(
$test[
'search:filter'])) {
478 if (!is_array(
$test[
'search:filter'])) {
479 $test[
'search:filter'] = array(
480 $test[
'search:filter']
487 if (isset(
$test[
'search:collection'])) {
493 $this->assertNotEmpty(
$sql, sprintf(
"Unexpected empty original query!"));
497 $this->assertEmpty(
$err, sprintf(
"Unexpected SearchDoc error [%s]: %s",
$sql,
$err));
501 $expected[] = $doc->name;
505 $this->assertEmpty(
$err, sprintf(
"Unexpected error in simpleQuery() [%s]: %s",
$sql,
$err));
506 foreach ($res as & $row) {
510 $missing = array_diff($expected, $res);
511 $spurious = array_diff($res, $expected);
512 $this->assertEmpty($missing, sprintf(
"Unexpected missing elements [%s]: {%s}",
$sql, join(
', ', $missing)));
513 $this->assertEmpty($spurious, sprintf(
"Unexpected spurious elements [%s]: {%s}",
$sql, join(
', ', $spurious)));
523 $dl = $s->
search()->getDocumentList();
525 foreach ($dl as $doc) {
526 if ($doc->name === $docName) {
527 foreach ($expectedAttr as $attrid =>
$value) {
528 $this->assertEquals(
$value, $doc->getRawValue($attrid) , sprintf(
"attribute \"%s\"", $attrid));
539 "TST_GETORIGINALQUERY2_3",
547 "TST_GETORIGINALQUERY2_2",
554 "TST_GETORIGINALQUERY2",
555 "TST_GETORIGINALQUERY2_2",
563 "TST_GETORIGINALQUERY2_2",
571 "TST_GETORIGINALQUERY2_1",
574 "s_text" =>
"Two£Four"
601 'criteria' =>
"us_login ~* '%s'",
603 'family' =>
"IUSER2",
604 'expectErrors' => array(
612 'criteria' =>
"us_mail y '%s'",
615 'expectErrors' => array(
623 'criteria' =>
"us_mail ~ '%s');update users set id=0 where id = -6;--",
626 'expectErrors' => array()
632 'criteria' =>
"us_login ~* '%s'",
635 'collection' =>
'TST_GETORIGINALQUERY_SEARCH_SSEARCH_1',
636 'expectErrors' => array(
661 "Poire|Pomme|Cerise|Banane",
723 "Poire|Pomme|Cerise|Banane|Prune|Corme",
752 "Poire|Pomme|Cerise|Banane|Prune|Corme",
767 "Poire|Pomme|Cerise|Banane|Prune|Corme",
779 "Poire|Pomme|Cerise|Orange|Prune|Corme",
793 "Poire|Pomme|Cerise|Orange|Prune|Corme",
813 "Pomme|Cerise|Orange|Prune|Corme|Kiwi",
829 "Pomme|Cerise|Orange|Prune|Corme|Kiwi",
848 "Poire|Pomme|Cerise|Banane",
858 "title_unknow ~* '%s'",
876 "import" =>
"PU_data_dcp_search_noviewcontrol.ods",
879 "search:family" =>
"TST_SEARCH_NOVIEWCONTROL",
883 "sudo" =>
"anonymous",
884 "search:family" =>
"TST_SEARCH_NOVIEWCONTROL",
888 "import" =>
"PU_data_dcp_search.ods",
889 "sudo" =>
"anonymous",
890 "search:family" =>
"TST_SEARCH_NOVIEWCONTROL",
891 "search:noviewcontrol" =>
true,
904 "import" =>
"PU_data_dcp_search_filters.ods",
907 "search:family" =>
"TST_SEARCH_FILTERS",
908 "search:filters" => array(
909 "a_text ~* '^TST_SEARCH_FILTERS_'",
910 "extract(year from a_timestamp) = '1970'"
915 "search:family" =>
"TST_SEARCH_FILTERS",
916 "search:filters" => array(
917 "extract(year from a_timestamp) = '1970'",
918 "a_text IN (select * from (values ('TST_SEARCH_FILTERS_01')) as foo(name))"
932 'search:family' =>
'',
933 'search:filter' =>
"s_title ~ '^T'",
934 'search:collection' =>
'TST_GETORIGINALQUERY_SEARCH_3'
939 'search:family' =>
'',
940 'search:filter' =>
"s_title ~ '^T'",
941 'search:collection' =>
'TST_GETORIGINALQUERY_SEARCH_4'
946 'search:family' =>
'',
947 'search:filter' =>
"s_title ~ '^T'",
948 'search:collection' =>
'TST_GETORIGINALQUERY_SEARCH_5'
testOnlyCountErrorSearch($criteria, $arg, $family, $error)
onlyCountWithNoViewControlCriteria()
testArrayCountSearch($criteria, $arg, $family, $count)
static importDocument($file)
testCountAndResetSearch($criteria, $arg, $family, $count)
testOnlyCountSearch($criteria, $arg, $family, $count)
onlyCountFilterCriteria()
countAllRevisionCriteria()
testOnlyCountWithNoViewControlSearch($data)
setObjectReturn($returnobject=true)
testGetOriginalQuery($test)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
testSliceSearch($criteria, $arg, $family)
static getCommonImportFile()
testSearchGetValue($famName, $docName, $expectedAttr)
testBasicSearch($criteria, $arg, $family)
testOnlyCountErrorSearchException($criteria, $arg, $family, $error)
addFilter($filter, $args= '')
testCountRevisionSearch($latest, $distinct, $trash, $criteria, $arg, $family, array $expectTitles)
testOnlyCountFilterSearch($data)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
testStartSearch($criteria, $arg, $family, $count)
testCountSearch($criteria, $arg, $family, $count)
if($file) if($subject==""&&$file) if($subject=="") $err
countErrorCriteriaException()
requiresCoreParamEquals($paramName, $requiredValue, $markTestIncomplete=true)