csv importer - create tests for different document types and fix index error on process item
This commit is contained in:
parent
78497d66ba
commit
7fd2138485
|
@ -106,14 +106,14 @@ class CSV extends Importer {
|
|||
|
||||
foreach ( $headers as $indexRaw => $headerRaw ) {
|
||||
if( $headerRaw === $header ){
|
||||
$index = $indexRaw;
|
||||
$column = $indexRaw;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($index))
|
||||
if(!isset($column))
|
||||
continue;
|
||||
|
||||
$valueToInsert = $this->handle_encoding( $values[ $index ] );
|
||||
$valueToInsert = $this->handle_encoding( $values[ $column ] );
|
||||
|
||||
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
|
||||
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
|
||||
|
@ -137,6 +137,12 @@ class CSV extends Importer {
|
|||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$file->setFlags(\SplFileObject::SKIP_EMPTY);
|
||||
$file->seek( $index );
|
||||
|
||||
if( $index === 0 ){
|
||||
$file->current();
|
||||
$file->next();
|
||||
}
|
||||
|
||||
$values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') );
|
||||
|
||||
if( is_array($values) && !empty($column_document) ){
|
||||
|
|
|
@ -483,6 +483,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$_SESSION['tainacan_importer'][$id]->add_collection( $collection_definition );
|
||||
$_SESSION['tainacan_importer'][$id]->set_option('encode','iso88591');
|
||||
|
||||
$this->assertEquals(1, $_SESSION['tainacan_importer'][$id]->run(), 'first step should import 1 item');
|
||||
while($_SESSION['tainacan_importer'][$id]->run()){
|
||||
continue;
|
||||
}
|
||||
|
||||
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
|
||||
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_source_number_of_items(), count( $items ) );
|
||||
|
||||
// test row 5
|
||||
$document_id = $items[0]->get_document();
|
||||
$this->assertFalse( is_numeric($document_id) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue