You are here

public function SpreadsheetIteratorTest::testGetHeaders in Migrate Spreadsheet 2.0.x

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

@covers ::getHeaders

File

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

Class

SpreadsheetIteratorTest
Tests the spreadsheet iterator.

Namespace

Drupal\Tests\migrate_spreadsheet\Unit

Code

public function testGetHeaders() : void {
  $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
    ->expectException('RuntimeException');
  $this->iterator
    ->getHeaders();
}