13 require_once
'PU_testcase_dcp_commonfamily.php';
25 "PU_data_dcp_formatcollection.ods",
26 "PU_data_dcp_documentsformat1.xml",
27 "PU_data_dcp_documentsformat2.xml",
28 "PU_data_dcp_documentsformat3.xml",
29 "PU_data_dcp_documentsformat4.xml",
30 "PU_data_dcp_documentsformat5.xml",
31 "PU_data_dcp_formatcollectionprofil.ods",
37 parent::setUpBeforeClass();
67 $s->setObjectReturn();
68 $dl =
$s->search()->getDocumentList();
69 $fc = new \FormatCollection();
70 $fc->useCollection($dl);
71 $fc->relationNoAccessText =
'no grant';
72 $fc->addProperty($fc::propName)->addProperty($fc::propUrl);
75 $la = $f->getNormalAttributes();
76 foreach (
$la as $aid => $oa) {
77 if ($oa->type !=
"array")
$fc->addAttribute($aid);
82 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
85 $fValue = $this->getRenderValue(
$r, $docName, $attrName);
86 if (is_array($expectRender)) {
87 foreach ($expectRender as $expAttr => $expVal) {
88 if (is_array($expVal)) {
90 $this->assertTrue(is_array($fValue) , sprintf(
"result %s not an array for %s", print_r($fValue,
true) , $expAttr));
91 foreach ($fValue as $k => $v) {
93 $testValue[$k] = array();
95 $testValue[$k][] = $vv->$expAttr;
98 $testValue[$k] = $v->$expAttr;
102 $testValue = ($fValue === null) ? null : $fValue->$expAttr;
104 $this->assertEquals($expVal, $testValue, sprintf(
"values is : %s %s ", print_r($testValue,
true) , json_encode($fValue)));
107 $this->assertEquals($expectRender, $fValue, sprintf(
"values is : %s", sprintf(json_encode($fValue))));
109 foreach ($expectContainRender as $expAttr => $expVal) {
110 $this->assertTrue(preg_match(
"/$expVal/", $fValue->$expAttr) > 0, sprintf(
"not match for $expVal. values is : %s", json_encode($fValue)));
116 public function testUnknowRenderFormatCollection($docName, $attrName, $nc)
119 $s->setObjectReturn();
120 $dl =
$s->search()->getDocumentList();
121 $fc = new \FormatCollection();
122 $fc->useCollection($dl);
123 $fc->addProperty($fc::propName);
124 $fc->addAttribute((
'tst_x'));
128 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
132 $fValue = $this->getRenderValue(
$r, $docName, $attrName);
133 $this->assertEquals($nc, $fValue->value);
138 public function testStateRenderFormatCollection($docName, $expectState, $expectColor, $expectActivity, $expectDisplayValue)
141 $s->setObjectReturn();
142 $dl =
$s->search()->getDocumentList();
143 $fc = new \FormatCollection();
144 $fc->useCollection($dl);
145 $fc->addProperty($fc::propName)->addProperty($fc::propState);
148 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
152 $fstate = $this->getRenderProp(
$r, $docName, $fc::propState);
153 $this->assertEquals($expectState, $fstate->reference,
"incorrect state reference");
154 $this->assertEquals($expectColor, $fstate->color,
"incorrect state color ");
155 $this->assertEquals($expectActivity, $fstate->activity,
"incorrect state activity");
156 $this->assertEquals($expectDisplayValue, $fstate->displayValue, sprintf(
"incorrect state display value : %s", print_r($fstate,
true)));
164 $s->setObjectReturn();
165 $dl =
$s->search()->getDocumentList();
166 $fc = new \FormatCollection();
167 $fc->useCollection($dl);
168 $fc->addProperty($fc::propName)->addProperty($propertyName);
169 $fc->setDateStyle($format);
172 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
174 $propertyValue = $this->getRenderProp(
$r, $docName, $propertyName);
175 $this->assertRegExp($expectedFormat, $propertyValue, sprintf(
"incorrect property (%s) display value : %s", $propertyName, print_r($propertyValue,
true)));
183 $s->setObjectReturn();
184 $dl =
$s->search()->getDocumentList();
185 $fc = new \FormatCollection();
187 $fc->useCollection($dl);
188 $fc->addProperty($fc::propName)->addProperty($propertyName);
191 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
193 $propertyValue = $this->getRenderProp(
$r, $docName, $propertyName);
194 if (is_array($expectedValue)) {
195 foreach ($expectedValue as $infoKey => $expectInfo) {
197 if ($expectInfo[0] ===
"/") {
198 $this->assertRegExp($expectInfo, (
string)$propertyValue[$infoKey], sprintf(
"incorrect property (%s) display value : %s", $propertyName, print_r($propertyValue,
true)));
200 $this->assertEquals($expectInfo, $propertyValue[$infoKey], sprintf(
"incorrect property (%s) display value : %s", $propertyName, print_r($propertyValue,
true)));
203 } elseif ($expectedValue[0] ===
"/") {
204 $this->assertRegExp($expectedValue, $propertyValue, sprintf(
"incorrect property (%s) display value : %s", $propertyName, print_r($propertyValue,
true)));
206 $this->assertEquals($expectedValue, $propertyValue, sprintf(
"incorrect property (%s) display value : %s", $propertyName, print_r($propertyValue,
true)));
216 $s->setObjectReturn();
217 $dl =
$s->search()->getDocumentList();
218 $fc = new \FormatCollection();
219 $fc->useCollection($dl);
220 $fc->setAttributeRenderHook($hook);
221 $fc->relationNoAccessText =
'no grant';
222 $fc->addProperty($fc::propName)->addProperty($fc::propUrl);
225 $la = $f->getNormalAttributes();
226 foreach (
$la as $aid => $oa) {
227 if ($oa->type !=
"array")
$fc->addAttribute($aid);
232 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
235 $fValue = $this->getRenderValue(
$r, $docName, $attrName);
236 if (is_array($expectRender)) {
237 foreach ($expectRender as $expAttr => $expVal) {
238 if (is_array($expVal)) {
239 $testValue = array();
240 $this->assertTrue(is_array($fValue) , sprintf(
"result %s not an array for %s", print_r($fValue,
true) , $expAttr));
241 foreach ($fValue as $k => $v) {
243 $testValue[$k] = array();
244 foreach ($v as $vv) {
245 $testValue[$k][] = $vv->$expAttr;
248 $testValue[$k] = $v->$expAttr;
252 $testValue = ($fValue === null) ? null : $fValue->$expAttr;
254 $this->assertEquals($expVal, $testValue, sprintf(
"values is : %s %s ", print_r($testValue,
true) , json_encode($fValue)));
257 $this->assertEquals($expectRender, $fValue, sprintf(
"values is : %s", sprintf(json_encode($fValue))));
266 $s->setObjectReturn();
267 $dl =
$s->search()->getDocumentList();
269 $fc = new \FormatCollection();
270 $fc->useCollection($dl);
271 $fc->setPropertyRenderHook($hook);
272 $fc->addProperty($fc::propName)->addProperty($propertyName);
275 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
277 $propertyValue = $this->getRenderProp(
$r, $docName, $propertyName);
278 $this->assertEquals($expectedValue, $propertyValue, sprintf(
"incorrect property (%s) value : %s", $propertyName, print_r($propertyValue,
true)));
286 $s->setObjectReturn();
287 $dl =
$s->search()->getDocumentList();
289 $fc = new \FormatCollection();
290 $fc->useCollection($dl);
291 $fc->setDocumentRenderHook($hook);
292 $fc->addProperty($fc::propName)->addProperty(
"revision");
295 $this->assertEquals(
$s->count() , count(
$r) ,
"render must have same entry count has collection");
297 foreach ($expectedProps as $propKey => $propValue) {
298 $propertyValue = $this->getRenderProp(
$r, $docName, $propKey);
299 $this->assertEquals($propValue, $propertyValue, sprintf(
"incorrect property (%s) value : %s", $propKey, print_r($propertyValue,
true)));
302 private function getRenderValue(array
$r, $docName, $attrName)
304 foreach ($r as $format) {
305 if ($format[
"properties"][
"name"] == $docName) {
306 return $format[
"attributes"][$attrName];
312 private function getRenderProp(array $r, $docName, $attrName)
314 foreach ($r as $format) {
315 if ($format[
"properties"][
"name"] == $docName) {
316 return $format[
"properties"][$attrName];
337 '/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/'
342 '/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/'
346 \formatCollection::propFamily,
348 "name" => $this->famName,
349 "title" =>
"Test Format",
350 "id" =>
'/^[0-9]+$/',
351 "icon" =>
"/resizeimg.php/"
356 \formatCollection::propRevisionData,
358 "id" =>
'/^[0-9]+$/',
364 \formatCollection::propSecurity,
371 \formatCollection::propType,
376 \formatCollection::propUsage,
381 \formatCollection::propNote,
388 \formatCollection::propViewController,
395 \formatCollection::propAffected,
402 \formatCollection::propWorkflow,
404 "title" =>
"Cycle format",
405 "id" =>
'/^[0-9]+$/',
406 "icon" =>
"/resizeimg.php/"
411 \formatCollection::propCreationDate,
412 '/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/'
416 \formatCollection::propLastModificationDate,
417 '/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/'
421 \formatCollection::propLastAccessDate,
422 '/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/'
426 public function dataDocumentHookRenderFormatCollection()
436 $info[
"properties"][
"revision"].=
' (bis)';
437 $info[
"properties"][
"hello"] =
'world - ' .
$doc->name;
442 "revision" =>
'0 (bis)',
443 "hello" =>
"world - TST_FMTCOL1"
454 function (
$info, $propId)
456 if ($propId ===
"revision") {
467 function (
$info, $propId)
469 if ($propId ===
"doctype") {
508 if (!is_array(
$info)) {
509 $info->value.=
" (bis)";
510 $info->displayValue.=
" (ter)";
517 "value" =>
"Test 1 (bis)",
518 "displayValue" =>
"Test 1 (ter)"
524 function (
$info, $oa)
528 if ($oa->id ===
"tst_doubles") {
529 foreach (
$info as & $oneInfo) {
530 $oneInfo->value+= 10;
543 "displayValue" => array(
559 '/^(\d\d)\/(\d\d)\/(\d\d\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
565 '/^(\d\d\d\d)-(\d\d)-(\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
571 '/^(\d\d\d\d)-(\d\d)-(\d\d)T?(\d\d)?:?(\d\d)?:?(\d\d)?/'
577 '/^(\d\d)\/(\d\d)\/(\d\d\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
583 '/^(\d\d\d\d)-(\d\d)-(\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
589 '/^(\d\d\d\d)-(\d\d)-(\d\d)T?(\d\d)?:?(\d\d)?:?(\d\d)?/'
595 '/^(\d\d)\/(\d\d)\/(\d\d\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
601 '/^(\d\d\d\d)-(\d\d)-(\d\d)\s?(\d\d)?:?(\d\d)?:?(\d\d)?/'
607 '/^(\d\d\d\d)-(\d\d)-(\d\d)T?(\d\d)?:?(\d\d)?:?(\d\d)?/'
650 "displayValue" =>
"Test 1"
658 "displayValue" =>
"Un"
665 "value" =>
"23.4567",
666 "displayValue" =>
"23,46"
683 "displayValue" =>
"Test 1",
684 "familyRelation" =>
"TST_FMTCOL"
687 "value" =>
"^[0-9]+$",
696 "displayValue" =>
"Test 3",
697 "familyRelation" =>
"TST_FMTCOL"
700 "value" =>
"^[0-9]+$",
709 "displayValue" =>
"Test 2"
716 "value" =>
"#52D7FF",
717 "displayValue" =>
"#52D7FF"
725 "displayValue" =>
"Deux"
732 "value" =>
"12:20:00"
739 "value" =>
"Cassoulet",
740 "displayValue" =>
"before Cassoulet"
748 "displayValue" =>
"101"
756 "displayValue" =>
"0"
764 "displayValue" =>
"0,00"
771 "value" =>
"2012-06-13 11:27:00"
778 "value" =>
"2012-06-13"
790 "displayValue" => array(
806 "displayValue" => array(
822 "displayValue" => array(
833 "displayValue" => array(
851 "displayValue" => array(
872 "mime" =>
"text/plain",
873 "fileName" =>
"Test.txt"
889 "displayValue" => array(
906 "displayValue" =>
"Test 1"
914 "displayValue" =>
"Test 1",
915 "familyRelation" =>
"TST_FMTCOL"
918 "value" =>
"^[0-9]+$",
928 "displayValue" =>
"Test 3",
929 "familyRelation" =>
"TST_FMTCOL"
932 "value" =>
"^[0-9]+$",
942 "displayValue" =>
"no grant",
943 "familyRelation" =>
"TST_FMTCOL"
946 "value" =>
"^[0-9]+$",
956 "displayValue" => array(
975 "displayValue" => array(
998 "displayValue" => array(
requiresCoreParamEquals($paramName, $requiredValue, $markTestIncomplete=true)