9 require_once
'PU_testcase_dcp.php';
10 include_once
'WHAT/Lib.Http.php';
11 include_once
'FDL/enum_choice.php';
19 parent::setUpBeforeClass();
21 self::addExternals(
"PU_data_dcp_getResPhpFunc.php");
24 self::beginTransaction();
25 self::importDocument(
"PU_data_dcp_getResPhpFunc_family.ods");
30 self::rollbackTransaction();
32 self::rollbackExternals();
34 parent::tearDownAfterClass();
49 $source =
'..' . DIRECTORY_SEPARATOR .
'DCPTEST' . DIRECTORY_SEPARATOR .
$file;
50 $destination =
'EXTERNALS' . DIRECTORY_SEPARATOR . basename(
$file);
52 if (file_exists($destination)) {
53 throw new \Exception(sprintf(
"External destination file '%s' already exists.", $destination));
56 $ret = symlink($source, $destination);
58 self::rollbackExternals();
59 throw new \Exception(sprintf(
"Could not symlink '%s' into '%s'.", $source, $destination));
62 self::$externalsList[] = $destination;
67 foreach (self::$externalsList as
$file) {
82 if (isset(
$data[
'document'])) {
84 $this->assertTrue(is_object(
$doc) , sprintf(
"Error retrieving document '%s'.",
$data[
'document']));
87 $this->assertTrue(is_object(
$doc) , sprintf(
"Could not create new document from family '%s'.",
$data[
'fam']));
89 $this->assertEmpty(
$err, sprintf(
"Could not add new document to database: %s",
$err));
92 $oattr =
$doc->getAttribute(
$data[
'attr']);
93 $this->assertTrue(is_object($oattr) , sprintf(
"Could not get attribute '%s' on document '%s' (id=%s).",
$data[
'attr'],
$doc->name,
$doc->id));
95 if (isset(
$data[
'http:vars'])) {
105 $this->assertTrue(is_array($res) , sprintf(
"getResPhpFunc did not returned an array."));
107 if (isset(
$data[
'expected:results'])) {
108 $err = $this->checkResult(
$data[
'expected:results'], $res);
109 $this->assertEmpty(
$err, sprintf(
"Expected results not met: %s",
$err));
112 if (isset(
$data[
'expected:rargids'])) {
113 $err = $this->checkRargids(
$data[
'expected:rargids'], $rargids);
114 $this->assertEmpty(
$err, sprintf(
"Expected rargids not met: %s",
$err));
123 $ZONE_ARGS = array();
126 $this->assertTrue(is_object(
$doc) , sprintf(
"Could not create new document from family '%s'.", $family));
128 $this->assertEmpty(
$err, sprintf(
"Could not add new document to database: %s",
$err));
130 $oattr =
$doc->getAttribute($attrid);
131 $this->assertTrue(is_object($oattr) , sprintf(
"Could not get attribute '%s' on document '%s' (id=%s).", $attrid,
$doc->name,
$doc->id));
133 foreach ($inputs as $name =>
$value) {
141 $this->assertTrue(is_string($res) , sprintf(
"getResPhpFunc mist return errors."));
143 foreach ($expectedErrors as $error) {
144 $this->assertContains($error, $res,
"getResPhpFunc not the expected error");
147 private function checkResult(&$expectedResult, &$actualResult)
149 $expectedCount = count($expectedResult);
150 $actualCount = count($actualResult);
151 if ($actualCount != $expectedCount) {
152 return sprintf(
"Result count mismatch: found '%s' while expecting '%s'", $actualCount, $expectedCount);
155 for ($line = 0; $line < $expectedCount; $line++) {
156 $expectedLine = $expectedResult[$line];
157 $actualLine = $actualResult[$line];
158 $expectedLineCount = count($expectedLine);
159 $actualLineCount = count($actualLine);
160 if ($actualLineCount != $expectedLineCount) {
161 return sprintf(
"Line #%s count mismatch: found '%s' while expecting '%s'", $line, $actualLineCount, $expectedLineCount);
164 for ($col = 0; $col < $expectedLineCount; $col++) {
165 $actualCell = $actualLine[$col];
166 $expectedCell = $expectedLine[$col];
167 if ($actualCell != $expectedCell) {
168 return sprintf(
"Data mismatch at Line #%s, Column #%s: found '%s' while expecting '%s'", $line, $col, $actualCell, $expectedCell);
175 private function checkRargids(&$expectedRargsid, &$actualRargids)
177 $expectedCount = count($expectedRargsid);
178 $actualCount = count($actualRargids);
179 if ($actualCount != $expectedCount) {
180 return sprintf(
"Rargids count mismatch: found '%s' while expecting '%s'", $actualCount, $expectedCount);
183 for ($i = 0; $i < $expectedCount; $i++) {
184 $expected = $expectedRargsid[$i];
185 $actual = $actualRargids[$i];
186 if ($actual != $expected) {
187 return sprintf(
"Data mismatch at index #%s: found '%s' while expecting '%s'", $i, $actual, $expected);
198 'fam' =>
'TST_GETRESPHPFUNC',
199 'attr' =>
'S_GRAVITE',
200 'expected:results' => array(
214 'expected:rargids' => array(
221 'fam' =>
'TST_GETRESPHPFUNC',
222 'attr' =>
'S_TITLE_1',
223 'http:vars' => array(
224 '_s_title_1' =>
'Relation'
226 'expected:results' => array(
236 'expected:rargids' => array(
243 'fam' =>
'TST_GETRESPHPFUNC',
244 'attr' =>
'S_TITLE_2',
245 'http:vars' => array(
246 '_s_title_2' =>
'Relation'
248 'expected:results' => array(
258 'expected:rargids' => array(
323 "_s_wrongarray" =>
"test"
getResPhpFunc(Doc &$doc, NormalAttribute &$oattr, &$rargids, &$tselect, &$tval, $whttpvars=true, $index="")
testExecuteGetResPhpFunc($data)
static addExternals($file)
static tearDownAfterClass()
testGetResPhpFuncError($family, $attrid, array $inputs, array $expectedErrors)
static rollbackExternals()
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
static setUpBeforeClass()
if($file) if($subject==""&&$file) if($subject=="") $err