public function PHPExcelTest::testIssue1988868 in PHPExcel 7.3
Same name and namespace in other branches
- 8.3 tests/phpexcel.test \PHPExcelTest::testIssue1988868()
A cell with a value of '0' must get exported as such.
See also
http://drupal.org/node/1988868
File
- tests/
phpexcel.test, line 108 - Defines the test case for phpexcel
Class
- PHPExcelTest
- @file Defines the test case for phpexcel
Code
public function testIssue1988868() {
// Prepare the data.
$headers = array(
'Header 1',
'Header 2',
);
$data = array(
array(
'0',
'Data 1.2',
),
array(
'Data 2.1',
'0',
),
array(
'0',
'0',
),
);
// Create a file path.
$correct_path = file_create_filename($this
->getFilename(), $this->directory);
// The filename will be munged by the export function, so:
$this->test_files[] = $actual_path = phpexcel_munge_filename($correct_path);
$this
->assertEqual(PHPEXCEL_SUCCESS, phpexcel_export($headers, $data, $correct_path), t('Exported data to !path', array(
'!path' => $actual_path,
)));
$this
->assertTrue(filesize($actual_path) > 0, 'Filesize should be bigger than 0');
// Import, not keyed by headers.
$data = phpexcel_import($actual_path, FALSE);
$this
->assertTrue(!!$data, 'Import succeeded');
// Second row, 1st cell should be '0'.
$cell = $data[0][1][0];
$this
->assertTrue($cell === '0', 'Second row, 1st cell data should be "0"');
// Second row, 2nd cell should be 'Data 1.2'.
$cell = $data[0][1][1];
$this
->assertTrue($cell === 'Data 1.2', 'Second row, 2nd cell data should be "Data 1.2"');
// Third row, 2nd cell should be '0'.
$cell = $data[0][2][1];
$this
->assertTrue($cell === '0', 'Third row, 2nd cell data should be "0"');
// Fourth row, 1st cell should be '0'.
$cell = $data[0][3][0];
$this
->assertTrue($cell === '0', 'Fourth row, 1st cell data should be "0"');
// Fourth row, 2nd cell should be '0'.
$cell = $data[0][3][1];
$this
->assertTrue($cell === '0', 'Fourth row, 2nd cell data should be "0"');
}