Commit 571fa0f1 authored by claudiu.cristea's avatar claudiu.cristea Committed by claudiu.cristea

Issue #2819275 by claudiu.cristea: Test with all supported types of worksheets

parent e919879f
......@@ -8,17 +8,9 @@ files. This source plugin uses the
to read from the spreadsheet files.
[The supported source
files](https://github.com/PHPOffice/PhpSpreadsheet#file-formats-supported)
files](https://phpspreadsheet.readthedocs.io/en/latest/#file-formats-supported)
includes .ods, .xls, .xlsx, .csv.
## Installing PHPSpreadsheet
### Requirements
Migrate Spreadsheet module requires PHP >= 5.6 due to its dependency on
[PhpOffice/PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) library,
which requires at least PHP 5.6.
### Get the code
Use [Composer](https://getcomposer.org/) to install [Migrate
......
,,
,ID,Name
,2,Foo
,6,Bar
,34,Baz
,999,Qux
ID;PCALCOOO32
C;X2;Y2;K"ID"
C;X3;Y2;K"Name"
C;X2;Y3;K2
C;X3;Y3;K"Foo"
C;X2;Y4;K6
C;X3;Y4;K"Bar"
C;X2;Y5;K34
C;X3;Y5;K"Baz"
C;X2;Y6;K999
C;X3;Y6;K"Qux"
E
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Claudiu Cristea</Author>
<LastAuthor>Claudiu Cristea</LastAuthor>
<Created>2020-10-07T09:23:40Z</Created>
<LastSaved>2020-10-07T12:06:37Z</LastSaved>
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>16320</WindowHeight>
<WindowWidth>28040</WindowWidth>
<WindowTopX>380</WindowTopX>
<WindowTopY>460</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:CharSet="238" x:Family="Swiss" ss:Size="12"
ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="6" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="16">
<Row ss:Index="2">
<Cell ss:Index="2"><Data ss:Type="String">ID</Data></Cell>
<Cell><Data ss:Type="String">Name</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="Number">2</Data></Cell>
<Cell><Data ss:Type="String">Foo</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="Number">6</Data></Cell>
<Cell><Data ss:Type="String">Bar</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="Number">34</Data></Cell>
<Cell><Data ss:Type="String">Baz</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="Number">999</Data></Cell>
<Cell><Data ss:Type="String">Qux</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>1</ActiveRow>
<ActiveCol>2</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
<?php
declare(strict_types = 1);
namespace Drupal\Tests\migrate_spreadsheet\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
/**
* Tests the 'spreadsheet' migrate source plugin.
*
* @coversDefaultClass \Drupal\migrate_spreadsheet\Plugin\migrate\source\Spreadsheet
* @group migrate_spreadsheet
*/
class MigrateSpreadsheetTest extends MigrateTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'entity_test',
'migrate',
'migrate_spreadsheet',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('entity_test');
}
/**
* @covers ::initializeIterator
* @dataProvider pluginTestProvider
*
* @param array $configuration
* The migrate plugin configuration.
*/
public function testPlugin(array $configuration): void {
$migration = $this->container->get('plugin.manager.migration')
->createStubMigration($configuration);
$this->executeMigration($migration);
$this->assertSame('Foo', EntityTest::load(2)->label());
$this->assertSame('Bar', EntityTest::load(6)->label());
$this->assertSame('Baz', EntityTest::load(34)->label());
$this->assertSame('Qux', EntityTest::load(999)->label());
}
/**
* Provides testing cases for ::testPlugin() test.
*
* @return \string[][]
* Test cases.
*/
public function pluginTestProvider(): array {
$configuration = [
'source' => [
'plugin' => 'spreadsheet',
'worksheet' => 'Sheet1',
'origin' => 'B3',
'header_row' => 2,
'columns' => [
'ID',
'Name',
],
'keys' => [
'ID' => [
'type' => 'integer',
'size' => 'big',
],
],
],
'process' => [
'id' => 'ID',
'name' => 'Name',
],
'destination' => [
'plugin' => 'entity:entity_test',
],
];
$files = [
'Open Document Format/OASIS (.ods)' => 'test.ods',
'Office Open XML (.xlsx) Excel 2007 and above' => 'test.xlsx',
'BIFF 8 (.xls) Excel 97 and above' => 'test.xls',
'BIFF 5 (.xls) Excel 95' => 'test_excel5.xls',
'SpreadsheetML (.xml) Excel 2003' => 'test.xml',
'SYLK' => 'test.slk',
'CSV' => 'test.csv',
];
return array_map(function (string $filename) use ($configuration): array {
$configuration['source']['file'] = __DIR__ . "/../../fixtures/{$filename}";
return [$configuration];
}, $files);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment