Merge branch 'release/0.18' of https://github.com/tainacan/tainacan into release/0.18

This commit is contained in:
mateuswetah 2021-05-13 16:12:27 -03:00
commit 014161c769
3 changed files with 51 additions and 4 deletions

View File

@ -403,7 +403,7 @@ class Item_Metadata extends Repository {
$metadatum = $item_metadata->get_metadatum();
if ( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\User' ) {
$options = $metadatum->get_metadata_type_options();
if ( isset($options['default_author']) && $options['default_author'] = 'yes') {
if ( isset($options['default_author']) && $options['default_author'] == 'yes') {
$value = $metadatum->is_multiple() ? [strval(get_current_user_id())] : strval(get_current_user_id());
$item_metadata->set_value($value);
if ( $item_metadata->validate() ) {

View File

@ -481,6 +481,52 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals(201, $response->get_status());
}
public function test_create_default_user_value_metadata() {
$user_id = get_current_user_id();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'Agile',
'description' => 'Agile methods',
'status' => 'publish'
),
true
);
$metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'creator',
'description' => 'description of creator',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\User',
'status' => 'publish',
'metadata_type_options' => [
'default_author' => 'yes',
]
),
true
);
$item_json = json_encode([
'status' => "auto-draft",
'collection_id' => $collection->get_id()
]);
$request = new \WP_REST_Request('POST', $this->namespace . '/collection/' . $collection->get_id() . '/items');
$request->set_body($item_json);
$response_item = $this->server->dispatch($request);
$data_item = $response_item->get_data();
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $data_item['id'] . '/metadata');
$this->server->dispatch($request);
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $data_item['id'] . '/metadata/' . $metadatum->get_id());
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals($data['value'], $user_id);
}
/**
* @group duplicate
*/

View File

@ -329,8 +329,8 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
$this->assertEquals(0, $check_deleted);
$core_metadata_son3 = $collection_son->get_core_metadata();
$this->assertEquals( $core_metadata_son3[0]->get_id(), $core_metadata_parent2[0]->get_id() );
$core_metadata_parent2_ids = array_map(function($meta) { return $meta->get_id(); }, $core_metadata_parent2);
$this->assertContains( $core_metadata_son3[0]->get_id(), $core_metadata_parent2_ids );
$it3 = get_post_meta($collection_son_item->get_id());
@ -350,7 +350,8 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
$core_metadata_son4 = $collection_son->get_core_metadata();
$this->assertEquals( $core_metadata_son4[0]->get_id(), $core_metadata_parent[0]->get_id() );
$core_metadata_parent_ids = array_map(function($meta) { return $meta->get_id(); }, $core_metadata_parent);
$this->assertContains( $core_metadata_son4[0]->get_id(), $core_metadata_parent_ids);
$it4 = get_post_meta($collection_son_item->get_id());