diff --git a/tests/test-api-items.php b/tests/test-api-items.php index 8c83cb29f..fa10aede5 100644 --- a/tests/test-api-items.php +++ b/tests/test-api-items.php @@ -380,7 +380,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase { $data = $response->get_data()['items']; $this->assertEquals( 2, sizeof($data) ); - $this->assertEquals( 5, sizeof($data[0]['metadata']) ); + $this->assertEquals( 6, sizeof($data[0]['metadata']) ); // Fetch only as admin $request = new \WP_REST_Request( diff --git a/tests/test-api-metadata.php b/tests/test-api-metadata.php index a1b2e8a01..6b5417f0e 100644 --- a/tests/test-api-metadata.php +++ b/tests/test-api-metadata.php @@ -825,7 +825,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase { $response = $this->server->dispatch($request); $data = $response->get_data(); - $this->assertEquals(4, count($data['metadata_order'])); + $this->assertEquals(5, count($data['metadata_order'])); wp_logout(); wp_set_current_user(0); diff --git a/tests/test-api-metadatum-mappers.php b/tests/test-api-metadatum-mappers.php index ada17ac79..bf1d82a7a 100644 --- a/tests/test-api-metadatum-mappers.php +++ b/tests/test-api-metadatum-mappers.php @@ -205,13 +205,13 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas $dc = new \Tainacan\Mappers\Dublin_Core(); $metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/collections'); - $metadatum_mapper_request->set_body(json_encode([ + $metadatum_mapper_request->set_body(json_encode([ \Tainacan\Mappers_Handler::MAPPER_PARAM => $dc->slug, 'name' => 'Test Collection' ])); - $metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request); - $this->assertEquals(201, $metadatum_mapper_response->get_status()); - $data = $metadatum_mapper_response->get_data(); + $metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request); + $this->assertEquals(201, $metadatum_mapper_response->get_status()); + $data = $metadatum_mapper_response->get_data(); $collection = \Tainacan\Repositories\Collections::get_instance()->fetch( $data['id'] ); diff --git a/tests/test-capabilities.php b/tests/test-capabilities.php index 0c38b8d5a..d9db8b010 100644 --- a/tests/test-capabilities.php +++ b/tests/test-capabilities.php @@ -510,17 +510,17 @@ class Capabilities extends TAINACAN_UnitTestCase { $current_user = $this->subscriber2; // force update current user object with new capabilities $meta = tainacan_metadata()->fetch_by_collection($this->public_collection); - $this->AssertEquals(5, sizeof($meta)); + $this->AssertEquals(6, sizeof($meta)); $meta = tainacan_metadata()->fetch_ids_by_collection($this->public_collection); - $this->AssertEquals(5, sizeof($meta)); + $this->AssertEquals(6, sizeof($meta)); $this->subscriber2->add_cap( 'tnc_rep_read_private_metadata' ); $current_user = $this->subscriber2; // force update current user object with new capabilities $meta = tainacan_metadata()->fetch_by_collection($this->public_collection); - $this->AssertEquals(6, sizeof($meta)); + $this->AssertEquals(7, sizeof($meta)); $meta = tainacan_metadata()->fetch_ids_by_collection($this->public_collection); - $this->AssertEquals(6, sizeof($meta)); + $this->AssertEquals(7, sizeof($meta)); } diff --git a/tests/test-core-metadatum-types.php b/tests/test-core-metadatum-types.php index 887ec54b2..b82ffede8 100644 --- a/tests/test-core-metadatum-types.php +++ b/tests/test-core-metadatum-types.php @@ -33,6 +33,8 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $metadatum = $collection->get_core_title_metadatum(); $metadatumDescription = $collection->get_core_description_metadatum(); + + $metadatumAuthor = $collection->get_core_author_metadatum(); $i = $this->tainacan_entity_factory->create_entity( @@ -56,7 +58,7 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $checkItem = $Tainacan_Items->fetch($i->get_id()); $this->assertEquals('changed title', $checkItem->get_title()); - + $check_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($checkItem, $metadatum); $this->assertEquals('changed title', $check_item_metadata->get_value()); @@ -87,6 +89,10 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertEquals(1, sizeof($checkMeta)); $this->assertEquals('changed description', $checkMeta[0]->get_description()); + + + // author + $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatumAuthor); } @@ -194,7 +200,7 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $core_metadata = $collection->get_core_metadata(); - $this->assertEquals(2, sizeof($core_metadata)); + $this->assertEquals(3, sizeof($core_metadata)); $this->assertNotEquals('Tainacan\Metadata_Types\Text', $core_metadata[0]->get_metadata_type()); $this->assertNotEquals('Tainacan\Metadata_Types\Text', $core_metadata[1]->get_metadata_type()); @@ -253,17 +259,30 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { array( 'title' => 'Son of son', 'description' => 'Desc of son of son', - 'collection' => $collection_son, + 'collection' => $collection_son, + 'author_id' => get_current_user_id(), 'status' => 'publish' ), true ); - $item_metadatum_title = $this->tainacan_item_metadata_factory->create_item_metadata($collection_son_item, - $core_metadata_son[1], 'Son of son'); + $item_metadatum_title = $this->tainacan_item_metadata_factory->create_item_metadata( + $collection_son_item, + $core_metadata_son[1], + 'Son of son' + ); - $item_metadatum_desc = $this->tainacan_item_metadata_factory->create_item_metadata($collection_son_item, $core_metadata_son[0], - 'Desc of son of son'); + $item_metadatum_desc = $this->tainacan_item_metadata_factory->create_item_metadata( + $collection_son_item, + $core_metadata_son[0], + 'Desc of son of son' + ); + + $item_metadatum_author = $this->tainacan_item_metadata_factory->create_item_metadata( + $collection_son_item, + $core_metadata_son[2], + get_current_user_id() + ); $this->assertEquals($core_metadata_son[0]->get_id(), $item_metadatum_desc->get_metadatum()->get_id()); $this->assertEquals($core_metadata_son[1]->get_id(), $item_metadatum_title->get_metadatum()->get_id()); diff --git a/tests/test-importer.php b/tests/test-importer.php index feb50c0c7..d02c799f4 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -263,19 +263,19 @@ 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('author', 'Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5')); // Sample data $data = array( - array('Data 11', 'Data 12', 'Data 13||TESTE', 'Data 14', 'Data 15>>DATA 151'), - array('Data 21', 'Data 22', 'this + array(get_current_user_id(), 'Data 11', 'Data 12', 'Data 13||TESTE', 'Data 14', 'Data 15>>DATA 151'), + array(get_current_user_id(), 'Data 21', 'Data 22', 'this is having multiple lines', 'Data 24', 'Data 25'), - array('Data 31', 'Data 32', utf8_decode( 'Data 33||Rééço' ), 'Data 34', 'Data 35'), - array('Data 41', 'Data 42', 'Data 43||limbbo', 'Data 44', 'Data 45'), - array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55>>DATA551') + array(get_current_user_id(), 'Data 31', 'Data 32', utf8_decode( 'Data 33||Rééço' ), 'Data 34', 'Data 35'), + array(get_current_user_id(), 'Data 41', 'Data 42', 'Data 43||limbbo', 'Data 44', 'Data 45'), + array(get_current_user_id(), 'Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55>>DATA551') ); // save each row of the data @@ -296,7 +296,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { // get metadata to mapping $headers = $importer_instance->get_source_metadata(); - $this->assertEquals( $headers[4], 'Column 5' ); + $this->assertEquals( $headers[5], 'Column 5' ); // inserting the collection $collection = $this->tainacan_entity_factory->create_entity( @@ -368,13 +368,18 @@ class ImporterTests extends TAINACAN_UnitTestCase { //create a random mapping $map = []; - foreach ( $metadata as $index => $metadatum ){ - if( $index === 0){ + $index = 1; + foreach ( $metadata as $metadatum ){ + if ($metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Core_Author') { + $map[$metadatum->get_id()] = $headers[0]; + continue; + } + if( $index === 1){ $map['create_metadata'] = $headers[$index]; } else { $map[$metadatum->get_id()] = $headers[$index]; } - + $index++; } $collection_definition['mapping'] = $map; diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 9badf85e3..abd2a1461 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -240,7 +240,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue(is_array($item_metadatas)); // notice for repository metadata - $this->assertEquals(3, sizeof($item_metadatas)); + $this->assertEquals(4, sizeof($item_metadatas)); //first 2 metadata are repository metadata $this->assertTrue( in_array('metadado', $names) ); diff --git a/tests/test-metadata.php b/tests/test-metadata.php index 3ba0a450f..d7380a4c7 100644 --- a/tests/test-metadata.php +++ b/tests/test-metadata.php @@ -165,8 +165,8 @@ class Metadata extends TAINACAN_UnitTestCase { $retrieve_metadata_ids = $Tainacan_Metadata->fetch_ids_by_collection( $collection_son, [] ); // should return 6 - $this->assertEquals( 6, sizeof( $retrieve_metadata ) ); - $this->assertEquals( 6, sizeof( $retrieve_metadata_ids ) ); + $this->assertEquals( 7, sizeof( $retrieve_metadata ) ); + $this->assertEquals( 7, sizeof( $retrieve_metadata_ids ) ); } /**