more tests for private meta and filters visibility

This commit is contained in:
leogermani 2020-02-11 10:09:45 -03:00
parent 7d42f87982
commit e2e57d05bd
2 changed files with 136 additions and 0 deletions

View File

@ -665,6 +665,85 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals(401, $status);
}
public function test_private_filter_ids_not_in_filters_list(){
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'Statement',
'description' => 'No Statement',
'status' => 'publish',
),
true
);
$metadatumA = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Data',
'description' => 'Descreve valor do campo data.',
'collection' => $collection,
'status' => 'publish',
'metadata_type' => 'Tainacan\Metadata_Types\Text',
), true
);
$metadatumB = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Data',
'description' => 'Descreve valor do campo data.',
'collection' => $collection,
'status' => 'private',
'metadata_type' => 'Tainacan\Metadata_Types\Text',
), true
);
$filterA = $this->tainacan_entity_factory->create_entity(
'filter',
array(
'name' => 'test',
'status' => 'publish',
'collection' => $collection,
'metadatum' => $metadatumA,
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
),
true
);
$filterB = $this->tainacan_entity_factory->create_entity(
'filter',
array(
'name' => 'test',
'status' => 'private',
'collection' => $collection,
'metadatum' => $metadatumA,
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
),
true
);
wp_logout();
wp_set_current_user(0);
$requestA = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterA->get_id());
$requestB = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterB->get_id());
$requestC = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/filters');
$response = $this->server->dispatch($requestA);
$status = $response->status;
$this->assertEquals(200, $status);
$response = $this->server->dispatch($requestB);
$status = $response->status;
$this->assertEquals(401, $status);
$response = $this->server->dispatch($requestC);
$data = $response->get_data();
$this->assertEquals(1, count($data));
$this->assertEquals($filterA->get_id(), $data[0]['id']);
}
}
?>

View File

@ -714,6 +714,63 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals(401, $status);
}
public function test_private_filter_ids_not_in_metadata_list(){
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'Statement',
'description' => 'No Statement',
'status' => 'publish',
),
true
);
$metadatumA = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Data',
'description' => 'Descreve valor do campo data.',
'collection' => $collection,
'status' => 'publish',
'metadata_type' => 'Tainacan\Metadata_Types\Text',
), true
);
$metadatumB = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Data',
'description' => 'Descreve valor do campo data.',
'collection' => $collection,
'status' => 'private',
'metadata_type' => 'Tainacan\Metadata_Types\Text',
), true
);
wp_logout();
wp_set_current_user(0);
$requestA = new \WP_REST_Request('GET', $this->namespace . '/metadata/' . $metadatumA->get_id());
$requestB = new \WP_REST_Request('GET', $this->namespace . '/metadata/' . $metadatumB->get_id());
$requestC = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/metadata');
$response = $this->server->dispatch($requestA);
$status = $response->status;
$this->assertEquals(200, $status);
$response = $this->server->dispatch($requestB);
$status = $response->status;
$this->assertEquals(401, $status);
$response = $this->server->dispatch($requestC);
$data = $response->get_data();
$this->assertEquals(3, count($data));
$this->assertNotEquals($metadatumB->get_id(), $data[0]['id']);
$this->assertNotEquals($metadatumB->get_id(), $data[1]['id']);
$this->assertNotEquals($metadatumB->get_id(), $data[2]['id']);
}
}
?>