Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_report.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  * Test class for _REPORT.
10  * Generated by PHPUnit on 2011-09-05 at 14:26:32.
11  */
12 
13 require_once 'PU_testcase_dcp_action.php';
14 
16 {
17 
18  public static function setUpBeforeClass()
19  {
20  parent::setUpBeforeClass();
21  self::connectUser();
22  self::beginTransaction();
23  self::importDocument("FamilyAll_element.csv");
24  self::importDocument("documents_rapport.csv");
25  /*import twice : there links between documents*/
26  self::importDocument("documents_rapport.csv");
27  }
28 
29  public function setUp()
30  {
31  // no call parent
32  $this->setUpTestAction("FDL", "REPORT_EXPORT_CSV");
33  }
34 
35  public function tearDown()
36  {
37  $this->resetCurrentParameters();
38  // no call parent
39 
40  }
41 
42  public static function tearDownAfterClass()
43  {
44 
45  TestSuiteDcp::addMessage(sprintf("\nResult data for %s written in file://%s.\n", __CLASS__, self::getOutputDir()));
46  self::rollbackTransaction();
47  }
48  /**
49  * Test report with default option
50  */
51  public function testDefaultReport()
52  {
53  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
54  $this->setCurrentParameters('id', 'RAPPORT_4e6e2c77b36ed');
55  $this->setCurrentParameters('numericRender', 'raw');
56 
57  $csvContent = $this->testAction->execute();
58  $this->saveReport(__METHOD__, $csvContent);
59  $this->assertEquals($this->readExampleFile("default_report.csv") , $csvContent);
60  }
61  /**
62  * Test report with kind pivot, and pivot == all_element_text
63  */
64  public function testPivotCustomPivotReport()
65  {
66  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
67  $this->setCurrentParameters('id', 'RAPPORT_4e6e2c77b36ed');
68  $this->setCurrentParameters('kind', 'pivot');
69  $this->setCurrentParameters('pivot', 'all_element_text');
70  $this->setCurrentParameters('numericRender', 'raw');
71  $csvContent = $this->testAction->execute();
72  $this->saveReport(__METHOD__, $csvContent);
73  $this->assertEquals($this->readExampleFile("pivot_allelement_report.csv") , $csvContent);
74  }
75  /**
76  * Test report with custom CSV export
77  */
78  public function testCustomCSVOption()
79  {
80  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
81  $this->setCurrentParameters('id', 'RAPPORT_4e6e2c77b36ed');
82  $this->setCurrentParameters('delimiter', '"');
83  $this->setCurrentParameters('enclosure', ',');
84  $this->setCurrentParameters('encoding', 'UTF-8');
85  $this->setCurrentParameters('numericRender', 'raw');
86  $csvContent = $this->testAction->execute();
87  $this->saveReport(__METHOD__, $csvContent);
88  $this->assertEquals($this->readExampleFile("customCSV_report.csv") , $csvContent);
89  }
90  /**
91  * Test report with custom date format
92  */
93  public function testCustomDateFormat()
94  {
95  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
96  $this->setCurrentParameters('id', 'RAPPORT_4e6e2c77b36ed');
97  $this->setCurrentParameters('dateFormat', 'ISO');
98  $this->setCurrentParameters('numericRender', 'raw');
99  $csvContent = $this->testAction->execute();
100  $this->saveReport(__METHOD__ . "_ISO", $csvContent);
101  $this->assertEquals($this->readExampleFile("dateISO_report.csv") , $csvContent, "ISO DATE");
102  $this->setCurrentParameters('dateFormat', 'FR');
103  $csvContent = $this->testAction->execute();
104  $this->saveReport(__METHOD__ . "_FR", $csvContent);
105  $this->assertEquals($this->readExampleFile("dateFR_report.csv") , $csvContent, "FR DATE");
106  }
107  /**
108  * Test report with custom date format
109  */
110  public function testDecimalSeparator()
111  {
112  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
113  $this->setCurrentParameters('id', 'RAPPORT_4e6e2c77b36ed');
114  $this->setCurrentParameters('decimalSeparator', '%');
115  $this->setCurrentParameters('numericRender', 'raw');
116  $csvContent = $this->testAction->execute();
117  $this->saveReport(__METHOD__, $csvContent);
118  $this->assertEquals($this->readExampleFile("decimalSeparator_report.csv") , $csvContent);
119  }
120 
121  private function readExampleFile($fileName)
122  {
123  $csvFile = 'DCPTEST/' . $fileName;
124  $content = file_get_contents($csvFile);
125  return $content;
126  }
127 
128  private static function getOutputDir()
129  {
130  $tmpdir = getTmpDir();
131  $subdir = $tmpdir . "/PU_Report/";
132  if (!is_dir($subdir)) {
133  mkdir($subdir);
134  }
135  return $subdir;
136  }
137 
138  private function saveReport($testName, $content)
139  {
140  $testName = str_replace(":", "_", $testName);
141  $testName = str_replace('\\', "_", $testName);
142  $csvFile = sprintf('%s/csv_%s.csv', $this->getOutputDir() , $testName);
143  $fp = fopen($csvFile, 'w');
144  fwrite($fp, $content);
145  fclose($fp);
146  }
147 }
148 ?>
static addMessage($msg)
Definition: PU_dcp.php:44
setUpTestAction($appName, $actionName)
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
requiresCoreParamEquals($paramName, $requiredValue, $markTestIncomplete=true)
← centre documentaire © anakeen