diff options
author | Matthieu Aubry <matt@piwik.org> | 2016-04-08 03:57:40 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2016-04-08 03:57:40 +0300 |
commit | 802b0f10642236269c9992c3b90d748a7ee052c3 (patch) | |
tree | d5d14c1fede1458005afe5ae98997d7f949a5283 /plugins | |
parent | 7970c82f530c71a0fb7e2cd96e456404eea8dbaa (diff) | |
parent | 1809a57381b37b68a3bcc8f50845b61e38e51d6d (diff) |
Merge pull request #10015 from piwik/excel_labels
Display labels correctly in Excel / LibreOffice
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/API/tests/Unit/CsvRendererTest.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/plugins/API/tests/Unit/CsvRendererTest.php b/plugins/API/tests/Unit/CsvRendererTest.php index 76d16ed515..9cc66e7277 100644 --- a/plugins/API/tests/Unit/CsvRendererTest.php +++ b/plugins/API/tests/Unit/CsvRendererTest.php @@ -105,6 +105,66 @@ The Output', $response); The\nOutput', $response); } + /** + * @dataProvider getCellValuesToPrefixOrNot + */ + public function test_renderScalar_whenCellValueIsFormula_shouldPrefixWithQuote($value, $expectedCsvValue) + { + $response = $this->builder->renderScalar($value); + + $this->assertEquals("value\n$expectedCsvValue", $response); + } + + public function getCellValuesToPrefixOrNot() + { + // input, expected csv output + return array( + // we prefix with quotes + array('=test()', '\'=test()'), + array('=1+1', '\'=1+1'), + array('@1+1', '\'@1+1'), + array('+1+1', '\'+1+1'), + array('+1+test()', '\'+1+test()'), + array('-1+1', '\'-1+1'), + array('@-1+1', '\'@-1+1'), + array('-test()', '\'-test()'), + array('-te,st()', '"\'-te,st()"'), + array('-te"st()', '"\'-te""st()"'), + + // we do not need to prefix with quote + array('1', '1'), + array('2', '2'), + array('2@', '2@'), + array('20000000', '20000000'), + array('10%', '10%'), + array('10.5%', '10.5%'), + array('-10.5%', '-10.5%'), + array('+10,5%', '"\'+10,5%"'), + array('10,5', '"10,5"'), + array('1+test()', '1+test()'), + array('1+test@', '1+test@'), + array('', ''), + array(0, '0'), + array(2.2, '2.2'), + array(-2.2, '-2.2'), + array(false, '0'), + array(null, ''), + ); + } + + /** + * @dataProvider getCellValuesToPrefixOrNot + */ + public function test_renderDataTable_shouldRenderFormulas($value, $expectedValue) + { + $dataTable = new DataTable(); + $dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => $value)); + + $response = $this->builder->renderDataTable($dataTable); + + $this->assertEquals("nb_visits,nb_random\n5,$expectedValue", $response); + } + public function test_renderDataTable_shouldRenderABasicDataTable() { $dataTable = new DataTable(); |