9 require_once
'PU_testcase_dcp_action.php';
10 include_once
'WHAT/Lib.Http.php';
11 include_once
'FDL/autocompletion.php';
21 parent::setUpBeforeClass();
23 self::addExternals(
"PU_data_dcp_autocompletion.php");
26 self::beginTransaction();
27 self::importDocument(
"PU_data_dcp_autocompletion_family.ods");
32 self::rollbackTransaction();
34 self::rollbackExternals();
36 parent::tearDownAfterClass();
41 $source =
'..' . DIRECTORY_SEPARATOR .
'DCPTEST' . DIRECTORY_SEPARATOR .
$file;
42 $destination =
'EXTERNALS' . DIRECTORY_SEPARATOR . basename(
$file);
44 if (file_exists($destination)) {
45 throw new \Exception(sprintf(
"External destination file '%s' already exists.", $destination));
48 $ret = symlink($source, $destination);
50 self::rollbackExternals();
51 throw new \Exception(sprintf(
"Could not symlink '%s' into '%s'.", $source, $destination));
54 self::$externalsList[] = $destination;
59 foreach (self::$externalsList as
$file) {
84 if (isset(
$data[
'document'])) {
86 $this->assertTrue(is_object(
$doc) , sprintf(
"Error retrieving document '%s'.",
$data[
'document']));
89 $this->assertTrue(is_object(
$doc) , sprintf(
"Could not create new document from family '%s'.",
$data[
'fam']));
91 $this->assertEmpty(
$err, sprintf(
"Could not add new document to database: %s",
$err));
94 $oattr =
$doc->getAttribute(
$data[
'attr']);
95 $this->assertTrue(is_object($oattr) , sprintf(
"Could not get attribute '%s' on document '%s' (id=%s).",
$data[
'attr'],
$doc->name,
$doc->id));
97 if (isset(
$data[
'http:vars'])) {
105 if (isset(
$data[
'action:args'])) {
106 foreach (
$data[
'action:args'] as $name =>
$value) {
111 $out = $this->testAction->execute();
113 $dom = new \DOMDocument();
115 $this->assertTrue(
$ret, sprintf(
"response does not seems to be valid XML: [%s…]", substr(
$out, 0, 30)));
117 $xp = new \DOMXpath($dom);
118 $res = $xp->query(
'/status');
119 $this->assertTrue((is_object($res) && ($res->length > 0)) , sprintf(
"response does not contains a status node."));
121 $statusNode = $res->item(0);
123 if (isset(
$data[
'expected:warning'])) {
124 $warning = $statusNode->getAttribute(
'warning');
125 $this->assertTrue(($warning ==
$data[
'expected:warning']) , sprintf(
"response contains non expected warning: found '%s' while expecting '%s'", $warning,
$data[
'expected:warning']));
129 $this->assertTrue(is_array($cibles) , sprintf(
"Error getting <cible> nodes: %s", $this->errmsg));
132 $this->assertTrue(is_array($options) , sprintf(
"Error getting <option> nodes: %s", $this->errmsg));
134 if (isset(
$data[
'expected:results'])) {
137 $this->assertEmpty(
$err, sprintf(
"Expected results not met: %s",
$err));
140 if (isset(
$data[
'expected:cibles'])) {
142 $this->assertEmpty(
$err, sprintf(
"Expected cibles not met: %s",
$err));
149 $cibleNodeList = $xp->query(
'cibles/cible', $statusNode);
150 if ($cibleNodeList ===
false) {
151 $this->errmsg = sprintf(
"XPath query error: 'cibles/cible'");
154 foreach ($cibleNodeList as $cibleNode) {
155 $cibles[] = $cibleNode->textContent;
163 $optionNodeList = $xp->query(
'option', $statusNode);
164 if ($optionNodeList ===
false) {
165 $this->errmsg = sprintf(
"XPath query error: 'option'");
168 foreach ($optionNodeList as $i => $optionNode) {
169 $options[$i] = array();
170 $titleNodeList = $xp->query(
'title', $optionNode);
171 $options[$i][
'title'] = $titleNodeList->item(0)->textContent;
172 $options[$i][
'value'] = $optionNode->getAttribute(
'value');
173 $options[$i][
'values'] = array();
175 $valNodeList = $xp->query(
'values/val', $optionNode);
176 foreach ($valNodeList as $valNode) {
177 if ($valNode->nodeName !=
'val') {
180 $options[$i][
'values'][] = $valNode->textContent;
189 foreach ($options as $i => & $option) {
193 foreach ($option[
'values'] as &
$value) {
204 $expectedCount = count($expectedResult);
205 $actualCount = count($actualResult);
206 if ($actualCount != $expectedCount) {
207 return sprintf(
"Result count mismatch: found '%s' while expecting '%s'", $actualCount, $expectedCount);
210 for ($line = 0; $line < $expectedCount; $line++) {
211 $expectedLine = $expectedResult[$line];
212 $actualLine = $actualResult[$line];
213 $expectedLineCount = count($expectedLine);
214 $actualLineCount = count($actualLine);
215 if ($actualLineCount != $expectedLineCount) {
216 return sprintf(
"Line #%s count mismatch: found '%s' while expecting '%s'", $line, $actualLineCount, $expectedLineCount);
219 for ($col = 0; $col < $expectedLineCount; $col++) {
220 $actualCell = $actualLine[$col];
221 $expectedCell = $expectedLine[$col];
222 if ($actualCell != $expectedCell) {
223 return sprintf(
"Data mismatch at Line #%s, Column #%s: found '%s' while expecting '%s'", $line, $col, $actualCell, $expectedCell);
232 $expectedCount = count($expectedCibles);
233 $actualCount = count($actualCibles);
234 if ($actualCount != $expectedCount) {
235 return sprintf(
"Cible count mismatch: found '%s' while expecting '%s'", $actualCount, $expectedCount);
238 for ($i = 0; $i < $expectedCount; $i++) {
239 $expected = $expectedCibles[$i];
240 $actual = $actualCibles[$i];
241 if ($actual != $expected) {
242 return sprintf(
"Data mismatch at index #%s: found '%s' while expecting '%s'", $i, $actual, $expected);
252 'fam' =>
'TST_AUTOCOMPLETION',
253 'attr' =>
'S_GRAVITE',
254 'expected:warning' =>
'',
255 'expected:results' => array(
269 'expected:cibles' => array(
276 'fam' =>
'TST_AUTOCOMPLETION',
277 'attr' =>
'S_TITLE_1',
278 'http:vars' => array(
279 '_s_title_1' =>
'Relation'
281 'expected:warning' =>
'',
282 'expected:results' => array(
292 'expected:cibles' => array(
299 'fam' =>
'TST_AUTOCOMPLETION',
300 'attr' =>
'S_TITLE_2',
301 'http:vars' => array(
302 '_s_title_2' =>
'Relation'
304 'expected:warning' =>
'',
305 'expected:results' => array(
315 'expected:cibles' => array(
323 'fam' =>
'TST_AUTOCOMPLETION',
324 'attr' =>
'S_TITLE_2',
325 'http:vars' => array(
326 '_s_title_2' =>
'Quoted'
328 'expected:warning' =>
'',
329 'expected:results' => array(
335 'expected:cibles' => array(
343 'fam' =>
'TST_AUTOCOMPLETION',
344 'attr' =>
'S_TITLE_2',
345 'http:vars' => array(
346 '_s_title_2' =>
'CDATA'
348 'expected:warning' =>
'',
349 'expected:results' => array(
351 'CDATA injection]]></error>',
352 'CDATA injection]]></error>'
355 'expected:cibles' => array(
362 'fam' =>
'TST_AUTOCOMPLETION',
363 'attr' =>
'BUG_2108',
364 'http:vars' => array(
365 '_s_text' =>
'Bug 2108',
366 '_ilink_bug_2108' =>
'Current Title'
368 'expected:warning' =>
'',
369 'expected:results' => array(
371 'Current Title, Bug 2108',
372 'Current Title, Bug 2108'
375 'expected:cibles' => array(
383 'fam' =>
'TST_AUTOCOMPLETION',
384 'attr' =>
'BUG_2108_OK',
385 'http:vars' => array(
386 '_s_text' =>
'Test Bug 2108 OK',
387 '_ilink_bug_2108_ok' =>
'Current Title'
389 'expected:warning' =>
'',
390 'expected:results' => array(
392 'Test Bug 2108 OK, Current Title',
393 'Test Bug 2108 OK, Current Title'
396 'expected_cibles' => array(
404 'fam' =>
'TST_AUTOCOMPLETION',
405 'document' =>
'TST_AUTOCOMPLETION_2',
406 'attr' =>
'RELATION_2',
407 'http:vars' => array(
408 '_s_text' =>
'Test Relation 2',
409 '_ilink_relation_1' =>
'Document test',
410 '_ilink_relation_2' =>
'Current Title'
412 'expected:warning' =>
'',
413 'expected:results' => array(
415 'Current Title, Document test, Test Relation 2',
416 'Current Title, Document test, Test Relation 2'
419 'expected:cibles' => array(
428 'fam' =>
'TST_AUTOCOMPLETION',
429 'document' =>
'TST_AUTOCOMPLETION_3',
430 'attr' =>
'RELATION_3',
431 'http:vars' => array(
432 '_s_text' =>
'Test Relation 3',
433 '_ilink_relation_1' =>
'Document test',
434 '_ilink_relation_3' =>
'Current Title'
436 'expected:warning' =>
'',
437 'expected:results' => array(
439 'Test Relation 3, Current Title, Document test',
440 'Test Relation 3, Current Title, Document test'
443 'expected:cibles' => array(
453 'fam' =>
'TST_AUTOCOMPLETION',
454 'attr' =>
'BUG_5151_FAM',
455 'http:vars' => array(
456 '_bug_5151_fam' =>
'Relation'
458 'expected:warning' =>
'',
459 'expected:results' => array(
469 'expected:cibles' => array(
476 'fam' =>
'TST_AUTOCOMPLETION',
477 'attr' =>
'BUG_5151_PARAM',
478 'http:vars' => array() ,
479 'expected:warning' =>
'',
480 'expected:results' => array(
485 'expected:cibles' => array(
493 'fam' =>
'TST_AUTOCOMPLETION',
494 'attr' =>
'DEFAULTPHPFUNC_DOCID',
495 'http:vars' => array(
496 '_ilink_defaultphpfunc_docid' =>
'Test Relation',
497 'defaultphpfunc' =>
'yes'
499 'expected:warning' =>
'',
500 'expected:results' => array(
512 'expected:cibles' => array(
513 'defaultphpfunc_docid',
514 'ilink_defaultphpfunc_docid'
520 'fam' =>
'TST_AUTOCOMPLETION',
521 'attr' =>
'DEFAULTPHPFUNC_ACCOUNT',
522 'http:vars' => array(
523 '_ilink_defaultphpfunc_account' =>
'barfirst',
524 'defaultphpfunc' =>
'yes'
526 'expected:warning' =>
'',
527 'expected:results' => array(
534 'expected:cibles' => array(
535 'defaultphpfunc_account',
536 'ilink_defaultphpfunc_account'
static rollbackExternals()
static tearDownAfterClass()
setUpTestAction($appName, $actionName)
static setUpBeforeClass()
setCurrentParameters($param, $value)
checkCibles(&$expectedCibles, &$actualCibles)
getArrayFromOptions(&$options)
testMainAutocompletion($data)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
static addExternals($file)
new_Doc($dbaccess, $id= '', $latest=false)
checkResult(&$expectedResult, &$actualResult)
getAutocompletionOptions(&$xp, &$statusNode)
if($file) if($subject==""&&$file) if($subject=="") $err
getAutocompletionCibles(&$xp, &$statusNode)