Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_attributecompute.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Pu;
8 /**
9  * @author Anakeen
10  * @package Dcp\Pu
11  */
12 
13 require_once 'PU_testcase_dcp_commonfamily.php';
14 
16 {
17  /**
18  * import TST_DEFAULTFAMILY1 family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return "PU_data_dcp_familycomputed.ods";
25  }
26 
27  protected $famName = 'TST_FAMILYCOMPUTED';
28  /**
29  * @dataProvider dataComputedValues
30  */
31  public function testComputedValue(array $inputs, array $expectedvalues, array $logMatch)
32  {
33  static $d = null;
34  if ($d === null) {
35  $d = createDoc(self::$dbaccess, $this->famName);
36  $this->assertTrue(is_object($d) , sprintf("cannot create %s document", $this->famName));
37  }
38 
39  foreach ($inputs as $k => $v) {
40  $d->setValue($k, $v);
41  }
42 
43  $tmpLogFile = tempnam(getTmpDir() , __FUNCTION__);
44  $d->log = new \Log($tmpLogFile, $d->log->application, $d->log->function);
45 
46  $info = new \storeInfo();
47  $err = $d->store($info);
48 
49  $log = file_get_contents($tmpLogFile);
50  unlink($tmpLogFile);
51 
52  $this->assertEmpty($err, sprintf("cannot modify %s document", $this->famName));
53  foreach ($expectedvalues as $k => $v) {
54  if (is_array($v)) $value = $d->getMultipleRawValues($k);
55  else $value = $d->getRawValue($k);
56  $this->assertEquals($v, $value, sprintf("error computed %s", $k));
57  }
58  $this->assertEmpty($info->refresh, sprintf("refresh returned with unexpected error: %s", $info->refresh));
59  foreach ($logMatch as $re) {
60  $this->assertTrue(preg_match($re, $log) == 1, sprintf("log did not contained expected message '%s'", $re));
61  }
62 
63  return $d;
64  }
65 
66  public function dataComputedValues()
67  {
68 
69  $arg = array(
70  array(
71  "x" => 10,
72  "y1" => 123,
73  "z1" => 230
74  ) ,
75  array(
76  "x" => 80,
77  "y1" => 133,
78  "z1" => 238
79  )
80  );
81  $out = array();
82  foreach ($arg as $a) {
83  $x = $a["x"];
84  $y1 = $a["y1"];
85  $z1 = $a["z1"];
86  $out[] = array(
87  "inputs" => array(
88  'tst_number1' => $x,
89  'tst_number10' => array(
90  $y1,
91  $z1
92  )
93  ) ,
94  'ouputs' => array(
95  'tst_number1' => $x1 = $x,
96  'tst_number2' => $x2 = $x + 1,
97  'tst_number3' => $x3 = $x2 + 1,
98  'tst_number4' => $x4 = 30 + 5 + 15,
99  'tst_number6' => $x6 = 1 + 2 + 3,
100  'tst_number7' => $x7 = $x1 + $x2 + $x3,
101  'tst_number9' => $x9 = $x3 + 10,
102  'tst_text1' => 'NULL',
103  'tst_text2' => 'zero',
104  'tst_text3' => "[the][beautiful][ rainbow ,][.]",
105  'tst_text4' => 'one',
106  "tst_number11" => array(
107  $y2 = $y1 + 10,
108  $z2 = $z1 + 10
109  ) ,
110  "tst_number12" => array(
111  $y1 + $y2,
112  $z1 + $z2
113  ) ,
114  'tst_count' => 2,
115  'tst_vis_i_1' => '',
116  'tst_vis_i_2' => '',
117  'tst_vis_i_3' => ''
118  ) ,
119  'logMatch' => array(
120  '/\[W\].*{ATTR1800} value of attribute "tst_vis_i_1"/',
121  '/\[W\].*{ATTR1800} value of attribute "tst_vis_i_3"/'
122  )
123  );
124  }
125  return $out;
126  }
127 }
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
$d
Definition: dav.php:77
$log
Definition: wsh.php:33
testComputedValue(array $inputs, array $expectedvalues, array $logMatch)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
if($file) if($subject==""&&$file) if($subject=="") $err
$value
← centre documentaire © anakeen