Merge branch 'master' of github.com:medialab-ufg/tainacan-test-repo

This commit is contained in:
Leo Germani 2017-11-14 22:52:20 -02:00
commit 602d088b0a
6 changed files with 49 additions and 45 deletions

View File

@ -48,12 +48,12 @@ class Tainacan_Filter extends Tainacan_Entity {
return new Tainacan_Metadata( $id );
}
function get_widget( $output = 'object' ){
if( $output === 'object'){
return unserialize( $this->get_mapped_property('option') );
} else{
return $this->get_mapped_property('widget');
}
function get_filter_type_object(){
return unserialize( $this->get_mapped_property('filter_type_object') );
}
function get_filter_type(){
return $this->get_mapped_property('filter_type');
}
// Setters
@ -82,21 +82,22 @@ class Tainacan_Filter extends Tainacan_Entity {
return $this->set_mapped_property('metadata', $id);
}
function set_widget($value){
if( is_object( $value ) && is_subclass_of( $value, 'Tainacan_Filter_Type' ) && $this->get_metadata() ){
$type = $this->get_metadata()->get_type();
//if filter matches the metadata type
if( in_array( $type->get_primitive_type(), $value->get_supported_types() ) ){
$this->set_option( $value );
return $this->set_mapped_property('widget', get_class( $value ) ) ;
}
}
return null;
function set_filter_type_object( Tainacan_Filter_Type $value ){
// TODO: validate primitive type with filter
//if filter matches the metadata type
//if( in_array( $type->get_primitive_type(), $value->get_supported_types() ) ){
$this->set_filter_type( get_class( $value ) );
return $this->set_mapped_property('filter_type_object',serialize($value) ) ;
//}
}
function set_option($value){
return $this->set_mapped_property('option', serialize($value) ) ;
/**
* este metodo eh privado pois eh setado automaticamente pelo metodo set_filter_type_object
*
* @param $value
*
*/
private function set_filter_type($value){
return $this->set_mapped_property('filter_type', $value );
}
}

View File

@ -75,12 +75,12 @@ class Tainacan_Metadata extends Tainacan_Entity {
return $this->get_mapped_property('default_value');
}
function get_type( $output = 'object' ){
if( $output === 'object'){
return unserialize( $this->get_mapped_property('option') );
}else{
return $this->get_mapped_property('type');
}
function get_field_type_object(){
return unserialize( $this->get_mapped_property('field_type_object') );
}
function get_field_type(){
return $this->get_mapped_property('field_type');
}
// Setters
@ -128,16 +128,19 @@ class Tainacan_Metadata extends Tainacan_Entity {
return $this->set_mapped_property('default_property', $value);
}
function set_type($value){
if( is_object( $value ) && is_subclass_of( $value, 'Tainacan_Field_Type' ) ){
$this->set_option( $value );
return $this->set_mapped_property('type', get_class( $value ) ) ;
}
return null;
function set_field_type_object(Tainacan_Field_Type $value){
$this->set_field_type( get_class( $value ) );
return $this->set_mapped_property('field_type_object', serialize($value) ) ;
}
function set_option($value){
return $this->set_mapped_property('option', serialize($value) ) ;
/**
* este metodo eh privado pois eh setado automaticamente pelo metodo set_field_type_object
*
* @param $value
*
*/
private function set_field_type($value){
return $this->set_mapped_property('field_type', $value ) ;
}
// helpers

View File

@ -24,11 +24,11 @@ class Tainacan_Filters {
'map' => 'post_content',
'validation' => ''
],
'widget' => [
'filter_type_object' => [
'map' => 'meta',
'validation' => ''
],
'option' => [
'filter_type' => [
'map' => 'meta',
'validation' => ''
],

View File

@ -31,7 +31,7 @@ class Tainacan_Metadatas {
'map' => 'post_content',
'validation' => ''
],
'type' => [
'field_type' => [
'map' => 'meta',
'validation' => ''
],
@ -67,7 +67,7 @@ class Tainacan_Metadatas {
'map' => 'meta',
'validation' => ''
],
'option' => [
'field_type_object' => [
'map' => 'meta',
'validation' => ''
],

View File

@ -49,7 +49,7 @@ class Test_Filters extends WP_UnitTestCase {
//setando os valores na classe do metadado
$metadata->set_name('metadado');
$metadata->set_collection_id( $collection->get_id() );
$metadata->set_type( $type );
$metadata->set_field_type_object( $type );
//inserindo o metadado
@ -61,9 +61,9 @@ class Test_Filters extends WP_UnitTestCase {
$filter->set_metadata( $metadata );
//nao devera permitir um filtro Range para o tipo string
$this->assertTrue( $filter->set_widget( $filter_range_type ) === null );
$this->assertTrue( $filter->set_filter_type_object( $filter_range_type ) === null );
$filter->set_widget( $filter_list_type );
$filter->set_filter_type_object( $filter_list_type );
$filter = $Tainacan_Filters->insert( $filter );
@ -72,7 +72,7 @@ class Test_Filters extends WP_UnitTestCase {
$this->assertEquals( $test->get_name(), 'filtro');
$this->assertEquals( $test->get_collection_id(), $collection->get_id() );
$this->assertEquals( $test->get_metadata()->get_id(), $metadata->get_id() );
$this->assertEquals( get_class( $test->get_widget() ), get_class( $filter_list_type ) );
$this->assertEquals( get_class( $test->get_filter_type_object() ), get_class( $filter_list_type ) );
}

View File

@ -54,7 +54,7 @@ class Test_Metadata extends WP_UnitTestCase {
//setando os valores na classe do metadado
$metadata->set_name('metadado');
$metadata->set_collection_id( $collection->get_id() );
$metadata->set_type( $type );
$metadata->set_field_type_object( $type );
//inserindo o metadado
@ -64,7 +64,7 @@ class Test_Metadata extends WP_UnitTestCase {
$this->assertEquals($test->get_name(), 'metadado');
$this->assertEquals($test->get_collection_id(), $collection->get_id());
$this->assertEquals($test->get_type('name'), 'Tainacan_Text_Field_Type');
$this->assertEquals($test->get_type(), $type);
$this->assertEquals($test->get_field_type(), 'Tainacan_Text_Field_Type');
$this->assertEquals($test->get_field_type_object(), $type);
}
}