public function PHPExcelTest::testIgnoreHeaders in PHPExcel 8.3
Same name and namespace in other branches
- 7.3 tests/phpexcel.test \PHPExcelTest::testIgnoreHeaders()
- 7.2 tests/phpexcel.test \PHPExcelTest::testIgnoreHeaders()
Test "ignore_headers" option.
File
- tests/
phpexcel.test, line 287 - Defines the test case for phpexcel
Class
- PHPExcelTest
- @file Defines the test case for phpexcel
Code
public function testIgnoreHeaders() {
/**
* Export
*/
// Prepare data
$data = array(
0 => array(
array(
'Data 1.1.1',
'Data 1.1.2',
),
array(
'Data 1.2.1',
'Data 1.2.2',
),
array(
'Data 1.3.1',
'Data 1.3.2',
),
),
'Sheet 2' => array(
array(
'Data 2.1.1',
'Data 2.1.2',
),
array(
'Data 2.2.1',
'Data 2.2.2',
),
array(
'Data 2.3.1',
'Data 2.3.2',
),
),
);
// Create a file path
$correct_path = file_create_filename('phpexcel_test3.xls', $this->directory);
// The filename will be munged by the export function, so:
$this->no_headers_file = phpexcel_munge_filename($correct_path);
// Should pass
$this
->assertEqual(PHPEXCEL_SUCCESS, phpexcel_export(NULL, $data, $correct_path, array(
'ignore_headers' => TRUE,
)), t('Exported data to !path', array(
'!path' => $this->no_headers_file,
)));
// Should pass
$this
->assertTrue(filesize($this->no_headers_file) > 0, 'Filesize should be bigger than 0');
/**
* Import and check.
* Import, not keyed by headers
*/
$data = phpexcel_import($this->no_headers_file, FALSE);
// Should pass
$this
->assertTrue(!!$data, 'Import succeeded');
// Should have 3 rows
$count = !empty($data[0]) ? count($data[0]) : 0;
$this
->assertTrue($count === 3, t('!count rows, expect 3', array(
'!count' => $count,
)));
// Should only have 2 cells
$count = !empty($data[0][0]) ? count($data[0][0]) : 0;
$this
->assertTrue($count === 2, t('!count cells, expect 2', array(
'!count' => $count,
)));
$header = !empty($data[0][0][0]) ? $data[0][0][0] : 'no';
$this
->assertTrue($header === 'Data 1.1.1', 'Should be "Data 1.1.1"');
$header = !empty($data[1][1][1]) ? $data[1][1][1] : 'no';
$this
->assertTrue($header === 'Data 2.2.2', 'Should be "Data 2.2.2"');
}