public function PHPExcelTest::testTemplateExport in PHPExcel 7.3
Same name and namespace in other branches
- 8.3 tests/phpexcel.test \PHPExcelTest::testTemplateExport()
- 6.2 tests/phpexcel.test \PHPExcelTest::testTemplateExport()
- 6 tests/phpexcel.test \PHPExcelTest::testTemplateExport()
- 7.2 tests/phpexcel.test \PHPExcelTest::testTemplateExport()
Test a simple, single worksheet Excel export.
File
- tests/
phpexcel.test, line 342 - Defines the test case for phpexcel
Class
- PHPExcelTest
- @file Defines the test case for phpexcel
Code
public function testTemplateExport() {
// Prepare the data.
$data = array(
array(
'Data 1.1',
'Data 1.2',
),
array(
'Data 2.1',
'Data 2.2',
),
array(
'Data 3.1',
'Data 3.2',
),
);
// Options.
$options = array(
'format' => 'xlsx',
'template' => drupal_get_path('module', 'phpexcel') . '/tests/data/phpexcel.test.template.xlsx',
'ignore_headers' => TRUE,
);
// Create a file path.
$correct_path = file_create_filename($this
->getFilename('xlsx'), $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(array(), $data, $correct_path, $options), t('Exported data to !path', array(
'!path' => $actual_path,
)));
$this
->assertTrue(filesize($actual_path) > 0, 'Filesize should be bigger than 0');
// Import and check.
$data = phpexcel_import($actual_path, FALSE);
// Debug data.
$this
->verbose(print_r($data, 1));
$this
->assertTrue(!!$data, 'Import succeeded');
// Should have 3 rows (3 rows and no headers).
$count = !empty($data[0]) ? count($data[0]) : 0;
$this
->assertTrue($count === 3, t('!count rows, expect 3', array(
'!count' => $count,
)));
// First row, 1st cell should be 'Data 1.1'.
$header = !empty($data[0][0][0]) ? $data[0][0][0] : 'no';
$this
->assertTrue($header === 'Data 1.1', 'First row, 1st cell data should be "Data 1.1", and is ' . $header);
// Second row, 1st cell should be 'Data 2.1'.
$header = !empty($data[0][1][0]) ? $data[0][1][0] : 'no';
$this
->assertTrue($header === 'Data 2.1', 'Second row, 1st cell data should be "Data 2.1", and is ' . $header);
}