insert validation methods in repositories mapping

This commit is contained in:
Eduardo humberto 2017-12-01 14:06:35 -02:00
parent d06e1a7135
commit f8b64edd6f
7 changed files with 109 additions and 13 deletions

View File

@ -91,7 +91,7 @@ class Taxonomy extends Entity {
}
function get_allow_insert() {
return ( boolean ) $this->get_mapped_property('allow_insert');
return $this->get_mapped_property('allow_insert');
}
function get_slug() {

View File

@ -5,6 +5,7 @@ use Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use \Respect\Validation\Validator as v;
class Filters extends Repository {
protected $entities_type = '\Tainacan\Entities\Filter';
@ -12,38 +13,66 @@ class Filters extends Repository {
return apply_filters('tainacan-get-map', [
'id' => [
'map' => 'ID',
'title' => __('ID', 'tainacan'),
'type' => 'integer',
'description'=> __('Unique identifier', 'tainacan'),
//'validation' => ''
],
'name' => [
'map' => 'post_title',
'validation' => ''
'title' => __('Name', 'tainacan'),
'type' => 'string',
'description'=> __('Name of the filter', 'tainacan'),
'on_error' => __('The filter name should be a text value and not empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
'order' => [
'map' => 'menu_order',
'title' => __('Order', 'tainacan'),
'type' => 'string',
'description'=> __('Filter order. Field used if filters are manually ordered', 'tainacan'),
'validation' => ''
],
'description' => [
'map' => 'post_content',
'title' => __('Description', 'tainacan'),
'type' => 'string',
'description'=> __('The filter description', 'tainacan'),
'validation' => ''
],
'filter_type_object' => [
'map' => 'meta',
'title' => __('Type', 'tainacan'),
'type' => 'string',
'description'=> __('The filter type object', 'tainacan'),
'validation' => ''
],
'filter_type' => [
'map' => 'meta',
'title' => __('Type', 'tainacan'),
'type' => 'string',
'description'=> __('The filter type', 'tainacan'),
'validation' => ''
],
'collection_id' => [
'map' => 'meta',
'title' => __('Collection', 'tainacan'),
'type' => 'integer',
'description'=> __('The collection ID', 'tainacan'),
'validation' => ''
],
'color' => [
'map' => 'meta',
'title' => __('Color', 'tainacan'),
'type' => 'integer',
'description'=> __('Filter color', 'tainacan'),
'validation' => ''
],
'metadata' => [
'map' => 'meta',
'title' => __('Metadata', 'tainacan'),
'type' => 'integer',
'description'=> __('Filter metadata', 'tainacan'),
'validation' => ''
],
]);

View File

@ -2,6 +2,7 @@
namespace Tainacan\Repositories;
use Tainacan\Entities;
use \Respect\Validation\Validator as v;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
@ -11,18 +12,31 @@ class Items extends Repository {
return apply_filters('tainacan-get-map', [
'id' => [
'map' => 'ID',
'title' => __('ID', 'tainacan'),
'type' => 'integer',
'description'=> __('Unique identifier', 'tainacan'),
//'validation' => ''
],
'title' => [
'map' => 'post_title',
'validation' => ''
'title' => __('Title', 'tainacan'),
'type' => 'string',
'description'=> __('Title of the item', 'tainacan'),
'on_error' => __('The title should be a text value and not empty', 'tainacan'),
'validation' => v::stringType()->notEmpty()
],
'description' => [
'map' => 'post_content',
'title' => __('Description', 'tainacan'),
'type' => 'string',
'description'=> __('The item description', 'tainacan'),
'validation' => ''
],
'collection_id' => [
'map' => 'meta',
'title' => __('Collection', 'tainacan'),
'type' => 'integer',
'description'=> __('The collection ID', 'tainacan'),
'validation' => ''
],
//'collection' => 'relation...',

View File

@ -124,13 +124,17 @@ class Metadatas extends Repository {
],
'field_type_object' => [ // not showed in form
'map' => 'meta',
'title' => __('Type', 'tainacan'),
'type' => 'string',
'validation' => ''
'description'=> __('The object type', 'tainacan'),
// 'validation' => ''
],
'collection_id' => [ // not showed in form
'map' => 'meta',
'title' => __('Collection', 'tainacan'),
'type' => 'integer',
'validation' => ''
'description'=> __('The collection ID', 'tainacan'),
//'validation' => ''
],
]);
}

View File

@ -5,6 +5,8 @@ use Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use \Respect\Validation\Validator as v;
/**
* Class Tainacan_Taxonomies
*/
@ -15,30 +17,54 @@ class Taxonomies extends Repository {
return apply_filters('tainacan-get-map', [
'id' => [
'map' => 'ID',
'title' => __('ID', 'tainacan'),
'type' => 'integer',
'description'=> __('Unique identifier', 'tainacan'),
//'validation' => ''
],
'name' => [
'map' => 'post_title',
'validation' => ''
'title' => __('Name', 'tainacan'),
'type' => 'string',
'description'=> __('Name of the taxonomy', 'tainacan'),
'on_error' => __('The taxonomy should be a text value and not empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
'parent' => [
'map' => 'parent',
'title' => __('Parent', 'tainacan'),
'type' => 'integer',
'description'=> __('Parent taxonomy', 'tainacan'),
'validation' => ''
],
'description' => [
'map' => 'post_content',
'title' => __('Description', 'tainacan'),
'type' => 'string',
'description'=> __('The taxonomy description', 'tainacan'),
'validation' => ''
],
'slug' => [
'map' => 'post_name',
'title' => __('Slug', 'tainacan'),
'type' => 'string',
'description'=> __('The taxonomy slug', 'tainacan'),
'validation' => ''
],
'allow_insert' => [
'map' => 'meta',
'validation' => ''
'title' => __('Allow insert', 'tainacan'),
'type' => 'string',
'description'=> __('Allow/Deny the creation of new terms in the taxonomy', 'tainacan'),
'on_error' => __('Allow insert is invalid, allowed values ( yes/no )', 'tainacan'),
'validation' => v::stringType()->in(['yes', 'no']), // yes or no
'default' => 'yes'
],
'collections_ids' => [
'map' => 'meta_multi',
'title' => __('Collections', 'tainacan'),
'type' => 'string',
'description'=> __('The IDs of collection where the taxonomy is used', 'tainacan'),
'validation' => ''
],
]);

View File

@ -5,6 +5,7 @@ use Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use \Respect\Validation\Validator as v;
/**
* Class Tainacan_Terms
*/
@ -15,27 +16,48 @@ class Terms extends Repository {
return apply_filters('tainacan-get-map', [
'term_id' => [
'map' => 'term_id',
'title' => __('ID', 'tainacan'),
'type' => 'integer',
'description'=> __('Unique identifier', 'tainacan'),
//'validation' => ''
],
'name' => [
'map' => 'name',
'validation' => ''
'title' => __('Name', 'tainacan'),
'type' => 'string',
'description'=> __('Name of the term', 'tainacan'),
'on_error' => __('The name is empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
'parent' => [
'map' => 'parent',
'title' => __('Parent', 'tainacan'),
'type' => 'integer',
'description'=> __('The parent of the term', 'tainacan'),
'validation' => ''
],
'description' => [
'map' => 'description',
'title' => __('Description', 'tainacan'),
'type' => 'string',
'description'=> __('The term description', 'tainacan'),
'validation' => ''
],
'taxonomy' => [
'map' => 'taxonomy',
'validation' => ''
'title' => __('Taxonomy', 'tainacan'),
'type' => 'string',
'description'=> __('The term taxonomy', 'tainacan'),
'on_error' => __('The taxonomy is empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
'user' => [
'map' => 'termmeta',
'validation' => ''
'title' => __('User', 'tainacan'),
'type' => 'integer',
'description'=> __('The term creator', 'tainacan'),
'on_error' => __('The user is empty or invalid', 'tainacan'),
'validation' => v::numeric()->positive(),
],
]);
}

View File

@ -25,10 +25,11 @@ class Taxonomies extends \WP_UnitTestCase {
//setando os valores na classe do tainacan
$taxonomy->set_name('genero');
$taxonomy->set_description('tipos de musica');
$taxonomy->set_allow_insert(true);
$taxonomy->set_allow_insert('yes');
//inserindo
$taxonomy->validate();
$taxonomy = $Tainacan_Taxonomies->insert($taxonomy);
//retorna a taxonomia
@ -36,7 +37,7 @@ class Taxonomies extends \WP_UnitTestCase {
$this->assertEquals( $test->get_name(), 'genero' );
$this->assertEquals( $test->get_description(), 'tipos de musica' );
$this->assertEquals( $test->get_allow_insert(), true );
$this->assertEquals( $test->get_allow_insert(), 'yes' );
$this->assertEquals( taxonomy_exists( $test->get_db_identifier() ) , true );
}