Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_attributedate.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  const testFamily = 'TST_DATETRANSFERT';
18  /**
19  * import TST_DATETRANSFERT family
20  * @static
21  * @return string
22  */
23  protected static function getCommonImportFile()
24  {
25  return "PU_data_dcp_datefamily.ods";
26  }
27  /**
28  * @dataProvider dataTransfert
29  */
30  public function testDateTransfert($docid, array $expectedValues)
31  {
32  $origin = new_doc(self::$dbaccess, $docid);
33  $this->assertTrue($origin->isAlive() , "cannot find $docid document");
34 
35  $target = createDoc(self::$dbaccess, self::testFamily);
36  $this->assertTrue(is_object($target) , sprintf("cannot create %s ", self::testFamily));
37 
38  $err = $target->transfertValuesFrom($origin);
39  $this->assertEmpty($err, sprintf("cannot transfert values from %s", self::testFamily));
40  $err = $target->add();
41  $this->assertEmpty($err, sprintf("cannot add %s ", self::testFamily));
42  $newId = $target->id;
43  clearCacheDoc();
44  $target = new_Doc(self::$dbaccess, $newId);
45  $this->verifyValues($target, $expectedValues);
46  }
47  /**
48  * @dataProvider dataTransfert
49  * @depends testDateTransfert
50  *
51  */
52  public function testDateCopy($docid, array $expectedValues)
53  {
54  $origin = new_doc(self::$dbaccess, $docid);
55  $this->assertTrue($origin->isAlive() , "cannot find $docid document");
56  $target = $origin->duplicate();
57  $target->transfertValuesFrom($origin);
58  $this->verifyValues($target, $expectedValues);
59  $this->verifyHtmlValues($origin, $target, array_keys($expectedValues));
60  }
61 
62  private function verifyValues(\Doc $test, array $expectedValues)
63  {
64  foreach ($expectedValues as $k => $expectValue) {
65  if (is_array($expectValue)) $targetValue = $test->getMultipleRawValues($k);
66  else $targetValue = $test->getRawValue($k);
67  $this->assertEquals($expectValue, $targetValue, sprintf("wrong value %s", $k));
68  }
69  }
70 
71  private function verifyHtmlValues(\Doc $origin, \Doc $target, array $attributeIds)
72  {
73  foreach ($attributeIds as $attrid) {
74  $tv = $origin->getHtmlAttrValue($attrid);
75  $to = $target->getHtmlAttrValue($attrid);
76  $this->assertEquals($tv, $to, sprintf("wrong html value %s", $attrid));
77  }
78  }
79 
80  public function dataTransfert()
81  {
82  return array(
83  array(
84  'TST_DATEORIGIN1',
85  array(
86  "tst_date" => '2012-02-29',
87  "tst_ts" => '2012-02-29 12:23:00',
88  'tst_dates' => array(
89  '2012-02-29',
90  '2012-03-13'
91  ) ,
92  'tst_tss' => array(
93  '2012-02-29 00:00',
94  '2012-03-13 13:45:56'
95  )
96  )
97  )
98  );
99  }
100 }
101 ?>
getHtmlAttrValue($attrid, $target="_self", $htmllink=2, $index=-1, $entities=true, $abstract=false)
Definition: Class.Doc.php:6489
testDateCopy($docid, array $expectedValues)
clearCacheDoc($id=0)
$to
$docid
Definition: cleanFamily.php:13
getMultipleRawValues($idAttr, $def="", $index=-1)
Definition: Class.Doc.php:3240
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
testDateTransfert($docid, array $expectedValues)
if($file) if($subject==""&&$file) if($subject=="") $err
$test
Definition: checkVault.php:30
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
← centre documentaire © anakeen