You are here

public function SpreadsheetIteratorTest::testGetHeaders in Migrate Spreadsheet 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/SpreadsheetIteratorTest.php \Drupal\Tests\migrate_spreadsheet\Unit\SpreadsheetIteratorTest::testGetHeaders()

@covers ::getHeaders

File

tests/src/Unit/SpreadsheetIteratorTest.php, line 100

Class

SpreadsheetIteratorTest
Tests the spreadsheet iterator.

Namespace

Drupal\Tests\migrate_spreadsheet\Unit

Code

public function testGetHeaders() {
  $cols = [
    'column b' => 'B',
    'column c' => 'C',
    'column d' => 'D',
    'column e' => 'E',
    'column g' => 'G',
  ];
  $this
    ->assertSame($cols, $this->iterator
    ->getHeaders());

  // Check headers when there's no header row. All columns should be used.
  $config = $this->iterator
    ->getConfiguration();
  unset($config['header_row']);
  $this->iterator
    ->setConfiguration($config);
  $this
    ->assertSame([
    'B' => 'B',
    'C' => 'C',
    'D' => 'D',
    'E' => 'E',
    'F' => 'F',
    'G' => 'G',
  ], $this->iterator
    ->getHeaders());

  // Check duplicate headers.
  $this
    ->getWorksheet()
    ->setCellValue('C2', 'column b');
  $config['header_row'] = 2;
  $this->iterator
    ->setConfiguration($config);
  $this
    ->setExpectedException('RuntimeException');
  $this->iterator
    ->getHeaders();
}