From 0c8545159cc76d5580c808a7a536a7cf0d8572b9 Mon Sep 17 00:00:00 2001 From: Eduardo Humberto Date: Tue, 23 Oct 2018 19:44:07 -0300 Subject: [PATCH] tainacan csv importer - add tests for create metadata in csv header --- src/importer/class-tainacan-csv.php | 2 +- src/importer/class-tainacan-importer.php | 4 ++-- tests/test-importer.php | 19 +++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/importer/class-tainacan-csv.php b/src/importer/class-tainacan-csv.php index 95fce4694..46d11bebf 100644 --- a/src/importer/class-tainacan-csv.php +++ b/src/importer/class-tainacan-csv.php @@ -160,7 +160,7 @@ class CSV extends Importer { $valueToInsert = $this->handle_encoding( $values[ $column ] ); if( !is_numeric($metadatum_id) ){ - $metadatum = $this->create_metadata( $metadatum_id, $collection_definition['id']); + $metadatum = $this->create_metadata( $headers[ $column ], $collection_definition['id']); } else { $metadatum = new \Tainacan\Entities\Metadatum($metadatum_id); } diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index 7f9183cce..9da62bb26 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -908,8 +908,8 @@ abstract class Importer { * @throws \Exception */ protected function create_metadata( $metadata_description, $collection_id){ - $taxonomy_repo = \Repositories\Taxonomy::get_instance(); - $metadata_repo = \Repositories\Metadata::get_instance(); + $taxonomy_repo = \Tainacan\Repositories\Taxonomies::get_instance(); + $metadata_repo = \Tainacan\Repositories\Metadata::get_instance(); $properties = array_filter( explode('|', $metadata_description) ); diff --git a/tests/test-importer.php b/tests/test-importer.php index c13bcfb0a..79b802747 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -258,7 +258,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { $file = fopen($file_name, 'w'); // save the column headers - fputcsv($file, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5')); + fputcsv($file, array('novo metadatao|text', 'Column 2', 'Column 3', 'Column 4', 'Column 5')); // Sample data $data = array( @@ -363,7 +363,12 @@ class ImporterTests extends TAINACAN_UnitTestCase { //create a random mapping $map = []; foreach ( $metadata as $index => $metadatum ){ - $map[$metadatum->get_id()] = $headers[$index]; + if( $index === 0){ + $map['create_metadata'] = $headers[$index]; + } else { + $map[$metadatum->get_id()] = $headers[$index]; + } + } $collection_definition['mapping'] = $map; @@ -383,16 +388,6 @@ class ImporterTests extends TAINACAN_UnitTestCase { $items = $Tainacan_Items->fetch( ['order'=> 'ASC','orderby' => 'date'], $collection, 'OBJECT' ); - foreach ( $items as $index => $item ) { - $singleItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadata_taxonomy ); - $term = $singleItemMetadata->get_value(); - - if( in_array( $item->get_title(),[ 'Data 11','Data 51', 'Data 12','Data 52'] ) && $term ){ - $this->assertTrue(in_array( strtoupper($term->get_name()),['DATA 151','DATA551'] )); - } - - } - $this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_source_number_of_items(), count( $items ) ); }