diff --git a/README.md b/README.md index f80f2d39a..b6f4db0fc 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Na pasta `src` temos os arquivos normais de um plugin de WP. Essa será a pasta Aí dentro podem haver arquivos sass e js que ainda serão compilados no build. -Na pasta `tests` temos a suíte de testes e as ferramentas para configurá-la. Já tem uns primeiros testes lá de exemplo que testa a classe `TainacanCollections`. +Na pasta `tests` temos a suíte de testes e as ferramentas para configurá-la. Já tem uns primeiros testes lá de exemplo que testa a classe `Tainacan_Collections`. Na raíz temos alguns scripts importantes: diff --git a/src/classes/Entities/Collection.php b/src/classes/Entities/Collection.php deleted file mode 100644 index 4128b752d..000000000 --- a/src/classes/Entities/Collection.php +++ /dev/null @@ -1,135 +0,0 @@ -repository = 'TainacanCollections'; - - if (is_numeric($which) && $which > 0) { - $post = get_post($which); - if ($post instanceof WP_Post) { - $this->WP_Post = get_post($which); - } - - } elseif ($which instanceof WP_Post) { - $this->WP_Post = $which; - } else { - $this->WP_Post = new StdClass(); - } - - } - - function register_post_type() { - $cpt_labels = array( - 'name' => 'Item', - 'singular_name' => 'Item', - 'add_new' => 'Adicionar Novo', - 'add_new_item' =>'Adicionar Item', - 'edit_item' => 'Editar', - 'new_item' => 'Novo Item', - 'view_item' => 'Visualizar', - 'search_items' => 'Pesquisar', - 'not_found' => 'Nenhum Item encontrado', - 'not_found_in_trash' => 'Nenhum Item encontrado na lixeira', - 'parent_item_colon' => 'Item acima:', - 'menu_name' => $this->get_name() - ); - - $cpt_slug = $this->get_db_identifier(); - - $args = array( - 'labels' => $cpt_labels, - 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), - 'public' => true, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, - 'publicly_queryable' => true, - 'exclude_from_search' => true, - 'has_archive' => true, - 'query_var' => true, - 'can_export' => true, - 'rewrite' => [ - 'slug' => $this->get_slug() - ], - 'capability_type' => 'post', - ); - - if (post_type_exists($this->get_db_identifier())) - unregister_post_type($this->get_db_identifier()); - - register_post_type($cpt_slug, $args); - } - - // Getters - // - function get_id() { - return $this->get_mapped_property('ID'); - } - function get_name() { - return $this->get_mapped_property('name'); - } - function get_slug() { - return $this->get_mapped_property('slug'); - } - function get_order() { - return $this->get_mapped_property('order'); - } - function get_parent() { - return $this->get_mapped_property('parent'); - } - function get_description() { - return $this->get_mapped_property('description'); - } - function get_itens_per_page() { - return $this->get_mapped_property('itens_per_page'); - } - - // special Getters - // - - function get_db_identifier() { - return $this->get_id() ? 'tnc_col_' . $this->get_id() : false; - } - - // metadata - function get_metadata() { - global $Tainacan_Metadatas; - return $Tainacan_Metadatas->get_metadata_by_collection($this); - } - - // Setters - // - - function set_name($value) { - return $this->set_mapped_property('name', $value); - } - function set_slug($value) { - return $this->set_mapped_property('slug', $value); - } - function set_order($value) { - return $this->set_mapped_property('order', $value); - } - function set_parent($value) { - return $this->set_mapped_property('parent', $value); - } - function set_description($value) { - return $this->set_mapped_property('description', $value); - } - function set_itens_per_page($value) { - return $this->set_mapped_property('itens_per_page', $value); - } - -} \ No newline at end of file diff --git a/src/classes/Entities/Item.php b/src/classes/Entities/Item.php deleted file mode 100644 index ac7eac1f0..000000000 --- a/src/classes/Entities/Item.php +++ /dev/null @@ -1,103 +0,0 @@ -repository = 'TainacanItems'; - - if (is_numeric($which) && $which > 0) { - $post = get_post($which); - if ($post instanceof WP_Post) { - $this->WP_Post = get_post($which); - } - - } elseif ($which instanceof WP_Post) { - $this->WP_Post = $which; - } else { - $this->WP_Post = new StdClass(); - } - - } - - // Getters - // - function get_id() { - return $this->get_mapped_property('ID'); - } - function get_title() { - return $this->get_mapped_property('title'); - } - function get_order() { - return $this->get_mapped_property('order'); - } - function get_parent() { - return $this->get_mapped_property('parent'); - } - function get_description() { - return $this->get_mapped_property('description'); - } - - - - - // Setters - // - - function set_title($value) { - return $this->set_mapped_property('title', $value); - } - function set_order($value) { - return $this->set_mapped_property('order', $value); - } - function set_parent($value) { - return $this->set_mapped_property('parent', $value); - } - function set_description($value) { - return $this->set_mapped_property('description', $value); - } - - - // Metadata - - function get_metadata() { - if (isset($this->metadata)) - return $this->metadata; - - $collection = $this->get_collection(); - $return = []; - if ($collection) { - $metaList = $collection->get_metadata(); - - foreach ($metaList as $meta) { - $return[$meta->get_id()] = new Tainacan_Item_Metadata_Entity($this, $meta); - } - } - return $return; - } - - function add_metadata(Tainacan_Metadata $new_metadata, $value) { - - //TODO Multiple metadata must receive an array as value - - $item_metadata = new Tainacan_Item_Metadata_Entity($this, $new_metadata); - $item_metadata->set_value($value); - $current_meta = $this->get_metadata(); - $current_meta[$new_metadata->get_id()] = $item_metadata; - $this->set_metadata($current_meta); - } - - function set_metadata(Array $metadata) { - $this->metadata = $metadata; - } - -} \ No newline at end of file diff --git a/src/classes/Entities/Item_Metadata_Entity.php b/src/classes/Entities/Item_Metadata_Entity.php deleted file mode 100644 index 776cc77b4..000000000 --- a/src/classes/Entities/Item_Metadata_Entity.php +++ /dev/null @@ -1,144 +0,0 @@ -repository = 'Tainacan_Item_Metadata'; - - $this->set_item($item); - $this->set_metadata($metadata); - - } - - function set_item(TainacanItem $item) { - $this->item = $item; - } - - function set_value($value) { - $this->value = $value; - } - - function set_metadata(Tainacan_Metadata $metadata) { - $this->metadata = $metadata; - } - - function get_item() { - return $this->item; - } - - function get_metadata() { - return $this->metadata; - } - - function get_value() { - - if (isset($this->value)) - return $this->value; - - global $Tainacan_Item_Metadata; - return $Tainacan_Item_Metadata->get_item_metadata_value($this); - } - - - ////////////////// - - function is_multiple() { - return $this->get_metadata()->is_multiple(); - } - - function is_collection_key() { - return $this->get_metadata()->is_collection_key(); - } - - function is_required() { - return $this->get_metadata()->is_required(); - } - - function validate() { - - $value = $this->get_value(); - $metadata = $this->get_metadata(); - $item = $this->get_item(); - - if (empty($value) && $this->is_required()) { - $this->add_error('required', $metadata->get_name() . ' is required'); - return false; - } - - if ($this->is_multiple()) { - - if (is_array($value)) { - - // if its required, at least one must be filled - $one_filled = false; - $valid = true; - foreach($value as $val) { - if (!empty($val)) - $one_filled = true; - - // TODO: call fieldtype validation - // if (invalid) $valid = false; - - } - - if ($this->is_required() && !$one_filled) { - $this->add_error('required', $metadata->get_name() . ' is required'); - return false; - } - - if (!$valid) { - $this->add_error('invalid', $metadata->get_name() . ' is invalid'); - return false; - } - - $this->reset_errors(); - return true; - - - } else { - $this->add_error('invalid', $metadata->get_name() . ' is invalid'); - return false; - } - - - } else { - - if ($this->is_collection_key()) { - global $TainacanItems; - $test = $TainacanItems->query([ - 'collections' => $item->get_collection(), - 'metadata' => [ - [ - 'key' => $this->metadata->get_id(), - 'value' => $value - ] - ] - ]); - - if (!empty($test)) { - $this->add_error('key_exists', $metadata->get_name() . ' is a collection key and there is another item with the same value'); - return false; - } - } - - // TODO: call fieldType validation - // - $this->reset_errors(); - return true; - - } - - } - - - -} \ No newline at end of file diff --git a/src/classes/Entities/Metadata.php b/src/classes/Entities/Metadata.php deleted file mode 100644 index b25aed37c..000000000 --- a/src/classes/Entities/Metadata.php +++ /dev/null @@ -1,170 +0,0 @@ -repository = 'Tainacan_Metadatas'; - - if ( is_numeric( $which ) && $which > 0) { - $post = get_post( $which ); - if ( $post instanceof WP_Post) { - $this->WP_Post = get_post( $which ); - } - - } elseif ( $which instanceof WP_Post ) { - $this->WP_Post = $which; - } else { - $this->WP_Post = new StdClass(); - } - - } - - - // Getters - - function get_id() { - return $this->get_mapped_property('ID'); - } - - - function get_name() { - return $this->get_mapped_property('name'); - } - - - function get_order() { - return $this->get_mapped_property('order'); - } - - - function get_parent() { - return $this->get_mapped_property('parent'); - } - - - function get_description() { - return $this->get_mapped_property('description'); - } - - - function get_required(){ - return $this->get_mapped_property('required'); - } - - function get_multiple(){ - return $this->get_mapped_property('multiple'); - } - - function get_cardinality(){ - return $this->get_mapped_property('cardinality'); - } - - function get_collection_key(){ - return $this->get_mapped_property('collection_key'); - } - - function get_mask(){ - return $this->get_mapped_property('mask'); - } - - function get_privacy(){ - return $this->get_mapped_property('privacy'); - } - - function get_default_value(){ - 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'); - } - } - - - // Setters - - - function set_name($value) { - return $this->set_mapped_property('name', $value); - } - - function set_order($value) { - return $this->set_mapped_property('order', $value); - } - - - function set_parent($value) { - return $this->set_mapped_property('parent', $value); - } - - - function set_description($value) { - return $this->set_mapped_property('description', $value); - } - - - function set_required( $value ){ - return $this->set_mapped_property('required', $value); - } - - function set_multiple( $value ){ - return $this->set_mapped_property('multiple', $value); - } - - function set_cardinality( $value ){ - return $this->set_mapped_property('cardinality', $value); - } - - function set_collection_key( $value ){ - return $this->set_mapped_property('collection_key', $value); - } - - function set_mask( $value ){ - return $this->set_mapped_property('mask', $value); - } - - function set_privacy( $value ){ - return $this->set_mapped_property('privacy', $value); - } - - function set_default_value( $value ){ - 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_option($value){ - return $this->set_mapped_property('option', serialize($value) ) ; - } - - - // helpers - - function is_multiple() { - return $this->get_multiple() === 'yes'; - } - - function is_collection_key() { - return $this->get_collection_key() === 'yes'; - } - - function is_required() { - return $this->get_required() === 'yes'; - } - -} \ No newline at end of file diff --git a/src/classes/Entities/Taxonomy.php b/src/classes/Entities/Taxonomy.php deleted file mode 100644 index 6c06fb4b6..000000000 --- a/src/classes/Entities/Taxonomy.php +++ /dev/null @@ -1,131 +0,0 @@ -repository = 'Tainacan_Taxonomies'; - - if ( is_numeric( $which ) && $which > 0) { - $post = get_post( $which ); - if ( $post instanceof WP_Post) { - $this->WP_Post = get_post( $which ); - } - - } elseif ( $which instanceof WP_Post ) { - $this->WP_Post = $which; - } else { - $this->WP_Post = new StdClass(); - } - - } - - function register_taxonomy() { - $labels = array( - 'name' => $this->get_name(), - 'singular_name' => __( 'Taxonomy','textdomain' ), - 'search_items' => __( 'Search taxonomies', 'textdomain' ), - 'all_items' => __( 'All taxonomies', 'textdomain' ), - 'parent_item' => __( 'Parent taxonomy', 'textdomain' ), - 'parent_item_colon' => __( 'Parent taxonomy:', 'textdomain' ), - 'edit_item' => __( 'Edit taxonomy', 'textdomain' ), - 'update_item' => __( 'Update taxonomy', 'textdomain' ), - 'add_new_item' => __( 'Add New taxonomy', 'textdomain' ), - 'new_item_name' => __( 'New Genre taxonomy', 'textdomain' ), - 'menu_name' => __( 'Genre', 'textdomain' ), - ); - - $args = array( - 'hierarchical' => true, - 'labels' => $labels, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_admin_column' => tnc_enable_dev_wp_interface(), - 'rewrite' => [ - 'slug' => $this->get_slug() - ], - ); - - - $tax_cpts = []; - if (is_array($this->get_collections())) - foreach ($this->get_collections() as $tax_col) - $tax_cpts[] = $tax_col->get_db_identifier(); - - if (taxonomy_exists($this->get_db_identifier())) - unregister_taxonomy($this->get_db_identifier()); - - register_taxonomy( - $this->get_db_identifier(), - $tax_cpts, - $args - ); - - return true; - } - - // Getters - - function get_id() { - return $this->get_mapped_property('ID'); - } - - - function get_name() { - return $this->get_mapped_property('name'); - } - - function get_parent() { - return $this->get_mapped_property('parent'); - } - - - function get_description() { - return $this->get_mapped_property('description'); - } - - function get_allow_insert() { - return ( boolean ) $this->get_mapped_property('allow_insert'); - } - - function get_slug() { - return $this->get_mapped_property('slug'); - } - - // special Getters - // - - function get_db_identifier() { - return $this->get_id() ? 'tnc_tax_' . $this->get_id() : false; - } - - - // Setters - - - function set_name($value) { - return $this->set_mapped_property('name', $value); - } - - function set_parent($value) { - return $this->set_mapped_property('parent', $value); - } - - function set_slug($value) { - return $this->set_mapped_property('slug', $value); - } - - - function set_description($value) { - return $this->set_mapped_property('description', $value); - } - - function set_allow_insert($value) { - return $this->set_mapped_property('allow_insert', $value); - } - -} \ No newline at end of file diff --git a/src/classes/Entities/Term.php b/src/classes/Entities/Term.php deleted file mode 100644 index e30642155..000000000 --- a/src/classes/Entities/Term.php +++ /dev/null @@ -1,78 +0,0 @@ -repository = 'Tainacan_Terms'; - $this->set_taxonomy( $taxonomy ); - - if ( is_numeric( $which ) && $which > 0) { - $post = get_term_by('id', $which, $taxonomy); - if ( $post instanceof WP_Term) { - $this->WP_Term = get_term_by('id', $which, $taxonomy); - } - - } elseif ( $which instanceof WP_Term ) { - $this->WP_Term = $which; - } else { - $this->WP_Term = new StdClass(); - } - - } - - // Getters - - function get_id() { - return $this->get_mapped_property('term_id'); - } - - - function get_name() { - return $this->get_mapped_property('name'); - } - - function get_parent() { - return $this->get_mapped_property('parent'); - } - - - function get_description() { - return $this->get_mapped_property('description'); - } - - function get_user() { - return $this->get_mapped_property('user'); - } - - function get_taxonomy() { - return $this->get_mapped_property('taxonomy'); - } - - // Setters - - - function set_name($value) { - return $this->set_mapped_property('name', $value); - } - - function set_parent($value) { - return $this->set_mapped_property('parent', $value); - } - - - function set_description($value) { - return $this->set_mapped_property('description', $value); - } - - function set_user($value) { - return $this->set_mapped_property('user', $value); - } - - function set_taxonomy($value) { - return $this->set_mapped_property('taxonomy', $value); - } -} diff --git a/src/classes/Entity.php b/src/classes/Entity.php deleted file mode 100644 index 8b97006f3..000000000 --- a/src/classes/Entity.php +++ /dev/null @@ -1,76 +0,0 @@ -repository}; - $map = ${$this->repository}->map; - - if (isset($this->$prop) && !empty($this->$prop)) - return $this->$prop; - - - if (!array_key_exists($prop, $map)) - return null; - - $mapped = $map[$prop]['map']; - - if ( $mapped == 'meta') { - $return = get_post_meta($this->WP_Post->ID, $prop, true); - }elseif ( $mapped == 'meta_multi') { - $return = get_post_meta($this->WP_Post->ID, $prop, false); - }elseif ( $mapped == 'termmeta' ){ - $return = get_term_meta($this->WP_Term->term_id, $prop, true); - }elseif ( isset( $this->WP_Post )) { - $return = isset($this->WP_Post->$mapped) ? $this->WP_Post->$mapped : null; - } elseif ( isset( $this->WP_Term )) { - $return = isset($this->WP_Term->$mapped) ? $this->WP_Term->$mapped : null; - } - - if (empty($return) && isset($map[$prop]['default']) && !empty($map[$prop]['default'])) - $return = $map[$prop]['default']; - - return $return; - } - - function set_mapped_property($prop, $value) { - - - $this->$prop = $value; - - - } - - function save() { - - // validate - - global ${$this->repository}; - - return ${$this->repository}->insert($this); - - - } - - function validate() { - return true; - } - - function get_errors() { - return $this->errors; - } - - function add_error($type, $message) { - $this->errors[] = [$type => $message]; - } - - function reset_errors() { - $this->errors = []; - } - -} \ No newline at end of file diff --git a/src/classes/FieldTypes/FieldType.php b/src/classes/FieldTypes/FieldType.php deleted file mode 100644 index 4f91de2e0..000000000 --- a/src/classes/FieldTypes/FieldType.php +++ /dev/null @@ -1,20 +0,0 @@ -get_name().'">'; - } -} \ No newline at end of file diff --git a/src/classes/Repositories/Collections.php b/src/classes/Repositories/Collections.php deleted file mode 100644 index f5a005018..000000000 --- a/src/classes/Repositories/Collections.php +++ /dev/null @@ -1,150 +0,0 @@ - [ - 'map' => 'ID', - 'validation' => '' - ], - 'name' => [ - 'map' => 'post_title', - 'validation' => '' - ], - 'order' => [ - 'map' => 'menu_order', - 'validation' => '' - ], - 'parent' => [ - 'map' => 'parent', - 'validation' => '' - ], - 'description' => [ - 'map' => 'post_content', - 'validation' => '' - ], - 'slug' => [ - 'map' => 'post_name', - 'validation' => '' - ], - 'itens_per_page' => [ - 'map' => 'meta', - 'validation' => '' - ], - ]; - - function __construct() { - add_action('init', array(&$this, 'register_post_type')); - } - - function register_post_type() { - $labels = array( - 'name' => 'Collections', - 'singular_name' => 'Collections', - 'add_new' => 'Adicionar Novo', - 'add_new_item' =>'Adicionar Collections', - 'edit_item' => 'Editar', - 'new_item' => 'Novo Collections', - 'view_item' => 'Visualizar', - 'search_items' => 'Pesquisar', - 'not_found' => 'Nenhum ticket encontrado', - 'not_found_in_trash' => 'Nenhum Collections encontrado na lixeira', - 'parent_item_colon' => 'Collections acima:', - 'menu_name' => 'Collections' - ); - $args = array( - 'labels' => $labels, - 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), - 'public' => true, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, - 'publicly_queryable' => true, - 'exclude_from_search' => true, - 'has_archive' => true, - 'query_var' => true, - 'can_export' => true, - 'rewrite' => true, - 'capability_type' => 'post', - ); - register_post_type(self::POST_TYPE, $args); - } - - function insert(TainacanCollection $collection) { - // First iterate through the native post properties - $map = $this->map; - foreach ($map as $prop => $mapped) { - if ($mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi') { - $collection->WP_Post->{$mapped['map']} = $collection->get_mapped_property($prop); - } - } - - // save post and geet its ID - $collection->WP_Post->post_type = self::POST_TYPE; - $collection->WP_Post->post_status = 'publish'; - - // TODO verificar se salvou mesmo - $id = wp_insert_post($collection->WP_Post); - - // reset object - $collection->WP_Post = get_post($id); - - // Now run through properties stored as postmeta - foreach ($map as $prop => $mapped) { - if ($mapped['map'] == 'meta') { - update_post_meta($id, $prop, $collection->get_mapped_property($prop)); - } elseif ($mapped['map'] == 'meta_multi') { - $values = $collection->get_mapped_property($prop); - delete_post_meta($id, $prop); - if (is_array($values)) - foreach ($values as $value) - add_post_meta($id, $prop, $value); - } - } - - $collection->register_post_type(); - - // return a brand new object - return new TainacanCollection($collection->WP_Post); - } - - function get_collections($args = array()) { - - $args = array_merge([ - 'post_type' => self::POST_TYPE, - 'posts_per_page' => -1, - 'post_status' => 'publish', - ], $args); - - $posts = get_posts($args); - - $return = []; - - foreach ($posts as $post) { - $return[] = new TainacanCollection($post); - } - - // TODO: Pegar coleções registradas via código - - return $return; - } - - function get_collection_by_id($id) { - return new TainacanCollection($id); - } - - -} - -global $TainacanCollections; -$TainacanCollections = new TainacanCollections(); \ No newline at end of file diff --git a/src/classes/Repositories/ItemMetadata.php b/src/classes/Repositories/ItemMetadata.php deleted file mode 100644 index cc63aa71a..000000000 --- a/src/classes/Repositories/ItemMetadata.php +++ /dev/null @@ -1,61 +0,0 @@ -get_collection(); - - if (!$collection instanceof TainacanCollection) - return []; - - $meta_list = $Tainacan_Metadatas->get_metadata_by_collection($collection); - - $return = []; - - if (is_array($meta_list)) { - foreach ($meta_list as $meta) { - $return = new Tainacan_Item_Metadata_Entity($item, $meta); - } - } - - return $return; - - } - - function insert(Tainacan_Item_Metadata_Entity $item_metadata) { - - $unique = ! $item_metadata->is_multiple(); - - if ($unique) { - update_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), $item_metadata->get_value()); - } else { - delete_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id()); - if (is_array($item_metadata->get_value())) - foreach ($item_metadata->get_value() as $value) - add_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), $value); - } - - // return a brand new object - return new Tainacan_Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_metadata()); - - } - - function get_item_metadata_value(Tainacan_Item_Metadata_Entity $item_metadata) { - - $unique = ! $item_metadata->is_multiple(); - - return get_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), $unique); - - } - -} - -global $Tainacan_Item_Metadata; -$Tainacan_Item_Metadata = new Tainacan_Item_Metadata(); \ No newline at end of file diff --git a/src/classes/Repositories/Items.php b/src/classes/Repositories/Items.php deleted file mode 100644 index d547160e5..000000000 --- a/src/classes/Repositories/Items.php +++ /dev/null @@ -1,221 +0,0 @@ - [ - 'map' => 'ID', - 'validation' => '' - ], - 'title' => [ - 'map' => 'post_title', - 'validation' => '' - ], - 'description' => [ - 'map' => 'post_content', - 'validation' => '' - ], - 'collection_id' => [ - 'map' => 'meta', - 'validation' => '' - ], - //'collection' => 'relation...', - // metadata .. metadata... - ]; - - function __construct() { - add_action('init', array(&$this, 'register_post_types')); - } - - function register_post_types() { - - global $TainacanCollections, $Tainacan_Taxonomies; - - $collections = $TainacanCollections->get_collections(); - $taxonomies = $Tainacan_Taxonomies->get_taxonomies(); - - if (!is_array($collections)) - return; - - - - - - // register collections post type and associate taxonomies - foreach ($collections as $collection) { - - $collection->register_post_type(); - - } - - - // register taxonomies - foreach ($taxonomies as $taxonomy) { - $taxonomy->register_taxonomy(); - } - - - } - - - - function insert(TainacanItem $item) { - - - $map = $this->map; - - // get collection to determine post type - $collection = $item->get_collection(); - - if (!$collection) - return false; - - $cpt = $collection->get_db_identifier(); - - // iterate through the native post properties - foreach ($map as $prop => $mapped) { - if ($mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi') { - $item->WP_Post->{$mapped['map']} = $item->get_mapped_property($prop); - } - } - - // save post and geet its ID - $item->WP_Post->post_type = $cpt; - $item->WP_Post->post_status = 'publish'; - $id = wp_insert_post($item->WP_Post); - $item->WP_Post = get_post($id); - - // Now run through properties stored as postmeta - foreach ($map as $prop => $mapped) { - if ($mapped['map'] == 'meta') { - update_post_meta($id, $prop, $item->get_mapped_property($prop)); - } elseif ($mapped['map'] == 'meta_multi') { - $values = $item->get_mapped_property($prop); - delete_post_meta($id, $prop); - if (is_array($values)) - foreach ($values as $value) - add_post_meta($id, $prop, $value); - } - } - - // save metadata - $metadata = $item->get_metadata(); - global $Tainacan_Item_Metadata; - foreach ($metadata as $meta) { - $Tainacan_Item_Metadata->insert($meta); - } - - // return a brand new object - return new TainacanItem($item->WP_Post); - } - - // collections id or array of ids; collection object or array of objects - function get_items($args = array(), $collections = []) { - - global $TainacanCollections; - - if (empty($collections)) { - $collections = $TainacanCollections->get_collections(); - } - - if (is_numeric($collections)) - $collections = $TainacanCollections->get_collection_by_id($collection); - - if ($collections instanceof TainacanCollection) { - $cpt = $collections->get_db_identifier(); - } elseif (is_array($collections)) { - $cpt = []; - - foreach ($collections as $collection) { - if (is_numeric($collection)) - $collection = $TainacanCollections->get_collection_by_id($collection); - - if ($collection instanceof TainacanCollection) - $cpt[] = $collection->get_db_identifier(); - } - - } else { - return []; - } - - if (empty($cpt)) - return []; - - $args = array_merge([ - 'post_type' => $cpt, - 'posts_per_page' => -1, - 'post_status' => 'publish', - ], $args); - - $posts = get_posts($args); - - $return = []; - - foreach ($posts as $post) { - $return[] = new TainacanItem($post); - } - - return $return; - } - - // same as WP_Query with few paramaters more: - // collections ID or array of IDs, object or array of objects - // metadata - array of metadata in meta_query format - // other item properties, present in the "map" - function query($args) { - - $map = $this->map; - $wp_query_exceptions = [ - 'ID' => 'p', - 'post_title' => 'title' - ]; - - $meta_query = []; - - foreach ($map as $prop => $mapped) { - if (array_key_exists($prop, $args)) { - $prop_value = $args[$prop]; - unset($args[$prop]); - if ( $mapped['map'] == 'meta' || $mapped['map'] == 'meta_multi' ) { - $meta_query[] = [ - 'key' => $prop, - 'value' => $prop_value - ]; - } else { - $prop_search_name = array_key_exists($mapped['map'], $wp_query_exceptions) ? $wp_query_exceptions[$mapped['map']] : $mapped['map']; - $args[$prop_search_name] = $prop_value; - } - - } - } - - if ( isset($args['metadata']) && is_array($args['metadata']) && !empty($args['metadata'])) { - $meta_query = array_merge($args['metadata'],$meta_query); - } - - $args['meta_query'] = $meta_query; - - unset($args['metadata']); - - $collections = !empty($args['collections']) ? $args['collections'] : []; - unset($args['collections']); - - return $this->get_items($args, $collections); - ### TODO I think its better if we return a WP_Query object. easier for loop and debugging - - } - - function get_item_by_id($id) { - return new TainacanItem($id); - } - - -} - -global $TainacanItems; -$TainacanItems = new TainacanItems(); \ No newline at end of file diff --git a/src/classes/Repositories/Metatadas.php b/src/classes/Repositories/Metatadas.php deleted file mode 100644 index 8c305d05c..000000000 --- a/src/classes/Repositories/Metatadas.php +++ /dev/null @@ -1,198 +0,0 @@ - [ - 'map' => 'ID', - 'validation' => '' - ], - 'name' => [ - 'map' => 'post_title', - 'validation' => '' - ], - 'order' => [ - 'map' => 'menu_order', - 'validation' => '' - ], - 'parent' => [ - 'map' => 'parent', - 'validation' => '' - ], - 'description' => [ - 'map' => 'post_content', - 'validation' => '' - ], - 'type' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'required' => [ - 'map' => 'meta', - 'validation' => '', // yes or no - 'default' => 'no' - ], - 'collection_key' => [ - 'map' => 'meta', - 'validation' => '', // yes or no. it cant be key if its multiple - 'default' => 'no' - ], - 'multiple' => [ - 'map' => 'meta', - 'validation' => '', // yes or no. It cant be multiple if its collection_key - 'default' => 'no' - ], - 'cardinality' => [ - 'map' => 'meta', - 'validation' => '', - 'default' => 1 - ], - 'privacy' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'mask' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'default_value' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'option' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'collection_id' => [ - 'map' => 'meta', - 'validation' => '' - ], - ]; - - function __construct() { - add_action('init', array(&$this, 'register_post_type')); - } - - function register_post_type() { - $labels = array( - 'name' => 'Metadata', - 'singular_name' => 'Metadata', - 'add_new' => 'Adicionar Metadata', - 'add_new_item' =>'Adicionar Metadata', - 'edit_item' => 'Editar', - 'new_item' => 'Novo Metadata', - 'view_item' => 'Visualizar', - 'search_items' => 'Pesquisar', - 'not_found' => 'Nenhum ticket encontrado', - 'not_found_in_trash' => 'Nenhum Collections encontrado na lixeira', - 'parent_item_colon' => 'Metadata acima:', - 'menu_name' => 'Metadata' - ); - - $args = array( - 'labels' => $labels, - 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), - 'public' => true, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, - 'publicly_queryable' => true, - 'exclude_from_search' => true, - 'has_archive' => true, - 'query_var' => true, - 'can_export' => true, - 'rewrite' => true, - 'capability_type' => 'post', - ); - register_post_type(self::POST_TYPE, $args); - } - - /** - * @param Tainacan_Metadata $metadata - * @return int - */ - function insert( Tainacan_Metadata $metadata ) { - // First iterate through the native post properties - $map = $this->map; - foreach ($map as $prop => $mapped) { - if ($mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi') { - $metadata->WP_Post->{$mapped['map']} = $metadata->get_mapped_property($prop); - } - } - - // save post and get its ID - $metadata->WP_Post->post_type = self::POST_TYPE; - $metadata->WP_Post->post_status = 'publish'; - $id = wp_insert_post($metadata->WP_Post); - $metadata->WP_Post = get_post($id); - - // Now run through properties stored as postmeta - foreach ($map as $prop => $mapped) { - if ($mapped['map'] == 'meta') { - update_post_meta($id, $prop, $metadata->get_mapped_property($prop)); - } elseif ($mapped['map'] == 'meta_multi') { - $values = $metadata->get_mapped_property($prop); - delete_post_meta($id, $prop); - if (is_array($values)) - foreach ($values as $value) - add_post_meta($id, $prop, $value); - } - } - - // return a brand new object - return new Tainacan_Metadata($metadata->WP_Post); - } - - /** - * @param ( TainacanCollection ) $collection_id - * @param array $args - * @return array - */ - function get_metadata_by_collection( $collection, $args = array()) { - - // TODO: get metadata from parent collections - - $collection_id = ( is_object( $collection ) ) ? $collection->get_id() : $collection; - - $args = array_merge([ - 'post_type' => self::POST_TYPE, - 'posts_per_page' => -1, - 'post_status' => 'publish', - 'meta_key' => 'collection_id', - 'meta_value' => $collection_id - ], $args); - - $posts = get_posts($args); - - $return = []; - - foreach ($posts as $post) { - $return[] = new Tainacan_Metadata($post); - } - - return $return; - } - - - /** - * @param int $id - * @return Tainacan_Metadata - */ - function get_metadata_by_id($id) { - return new Tainacan_Metadata($id); - } -} - -global $Tainacan_Metadatas; -$Tainacan_Metadatas = new Tainacan_Metadatas(); \ No newline at end of file diff --git a/src/classes/Repositories/Taxonomies.php b/src/classes/Repositories/Taxonomies.php deleted file mode 100644 index cf32df697..000000000 --- a/src/classes/Repositories/Taxonomies.php +++ /dev/null @@ -1,176 +0,0 @@ - [ - 'map' => 'ID', - 'validation' => '' - ], - 'name' => [ - 'map' => 'post_title', - 'validation' => '' - ], - 'parent' => [ - 'map' => 'parent', - 'validation' => '' - ], - 'description' => [ - 'map' => 'post_content', - 'validation' => '' - ], - 'slug' => [ - 'map' => 'post_name', - 'validation' => '' - ], - 'allow_insert' => [ - 'map' => 'meta', - 'validation' => '' - ], - 'collections_ids' => [ - 'map' => 'meta_multi', - 'validation' => '' - ], - ]; - - - function __construct() { - add_action('init', array(&$this, 'register_post_type')); - } - - function register_post_type() { - $labels = array( - 'name' => 'Taxonomy', - 'singular_name' => 'Taxonomy', - 'add_new' => 'Adicionar Taxonomy', - 'add_new_item' =>'Adicionar Taxonomy', - 'edit_item' => 'Editar', - 'new_item' => 'Novo Taxonomy', - 'view_item' => 'Visualizar', - 'search_items' => 'Pesquisar', - 'not_found' => 'Nenhum ticket encontrado', - 'not_found_in_trash' => 'Nenhum Taxonomy encontrado na lixeira', - 'parent_item_colon' => 'Taxonomy acima:', - 'menu_name' => 'Taxonomy' - ); - - $args = array( - 'labels' => $labels, - 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), - 'public' => true, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, - 'publicly_queryable' => false, - 'exclude_from_search' => true, - 'has_archive' => false, - 'query_var' => true, - 'can_export' => true, - 'rewrite' => true, - 'capability_type' => 'post', - ); - register_post_type(self::POST_TYPE, $args); - } - - function get_taxonomies($args = []){ - $args = array_merge([ - 'post_type' => self::POST_TYPE, - 'posts_per_page' => -1, - 'post_status' => 'publish', - ], $args); - - $posts = get_posts($args); - - $return = []; - - foreach ($posts as $post) { - $return[] = new Tainacan_Taxonomy($post); - } - - // TODO: Pegar taxonomias registradas via código - - return $return; - } - - - /** - * @param Tainacan_Taxonomy $metadata - * @return int - */ - function insert( Tainacan_Taxonomy $taxonomy ) { - // First iterate through the native post properties - $map = $this->map; - foreach ($map as $prop => $mapped) { - if ($mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi') { - $taxonomy->WP_Post->{$mapped['map']} = $taxonomy->get_mapped_property($prop); - } - } - - // save post and get its ID - $taxonomy->WP_Post->post_type = self::POST_TYPE; - $taxonomy->WP_Post->post_status = 'publish'; - $id = wp_insert_post($taxonomy->WP_Post); - $taxonomy->WP_Post = get_post($id); - - // Now run through properties stored as postmeta - foreach ($map as $prop => $mapped) { - if ($mapped['map'] == 'meta') { - update_post_meta($id, $prop, $taxonomy->get_mapped_property($prop)); - } elseif ($mapped['map'] == 'meta_multi') { - $values = $taxonomy->get_mapped_property($prop); - delete_post_meta($id, $prop); - if (is_array($values)) - foreach ($values as $value) - add_post_meta($id, $prop, $value); - } - } - - $taxonomy->register_taxonomy(); - - // return a brand new object - return new Tainacan_Taxonomy($taxonomy->WP_Post); - } - - function registerTainacanTaxonomy( $taxonomy_name ){ - $labels = array( - 'name' => __( 'Taxonomies', 'textdomain' ), - 'singular_name' => __( 'Taxonomy','textdomain' ), - 'search_items' => __( 'Search taxonomies', 'textdomain' ), - 'all_items' => __( 'All taxonomies', 'textdomain' ), - 'parent_item' => __( 'Parent taxonomy', 'textdomain' ), - 'parent_item_colon' => __( 'Parent taxonomy:', 'textdomain' ), - 'edit_item' => __( 'Edit taxonomy', 'textdomain' ), - 'update_item' => __( 'Update taxonomy', 'textdomain' ), - 'add_new_item' => __( 'Add New taxonomy', 'textdomain' ), - 'new_item_name' => __( 'New Genre taxonomy', 'textdomain' ), - 'menu_name' => __( 'Genre', 'textdomain' ), - ); - - $args = array( - 'hierarchical' => true, - 'labels' => $labels, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_admin_column' => tnc_enable_dev_wp_interface(), - ); - - register_taxonomy( $taxonomy_name, array( ), $args ); - } - - function get_taxonomy_by_id($id) { - return new Tainacan_Taxonomy($id); - } -} - -global $Tainacan_Taxonomies; -$Tainacan_Taxonomies = new Tainacan_Taxonomies(); \ No newline at end of file diff --git a/src/classes/Repositories/Terms.php b/src/classes/Repositories/Terms.php deleted file mode 100644 index ec2114fe1..000000000 --- a/src/classes/Repositories/Terms.php +++ /dev/null @@ -1,78 +0,0 @@ - [ - 'map' => 'term_id', - 'validation' => '' - ], - 'name' => [ - 'map' => 'name', - 'validation' => '' - ], - 'parent' => [ - 'map' => 'parent', - 'validation' => '' - ], - 'description' => [ - 'map' => 'description', - 'validation' => '' - ], - 'taxonomy' => [ - 'map' => 'taxonomy', - 'validation' => '' - ], - 'user' => [ - 'map' => 'termmeta', - 'validation' => '' - ], - ]; - - function insert( Tainacan_Term $term ){ - // First iterate through the native post properties - $map = $this->map; - foreach ($map as $prop => $mapped) { - if ($mapped['map'] != 'termmeta') { - $term->WP_Term->{$mapped['map']} = $term->get_mapped_property($prop); - } - } - - // save post and get its ID - $term_inserted = wp_insert_term( $term->WP_Term->name, $term->WP_Term->taxonomy, [ - 'parent' => ( isset( $term->WP_Term->parent ) ) ? $term->WP_Term->parent : 0, - 'description' => ( isset( $term->WP_Term->description ) ) ? $term->WP_Term->description : '', - ]); - - // Now run through properties stored as postmeta - foreach ($map as $prop => $mapped) { - if ($mapped['map'] == 'termmeta') { - update_term_meta($term_inserted['term_id'], $prop, $term->get_mapped_property($prop)); - } - } - - return $term_inserted['term_id']; - } - - function get_terms( $taxonomies, $args ){ - return get_terms( $taxonomies, $args ); - } - - function get_term_by($field,$value,$taxonomy){ - $wp_term = get_term_by($field,$value,$taxonomy); - - $tainacan_term = new Tainacan_Term( $wp_term ); - $tainacan_term->set_user( get_term_meta($tainacan_term->get_id() , 'user', true ) ); - - return $tainacan_term; - } -} - -global $Tainacan_Terms; -$Tainacan_Terms = new Tainacan_Terms(); \ No newline at end of file diff --git a/src/classes/Repository.php b/src/classes/Repository.php deleted file mode 100644 index 64053e844..000000000 --- a/src/classes/Repository.php +++ /dev/null @@ -1,17 +0,0 @@ -map; - - if (!key_exists($prop, $map)) - return null; - - - - } - -} \ No newline at end of file diff --git a/src/classes/Traits/EntityCollectionRelation.php b/src/classes/Traits/EntityCollectionRelation.php deleted file mode 100644 index 227a5664c..000000000 --- a/src/classes/Traits/EntityCollectionRelation.php +++ /dev/null @@ -1,37 +0,0 @@ -get_mapped_property('collection_id'); - } - - - function get_collection() { - if (isset($this->collection) && $this->collection instanceof TainacanCollection) - return $this->collection; - - if (is_numeric($this->get_collection_id())) { - global $TainacanCollections; - $this->collection = $TainacanCollections->get_collection_by_id($this->get_collection_id()); - return $this->collection; - } - - return null; - - } - - function set_collection_id($value) { - $this->collection = null; - return $this->set_mapped_property('collection_id', $value); - - } - - function set_collection(TainacanCollection $collection) { - $this->collection = $collection; - $this->set_collection_id($collection->get_id()); - } - -} \ No newline at end of file diff --git a/src/classes/Traits/EntityCollectionsRelation.php b/src/classes/Traits/EntityCollectionsRelation.php deleted file mode 100644 index 520f0f8e0..000000000 --- a/src/classes/Traits/EntityCollectionsRelation.php +++ /dev/null @@ -1,46 +0,0 @@ -get_mapped_property('collections_ids'); - } - - - function get_collections() { - if (isset($this->collection) && !empty($this->collection) && is_array($this->collection)) - return $this->collection; - - if (is_array($this->get_collections_ids()) && !empty(is_array($this->get_collections_ids()))) { - - global $TainacanCollections; - $collections = []; - foreach ($this->get_collections_ids() as $col_id) { - $collections[] = $TainacanCollections->get_collection_by_id($col_id); - } - - return $collections; - } - - return null; - - } - - function set_collections_ids(Array $value) { - return $this->set_mapped_property('collection_id', $value); - $this->collections = null; - } - - function set_collections(Array $collections) { - $collections_ids = []; - $this->collections = $collections; - - foreach ($collections as $collection) - $collections_ids[] = $collection->get_id(); - - $this->set_collections_ids($collections_ids); - } - -} \ No newline at end of file diff --git a/src/test-tainacan.php b/src/test-tainacan.php deleted file mode 100644 index c4799690b..000000000 --- a/src/test-tainacan.php +++ /dev/null @@ -1,94 +0,0 @@ -add(), find(), get() - * - * $collection->getItems(), getItem(), addItem(), deleteItem() - * - * metadados registrado via codigo deinem ibase_add_user - * colecoes registradas via cõdigo passam o objeto inteiro e marcamos de algum jeito q não são editaveis - * (source) - * - * - */ - - - - - - - - - - - - - - -function tnc_enable_dev_wp_interface() { - return defined('TNC_ENABLE_DEV_WP_INTERFACE') && true === TNC_ENABLE_DEV_WP_INTERFACE ? true : false; -} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bb2411106..4f1575766 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,7 +16,7 @@ require_once $_tests_dir . '/includes/functions.php'; * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/src/test-tainacan.php'; + require dirname( dirname( __FILE__ ) ) . '/src/class-tainacan.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); // Start up the WP testing environment. diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 59672e4a2..7d9b1e0f9 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -8,20 +8,20 @@ /** * Sample test case. */ -class TestItemMetadata extends WP_UnitTestCase { +class Test_Item_Metadata extends WP_UnitTestCase { /** * Teste da insercao de um metadado simples sem o tipo */ function test_add() { - global $TainacanCollections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; + global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new TainacanCollection(); + $collection = new Tainacan_Collection(); $metadata = new Tainacan_Metadata(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); //setando os valores na classe do metadado $metadata->set_name('metadado'); @@ -33,16 +33,16 @@ class TestItemMetadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); $i->set_collection($collection); - global $TainacanItems; - $item = $TainacanItems->insert($i); + global $Tainacan_Items; + $item = $Tainacan_Items->insert($i); - $item = $TainacanItems->get_item_by_id($item->get_id()); + $item = $Tainacan_Items->get_item_by_id($item->get_id()); $item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); @@ -60,13 +60,13 @@ class TestItemMetadata extends WP_UnitTestCase { * Teste da insercao de um metadado simples com o tipo */ function teste_required(){ - global $TainacanCollections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; + global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new TainacanCollection(); + $collection = new Tainacan_Collection(); $metadata = new Tainacan_Metadata(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); //setando os valores na classe do metadado $metadata->set_name('metadado'); @@ -79,16 +79,16 @@ class TestItemMetadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); $i->set_collection($collection); - global $TainacanItems; - $item = $TainacanItems->insert($i); + global $Tainacan_Items; + $item = $Tainacan_Items->insert($i); - $item = $TainacanItems->get_item_by_id($item->get_id()); + $item = $Tainacan_Items->get_item_by_id($item->get_id()); $item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); @@ -105,13 +105,13 @@ class TestItemMetadata extends WP_UnitTestCase { } function teste_collection_key(){ - global $TainacanCollections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; + global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new TainacanCollection(); + $collection = new Tainacan_Collection(); $metadata = new Tainacan_Metadata(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); //setando os valores na classe do metadado $metadata->set_name('metadado'); @@ -124,16 +124,16 @@ class TestItemMetadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); $i->set_collection($collection); - global $TainacanItems; - $item = $TainacanItems->insert($i); + global $Tainacan_Items; + $item = $Tainacan_Items->insert($i); - $item = $TainacanItems->get_item_by_id($item->get_id()); + $item = $Tainacan_Items->get_item_by_id($item->get_id()); diff --git a/tests/test-items.php b/tests/test-items.php index c0a129b62..f4e613f48 100644 --- a/tests/test-items.php +++ b/tests/test-items.php @@ -8,19 +8,19 @@ /** * Sample test case. */ -class TestItems extends WP_UnitTestCase { +class Test_Items extends WP_UnitTestCase { function teste_query(){ - global $TainacanCollections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; + global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new TainacanCollection(); - $collection2 = new TainacanCollection(); + $collection = new Tainacan_Collection(); + $collection2 = new Tainacan_Collection(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); $collection2->set_name('teste2'); - $collection2 = $TainacanCollections->insert($collection2); + $collection2 = $Tainacan_Collections->insert($collection2); $metadata = new Tainacan_Metadata(); $metadata2 = new Tainacan_Metadata(); @@ -36,63 +36,63 @@ class TestItems extends WP_UnitTestCase { $metadata3->set_collection( $collection2 ); $metadata3 = $Tainacan_Metadatas->insert($metadata3); - global $TainacanItems; - $i = new TainacanItem(); + global $Tainacan_Items; + $i = new Tainacan_Item(); $i->set_title('orange'); $i->set_collection($collection); $i->add_metadata($metadata, 'value_1'); - $item = $TainacanItems->insert($i); + $item = $Tainacan_Items->insert($i); - $item = $TainacanItems->get_item_by_id($item->get_id()); + $item = $Tainacan_Items->get_item_by_id($item->get_id()); $meta_test = $item->get_metadata(); $this->assertTrue( isset($meta_test[$metadata->get_id()]) ); $this->assertTrue( $meta_test[$metadata->get_id()] instanceof Tainacan_Item_Metadata_Entity ); $this->assertEquals( $meta_test[$metadata->get_id()]->get_value(), 'value_1'); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('apple'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_2'); $i->add_metadata($metadata3, 'value_2'); - $item = $TainacanItems->insert($i); + $item = $Tainacan_Items->insert($i); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('lemon'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_2'); $i->add_metadata($metadata2, 'value_3'); // if we set twice, value is overridden $i->add_metadata($metadata3, 'value_3'); - $item = $TainacanItems->insert($i); + $item = $Tainacan_Items->insert($i); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('pinapple'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_3'); $i->add_metadata($metadata3, 'value_6'); - $item = $TainacanItems->insert($i); + $item = $Tainacan_Items->insert($i); // should return all 4 items - $test_query = $TainacanItems->query([]); + $test_query = $Tainacan_Items->query([]); $this->assertEquals(4, sizeof($test_query)); // should also return all 4 items - $test_query = $TainacanItems->query(['collections' => [$collection, $collection2]]); + $test_query = $Tainacan_Items->query(['collections' => [$collection, $collection2]]); $this->assertEquals(4, sizeof($test_query)); // should return only the first item - $test_query = $TainacanItems->query(['collections' => $collection]); + $test_query = $Tainacan_Items->query(['collections' => $collection]); $this->assertEquals(1, sizeof($test_query)); $this->assertEquals('orange', $test_query[0]->get_title()); - $test_query = $TainacanItems->query(['title' => 'orange']); + $test_query = $Tainacan_Items->query(['title' => 'orange']); $this->assertEquals(1, sizeof($test_query)); $this->assertEquals('orange', $test_query[0]->get_title()); // should return the other 3 items - $test_query = $TainacanItems->query(['collections' => $collection2]); + $test_query = $Tainacan_Items->query(['collections' => $collection2]); $this->assertEquals(3, sizeof($test_query)); - $test_query = $TainacanItems->query(['title' => 'apple']); + $test_query = $Tainacan_Items->query(['title' => 'apple']); $this->assertEquals(1, sizeof($test_query)); $this->assertEquals('apple', $test_query[0]->get_title()); $apple_meta = $test_query[0]->get_metadata(); @@ -103,7 +103,7 @@ class TestItems extends WP_UnitTestCase { } // should return 1 item - $test_query = $TainacanItems->query([ + $test_query = $Tainacan_Items->query([ 'collections' => $collection2, 'metadata' => [ [ @@ -115,7 +115,7 @@ class TestItems extends WP_UnitTestCase { $this->assertEquals(1, sizeof($test_query)); // should return 2 items - $test_query = $TainacanItems->query([ + $test_query = $Tainacan_Items->query([ 'collections' => $collection2, 'metadata' => [ [ @@ -127,7 +127,7 @@ class TestItems extends WP_UnitTestCase { $this->assertEquals(2, sizeof($test_query)); // should return 2 item - $test_query = $TainacanItems->query([ + $test_query = $Tainacan_Items->query([ 'collections' => $collection2, 'metadata' => [ [ diff --git a/tests/test-metadata.php b/tests/test-metadata.php index a25b36bd2..60e3f91db 100644 --- a/tests/test-metadata.php +++ b/tests/test-metadata.php @@ -8,19 +8,19 @@ /** * Sample test case. */ -class TestMetadata extends WP_UnitTestCase { +class Test_Metadata extends WP_UnitTestCase { /** * Teste da insercao de um metadado simples sem o tipo */ function test_add() { - global $TainacanCollections, $Tainacan_Metadatas; + global $Tainacan_Collections, $Tainacan_Metadatas; - $collection = new TainacanCollection(); + $collection = new Tainacan_Collection(); $metadata = new Tainacan_Metadata(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); //setando os valores na classe do metadado $metadata->set_name('metadado'); @@ -42,14 +42,14 @@ class TestMetadata extends WP_UnitTestCase { * Teste da insercao de um metadado simples com o tipo */ function teste_add_type(){ - global $TainacanCollections, $Tainacan_Metadatas; + global $Tainacan_Collections, $Tainacan_Metadatas; - $collection = new TainacanCollection(); + $collection = new Tainacan_Collection(); $metadata = new Tainacan_Metadata(); $type = new Tainacan_Text_Field_Type(); $collection->set_name('teste'); - $collection = $TainacanCollections->insert($collection); + $collection = $Tainacan_Collections->insert($collection); //setando os valores na classe do metadado $metadata->set_name('metadado'); diff --git a/tests/test-sample.php b/tests/test-sample.php index d6817b4f8..e0f13854f 100644 --- a/tests/test-sample.php +++ b/tests/test-sample.php @@ -8,25 +8,25 @@ /** * Sample test case. */ -class TestCollections extends WP_UnitTestCase { +class Test_Collections extends WP_UnitTestCase { /** * A single example test. */ function test_add() { - $x = new TainacanCollection(); + $x = new Tainacan_Collection(); $x->set_name('teste'); $x->set_description('adasdasdsa'); $x->set_itens_per_page(23); - global $TainacanCollections; - $col = $TainacanCollections->insert($x); + global $Tainacan_Collections; + $col = $Tainacan_Collections->insert($x); // - $test = $TainacanCollections->get_collection_by_id($col->get_id()); + $test = $Tainacan_Collections->get_collection_by_id($col->get_id()); $this->assertEquals($test->get_name(), 'teste'); @@ -39,29 +39,29 @@ class TestCollections extends WP_UnitTestCase { function test_item() { - $x = new TainacanCollection(); + $x = new Tainacan_Collection(); $x->set_name('teste'); $x->set_description('adasdasdsa'); $x->set_itens_per_page(23); - global $TainacanCollections; - $col = $TainacanCollections->insert($x); + global $Tainacan_Collections; + $col = $Tainacan_Collections->insert($x); - $collection = $TainacanCollections->get_collection_by_id($col->get_id()); + $collection = $Tainacan_Collections->get_collection_by_id($col->get_id()); - $i = new TainacanItem(); + $i = new Tainacan_Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); $i->set_collection($collection); - global $TainacanItems; - $item = $TainacanItems->insert($i); + global $Tainacan_Items; + $item = $Tainacan_Items->insert($i); - $item = $TainacanItems->get_item_by_id($item->get_id()); + $item = $Tainacan_Items->get_item_by_id($item->get_id()); $this->assertEquals($item->get_title(), 'item teste'); $this->assertEquals($item->get_description(), 'adasdasdsa'); diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index e636dcc42..6ea064c39 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -8,7 +8,7 @@ /** * Sample test case. */ -class TestTaxonomies extends WP_UnitTestCase { +class Test_Taxonomies extends WP_UnitTestCase { /** @@ -37,7 +37,7 @@ class TestTaxonomies extends WP_UnitTestCase { } function test_add_term_taxonomy(){ - global $Tainacan_Taxonomies,$Tainacan_Terms; + global $Tainacan_Taxonomies, $Tainacan_Terms; $taxonomy = new Tainacan_Taxonomy(); $term = new Tainacan_Term();