Remove Custom Interval filter and migrate to new ones #306

This commit is contained in:
leogermani 2019-10-23 17:28:48 -03:00
parent 28d9b1df6e
commit f94426580b
8 changed files with 199 additions and 501 deletions

View File

@ -23,7 +23,6 @@ import FormRelationship from '../../classes/metadata-types/relationship/FormRela
import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.vue';
import FormSelectbox from '../../classes/metadata-types/selectbox/FormSelectbox.vue';
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
@ -59,7 +58,7 @@ import FormNumericListInterval from '../../classes/filter-types/numeric-list-int
// Configure and Register Plugins
Vue.use(Buefy, {
defaultTooltipAnimated: true
defaultTooltipAnimated: true
});
Vue.use(VTooltip);
Vue.use(VueMasonry);
@ -87,7 +86,6 @@ Vue.component('tainacan-form-item', TainacanFormItem);
Vue.component('tainacan-filter-item', TainacanFiltersList);
/* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
@ -128,7 +126,7 @@ new Vue({
render: h => h(AdminPage)
});
// Display Icons only once everything is loaded
// Display Icons only once everything is loaded
function listen(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);

View File

@ -5,7 +5,6 @@ import VTooltip from 'v-tooltip';
import VueMasonry from 'vue-masonry-css';
// Custom elements
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
@ -34,7 +33,7 @@ import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin, StatusH
// Configure and Register Plugins
Vue.use(Buefy, {
defaultTooltipAnimated: true
defaultTooltipAnimated: true
});
Vue.use(VTooltip);
Vue.use(VueMasonry);
@ -44,11 +43,9 @@ Vue.use(RouterHelperPlugin);
Vue.use(StatusHelperPlugin);
Vue.use(ConsolePlugin, {visual: false});
Vue.component('tainacan-filter-item', TaincanFiltersList);
/* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
@ -79,7 +76,7 @@ import ThemeItemsList from '../theme-items-list.vue';
export const ThemeItemsListing = new Vue({
el: '#tainacan-items-page',
store,
router: routerTheme,
router: routerTheme,
data: {
termId: '',
taxonomy: '',
@ -90,9 +87,9 @@ export const ThemeItemsListing = new Vue({
},
render: h => h(ThemeItemsList),
beforeMount () {
this.collectionId = this.$el.attributes['collection-id'] != undefined ? this.$el.attributes['collection-id'].value : undefined;
if (this.$el.attributes['default-view-mode'] != undefined)
this.defaultViewMode = this.$el.attributes['default-view-mode'].value;
else
@ -107,10 +104,10 @@ export const ThemeItemsListing = new Vue({
this.taxonomy = this.$el.attributes['taxonomy'].value;
}
});
// Display Icons only once everything is loaded
// Display Icons only once everything is loaded
function listen(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);

View File

@ -1,261 +0,0 @@
<template>
<div>
<!-- Date -->
<div v-if="metadatumType === 'Tainacan\\Metadata_Types\\Date'">
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="dateInit"
size="is-small"
@focus="isTouched = true"
@input="validadeValues()"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:years-range="[-200, 50]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="dateEnd"
size="is-small"
@input="validadeValues()"
@focus="isTouched = true"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:years-range="[-200, 50]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
</div>
<!-- Numeric -->
<div v-else>
<b-input
type="number"
:aria-labelledby="'filter-label-id-' + filter.id"
size="is-small"
step="any"
@input="validadeValues"
v-model="valueInit"/>
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
<b-input
type="number"
:aria-labelledby="'filter-label-id-' + filter.id"
size="is-small"
step="any"
@input="validadeValues"
@focus="isTouched = true"
v-model="valueEnd"/>
</div>
</div>
</template>
<script>
import { wpAjax, dateInter } from "../../../admin/js/mixins";
import { filterTypeMixin } from '../filter-types-mixin';
import moment from 'moment';
export default {
mixins: [
wpAjax,
dateInter,
filterTypeMixin
],
mounted() {
this.updateSelectedValues();
},
data(){
return {
valueInit: '',
valueEnd: '',
dateInit: undefined,
dateEnd: undefined,
isTouched: false,
type: 'DECIMAL'
}
},
watch: {
isTouched( val ){
if ( val && this.dateInit === null)
this.dateInit = new Date();
if ( val && this.dateEnd === null)
this.dateEnd = new Date();
},
'query.metaquery'() {
this.updateSelectedValues();
}
},
methods: {
// only validate if the first value is higher than first
validadeValues: _.debounce( function (){
if( this.metadatumType === 'Tainacan\\Metadata_Types\\Date' ){
if (this.dateInit === undefined)
this.dateInit = new Date();
if (this.dateEnd === undefined)
this.dateEnd = new Date();
if ( this.dateInit > this.dateEnd ) {
this.showErrorMessage();
return
}
} else {
if (this.valueInit.constructor == Number)
this.valueInit = this.valueInit.valueOf();
if (this.valueEnd.constructor == Number)
this.valueEnd = this.valueEnd.valueOf();
this.valueInit = parseFloat(this.valueInit);
this.valueEnd = parseFloat(this.valueEnd);
if (isNaN(this.valueInit) || isNaN(this.valueEnd))
return
if (this.valueInit > this.valueEnd) {
this.showErrorMessage();
return;
}
}
this.emit();
}, 800),
// message for error
showErrorMessage(){
if ( !this.isTouched ) return false;
this.$buefy.toast.open({
duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'),
position: 'is-bottom',
type: 'is-danger'
})
},
dateFormatter(dateObject){
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
},
dateParser(dateString){
return moment(dateString, this.dateFormat).toDate();
},
updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId);
if (index >= 0) {
let metadata = this.query.metaquery[ index ];
if( metadata.value && metadata.value.length > 0 && this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric'){
this.valueInit = parseFloat(metadata.value[0]);
this.valueEnd = parseFloat(metadata.value[1]);
} else if( metadata.value && metadata.value.length > 0 ){
this.dateInit = new Date(metadata.value[0]);
this.dateEnd = new Date(metadata.value[1]);
}
if (metadata.value[0] != undefined && metadata.value[1] != undefined)
this.$emit('sendValuesToTags', {
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (metadata.value[0] + ' - ' + metadata.value[1]) : this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])),
value: [metadata.value[0], metadata.value[1]]
});
} else {
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric') {
this.valueInit = '';
this.valueEnd = '';
} else {
this.dateInit = null;
this.dateEnd = null;
}
}
},
// emit the operation for listeners
emit() {
let values = [];
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Date') {
if (this.dateInit === null && this.dateEnd === null) {
values = [];
this.type = 'DATE';
} else {
let dateInit = this.dateInit.getUTCFullYear() + '-' +
('00' + (this.dateInit.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.dateInit.getUTCDate()).slice(-2);
let dateEnd = this.dateEnd.getUTCFullYear() + '-' +
('00' + (this.dateEnd.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.dateEnd.getUTCDate()).slice(-2);
values = [ dateInit, dateEnd ];
this.type = 'DATE';
}
} else {
if (this.valueInit === null || this.valueEnd === null
|| this.valueInit === '' || this.valueEnd === ''){
return;
} else {
values = [ this.valueInit, this.valueEnd ];
if(this.valueInit !== this.valueEnd && (this.valueInit % 1 !== 0 && this.valueEnd % 1 == 0)) {
this.type = 'DECIMAL';
} else if(this.valueInit !== this.valueEnd &&
this.valueInit % 1 !== 0 &&
this.valueEnd % 1 !== 0) {
this.type = '';
} else if(this.valueInit !== this.valueEnd &&
!(this.valueInit % 1 == 0 && this.valueEnd % 1 !== 0)){
this.type = 'DECIMAL';
} else {
this.type = '';
}
}
}
this.$emit('input', {
filter: 'range',
type: this.type,
compare: 'BETWEEN',
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: values
});
if (values[0] != undefined && values[1] != undefined)
this.$emit( 'sendValuesToTags', {
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (values[0] + ' - ' + values[1]) : this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])),
value: [ values[0], values[1] ]
});
}
}
}
</script>
<style scoped>
.field {
margin-bottom: 0.125rem !important;
}
p.is-size-7 {
margin-bottom: 0.125rem !important;
}
</style>

View File

@ -1,74 +0,0 @@
<?php
namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Class TainacanMetadatumType
*/
class Custom_Interval extends Filter_Type {
function __construct(){
$this->set_name( __('Custom Interval', 'tainacan'));
$this->set_supported_types(['float','date']);
$this->set_component('tainacan-filter-custom-interval');
$this->set_use_max_options(false);
$this->set_preview_template('
<div>
<div class="b-numberinput field is-grouped">
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-minus"></i>
</span>
</button>
</p>
<div class="control is-small is-clearfix">
<input type="number" step="0.01" class="input is-small" value="6">
</div>
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-plus"></i>
</span>
</button>
</p>
</div>
<p class="is-size-7 has-text-centered is-marginless">until</p>
<div class="b-numberinput field is-grouped">
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-minus"></i>
</span>
</button>
</p>
<div class="control is-small is-clearfix">
<input type="number" step="0.01" class="input is-small" value="10">
</div>
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-plus"></i>
</span>
</button>
</p>
</div>
</div>
');
}
/**
* @param $filter
* @return string
* @internal param $metadatum
*/
public function render( $filter ){
$type = ( $filter->get_metadatum()->get_metadata_type() === 'Tainacan\Metadata_Types\Date' ) ? 'date' : 'numeric';
return '<tainacan-filter-custom-interval
name="'.$filter->get_name().'"
collection_id="'.$filter->get_collection_id().'"
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-custom-interval>';
}
}

View File

@ -106,7 +106,7 @@ function tainacan_autoload($class_name){
}
$file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
if(file_exists($file)) {
require_once($file);
}
@ -132,7 +132,6 @@ $Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Taxonomy');
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
//register filter type
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Custom_Interval');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Selectbox');

View File

@ -1,38 +1,38 @@
<?php
<?php
namespace Tainacan;
class Migrations {
static function run_migrations() {
$migrations = get_class_methods('Tainacan\Migrations');
foreach ($migrations as $migration) {
$option_name = '_migration_' . $migration;
if ('run_migrations' == $migration || get_option($option_name)) {
continue;
}
update_option($option_name, 1);
call_user_func(array('Tainacan\Migrations', $migration));
}
}
// Migrations methods below
static function tainacan_create_bd_process_db() {
global $wpdb;
$table_name = $wpdb->prefix . 'tnc_bg_process';
$charset_collate = $wpdb->get_charset_collate();
$max_index_length = 191;
$query = "CREATE TABLE IF NOT EXISTS $table_name (
ID bigint(20) unsigned NOT NULL auto_increment,
user_id bigint(20) unsigned NOT NULL default '0',
@ -51,20 +51,20 @@ class Migrations {
KEY user_id (user_id),
KEY action (action($max_index_length))
) $charset_collate;\n";
$wpdb->query($query);
}
/**
* We had some cases of tainacan upgrades from very old versions that missed some migrations...
* This migration make sure the table strucure is updated since the very first version
*/
static function assure_bg_process_database() {
global $wpdb;
$table_name = $wpdb->prefix . 'tnc_bg_process';
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'progress_label'" );
if(empty($column_exists)) {
@ -83,8 +83,8 @@ class Migrations {
ADD name text NOT NULL
");
}
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'output'" );
if(empty($column_exists)) {
@ -93,7 +93,7 @@ class Migrations {
ADD output longtext
");
}
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'status'" );
if(empty($column_exists)) {
@ -102,14 +102,14 @@ class Migrations {
ADD status ENUM('waiting','running','paused','cancelled','errored','finished','finished-errors')
");
}
}
static function init_capabilites() {
$Tainacan_Capabilities = \Tainacan\Capabilities::get_instance();
$Tainacan_Capabilities->init();
}
static function tainacan_migrate_post_type_field_to_metadatum(){
global $wpdb;
@ -117,7 +117,7 @@ class Migrations {
['post_type' => 'tainacan-metadatum'],
['post_type' => 'tainacan-field'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_key' => 'default_displayed_metadata'],
['meta_key' => 'default_displayed_fields'],
@ -137,17 +137,17 @@ class Migrations {
['meta_key' => 'metadata_type'],
['meta_key' => 'field_type'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_key' => 'metadata_type_options'],
['meta_key' => 'field_type_options'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_key' => 'metadata_type'],
['meta_key' => 'metadatum_type'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_key' => 'metadata_type_options'],
['meta_key' => 'metadatum_type_options'],
@ -204,8 +204,8 @@ class Migrations {
['meta_value' => 'Tainacan\Metadata_Types\Compound'],
['meta_value' => 'Tainacan\Field_Types\Compound'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_value' => 'Tainacan\Metadata_Types\Core_Description'],
['meta_value' => 'Tainacan\Metadatum_Types\Core_Description'],
@ -245,7 +245,7 @@ class Migrations {
['meta_value' => 'Tainacan\Metadata_Types\Relationship'],
['meta_value' => 'Tainacan\Metadatum_Types\Relationship'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_value' => 'Tainacan\Metadata_Types\Compound'],
['meta_value' => 'Tainacan\Metadatum_Types\Compound'],
@ -255,7 +255,7 @@ class Migrations {
['meta_value' => 'Tainacan\Metadata_Types\Taxonomy'],
['meta_value' => 'Tainacan\Metadatum_Types\Category'],
'%s', '%s');
$wpdb->update($wpdb->postmeta,
['meta_value' => 'Tainacan\Metadata_Types\Taxonomy'],
['meta_value' => 'Tainacan\Metadata_Types\Category'],
@ -289,20 +289,20 @@ class Migrations {
// update input type
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = REPLACE(meta_value, 'tainacan-taxonomy-selectbox', 'tainacan-taxonomy-radio')");
}
static function update_core_metadata() {
global $wpdb;
$collections = \Tainacan\Repositories\Collections::get_instance()->fetch([], 'OBJECT');
foreach ($collections as $collection) {
// get title
// get title
$title_meta = $collection->get_core_title_metadatum();
// delete metadata if exists
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $title_meta->get_id() ));
// create metadata
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
SELECT ID, %s, post_title FROM $wpdb->posts WHERE post_type = %s
", $title_meta->get_id(), $collection->get_db_identifier() ));
@ -314,7 +314,7 @@ class Migrations {
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $description_meta->get_id() ));
// create metadata
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
SELECT ID, %s, post_content FROM $wpdb->posts WHERE post_type = %s
", $description_meta->get_id(), $collection->get_db_identifier() ));
@ -324,46 +324,46 @@ class Migrations {
static function refresh_rewrite_rules() {
// needed after we changed the Collections post type rewrite slug
$option_name = '_migration_refresh_rewrite_rules_items';
if (!get_option($option_name)) {
return; // avoid running twice cause there is the same update right below this one
}
flush_rewrite_rules(false);
}
static function refresh_rewrite_rules_items() {
// needed after we added the /items rewrite rule
flush_rewrite_rules(false);
}
static function update_filters_definition() {
global $wpdb;
$wpdb->query("UPDATE $wpdb->postmeta SET meta_key = 'metadatum_id' WHERE
meta_key = 'metadatum' AND post_id IN (
SELECT ID FROM $wpdb->posts WHERE post_type = 'tainacan-filter'
)");
}
static function update_repository_filters_meta() {
global $wpdb;
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 'default' WHERE
post_id IN (
SELECT ID FROM $wpdb->posts WHERE post_type = 'tainacan-filter'
) AND meta_key = 'collection_id' AND meta_value = 'filter_in_repository'"
) AND meta_key = 'collection_id' AND meta_value = 'filter_in_repository'"
);
}
static function update_relationship_metadata_search_option() {
global $wpdb;
$q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'metadata_type' AND meta_value = 'Tainacan\\\\Metadata_Types\\\\Relationship'";
$ids = $wpdb->get_col($q);
foreach ($ids as $id) {
@ -373,11 +373,54 @@ class Migrations {
update_post_meta($id, 'metadata_type_options', $meta);
}
}
}
static function replace_custom_interval_filters() {
$tainacan_filters = \Tainacan\Repositories\Filters::get_instance();
$filters = $tainacan_filters->fetch([
'nopaging' => true,
'filter_type' => 'Tainacan\Filter_Types\Custom_Interval',
'post_status' => 'any'
], 'OBJECT');
foreach ($filters as $filter) {
$meta = $filter->get_metadatum();
#echo 'found filter:' . $filter->get_name(). "<br>";
if ($meta instanceof \Tainacan\Entities\Metadatum) {
$type = $meta->get_metadata_type();
#echo 'found meta:' . $meta->get_name(). "<br>";
#echo 'found meta:' . $meta->get_metadata_type(). "<br>";
$newtype = false;
if ( $type == 'Tainacan\Metadata_Types\Date' ) {
$newtype = 'Tainacan\Filter_Types\Date_Interval';
} elseif ( $type == 'Tainacan\Metadata_Types\Numeric' ) {
$newtype = 'Tainacan\Filter_Types\Numeric_Interval';
}
#echo 'New type:' . $newtype. "<br>";
if ($newtype) {
$filter->set_filter_type($newtype);
if ($filter->validate()) {
#echo "INSERT\n\n";
$tainacan_filters->insert($filter);
}
}
}
}
}
}
?>
?>

View File

@ -3,7 +3,7 @@
namespace Tainacan\Tests;
/**
* @group api
* @group api
*/
class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
@ -33,7 +33,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$request_body = json_encode(
array(
'filter_type' => '\Tainacan\Filter_Types\Custom_Interval',
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
'filter' => [
'name' => 'Filter name',
'description' => 'This is CUSTOM INTERVAL!',
@ -49,7 +49,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$data = $response->get_data();
$this->assertTrue(is_array($data) && array_key_exists('filter_type', $data), sprintf('cannot create a custom interval, response: %s', print_r($data, true)));
$this->assertEquals('Tainacan\Filter_Types\Custom_Interval', $data['filter_type']);
$this->assertEquals('Tainacan\Filter_Types\Numeric_Interval', $data['filter_type']);
$this->assertEquals('Filter name', $data['name']);
}
@ -82,7 +82,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'description' => 'descricao',
'metadatum_id' => $metadatum->get_id(),
'filter_type' => 'Tainacan\Filter_Types\Custom_Interval',
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
),
true
);
@ -143,8 +143,6 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$filter_type = $this->tainacan_filter_factory->create_filter('custom_interval');
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -152,7 +150,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'description' => 'descricao',
'metadatum_id' => $metadatum->get_id(),
'filter_type' => $filter_type,
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
),
true
);
@ -209,8 +207,6 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$filter_type = $this->tainacan_filter_factory->create_filter('custom_interval');
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -218,7 +214,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'description' => 'descricao',
'metadatum' => $metadatum,
'filter_type' => $filter_type,
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
'status' => 'publish'
),
true
@ -231,7 +227,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'description' => 'descricao',
'metadatum' => $metadatum2,
'filter_type' => $filter_type,
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
'status' => 'publish'
),
true
@ -366,9 +362,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertCount(2, $data4);
//$this->assertEquals('4x Filter', $data4[0]['name']);
}
public function test_return_filter_type_options_in_get_item() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -377,7 +373,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -388,7 +384,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$filter_numeric = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -403,7 +399,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/filters/' . $filter_numeric->get_id()
@ -416,11 +412,11 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals($filter_numeric->get_id(), $data['id']);
$this->assertEquals('numeric', $data['name']);
$this->assertEquals(3, $data['filter_type_options']['step']);
}
public function test_return_filter_type_options_in_get_items() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -429,7 +425,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -440,7 +436,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$filter_numeric = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -455,7 +451,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/collection/' . $collection1->get_id() . '/filters'
@ -464,7 +460,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$response = $this->server->dispatch($request);
$data = $response->get_data();
//var_dump($data, $this->namespace . '/collection/' . $collection2->get_id() . '/metadata/');
foreach ($data as $d) {
if ($d['id'] == $filter_numeric->get_id()) {
@ -472,15 +468,15 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
break;
}
}
$this->assertEquals($filter_numeric->get_id(), $meta['id']);
$this->assertEquals('numeric', $meta['name']);
$this->assertEquals(3, $meta['filter_type_options']['step']);
}
public function test_return_filter_type_options_in_get_item_default_value() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -489,7 +485,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -500,7 +496,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$filter_numeric = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -515,7 +511,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/filters/' . $filter_numeric->get_id()
@ -529,11 +525,11 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals('numeric', $data['name']);
$this->assertEquals(1, $data['filter_type_object']['options']['step']);
$this->assertEquals(1, $data['filter_type_options']['step']);
}
public function test_return_metadata_type_options_inside_metadatum_property() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -542,7 +538,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$collection2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -551,9 +547,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$core1 = $collection1->get_core_title_metadatum();
$meta_relationship = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -569,7 +565,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -581,7 +577,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
),
true
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/filters/' . $filter->get_id()
@ -595,9 +591,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals('yes', $data['metadatum']['metadata_type_object']['options']['repeated']);
$this->assertEquals($collection1->get_id(), $data['metadatum']['metadata_type_object']['options']['collection_id']);
$this->assertEquals($core1->get_id(), $data['metadatum']['metadata_type_object']['options']['search']);
}
}
?>
?>

View File

@ -78,7 +78,7 @@ class Filters extends TAINACAN_UnitTestCase {
true
);
$filter_range_type = $this->tainacan_filter_factory->create_filter('custom_interval');
$filter_range_type = $this->tainacan_filter_factory->create_filter('Numeric_Interval');
//nao devera permitir um filtro Range para o tipo string
$this->assertTrue( $filter->set_filter_type( $filter_range_type ) === null );
@ -97,7 +97,7 @@ class Filters extends TAINACAN_UnitTestCase {
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$all_filter_types = $Tainacan_Filters->fetch_filter_types();
$this->assertEquals( 12, count( $all_filter_types ) );
$this->assertEquals( 11, count( $all_filter_types ) );
$float_filters = $Tainacan_Filters->fetch_supported_filter_types('float');
$this->assertTrue( count( $float_filters ) > 0 );
@ -150,12 +150,12 @@ class Filters extends TAINACAN_UnitTestCase {
$filter2->set_collection($collection);
$filter2->set_description('description');
$filter2->set_metadatum($metadatum2);
$filter2->set_filter_type('Tainacan\Filter_Types\Custom_Interval');
$filter2->set_filter_type('Tainacan\Filter_Types\Numeric_Interval');
$this->assertFalse($filter2->validate(), 'filter with a metadatum with unsupported primitive type should not validate');
}
/**
* test if parent metadatum are visible for children collection
*/
@ -173,7 +173,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -282,14 +282,14 @@ class Filters extends TAINACAN_UnitTestCase {
);
$retrieve_filters = $Tainacan_Filters->fetch_by_collection( $collection_son, [], 'OBJECT' );
$retrieve_filters_ids = $Tainacan_Filters->fetch_ids_by_collection( $collection_son, [] );
// should return 4
$this->assertEquals( 4, sizeof( $retrieve_filters ) );
$this->assertEquals( 4, sizeof( $retrieve_filters_ids ) );
}
function test_metadatum_getter_setter(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
@ -319,29 +319,29 @@ class Filters extends TAINACAN_UnitTestCase {
$filter2->set_description('description');
$filter2->set_metadatum($metadatum2);
$filter2->set_filter_type('Tainacan\Filter_Types\Selectbox');
$filter2->validate();
$filter = $Tainacan_Filters->insert($filter2);
$this->assertEquals($metadatum2->get_id(), $filter->get_metadatum_id());
$this->assertEquals($metadatum2->get_name(), $filter->get_metadatum()->get_name());
$filter3 = new \Tainacan\Entities\Filter();
$filter3->set_name('filter 3');
$filter3->set_collection($collection);
$filter3->set_description('description');
$filter3->set_metadatum_id($metadatum2->get_id());
$filter3->set_filter_type('Tainacan\Filter_Types\Selectbox');
$filter3->validate();
$filter = $Tainacan_Filters->insert($filter3);
$this->assertEquals($metadatum2->get_id(), $filter->get_metadatum_id());
$this->assertEquals($metadatum2->get_name(), $filter->get_metadatum()->get_name());
$metadatum3 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -352,27 +352,27 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$filter4 = new \Tainacan\Entities\Filter();
$filter4->set_name('filter 4');
$filter4->set_metadatum_id($metadatum3->get_id());
$this->assertEquals($metadatum3->get_id(), $filter4->get_metadatum_id());
$this->assertEquals($metadatum3->get_name(), $filter4->get_metadatum()->get_name());
$filter4->set_metadatum($metadatum2);
$this->assertEquals($metadatum2->get_id(), $filter4->get_metadatum_id());
$this->assertEquals($metadatum2->get_name(), $filter4->get_metadatum()->get_name());
}
function test_delete_filter_when_metadata_deleted() {
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -381,7 +381,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$metadatum2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -392,7 +392,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -404,20 +404,20 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$Tainacan_Metadata->delete($metadatum2);
$x = $Tainacan_Filters->fetch( $filter->get_id() );
$this->assertEmpty($x);
}
function test_trash_filter_when_metadata_trashed() {
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -426,7 +426,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$metadatum2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -437,7 +437,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -449,20 +449,20 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$Tainacan_Metadata->trash($metadatum2);
$x = $Tainacan_Filters->fetch( $filter->get_id() );
$this->assertEquals('trash', $x->get_status());
}
function test_private_metadatum() {
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -471,7 +471,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$metadatum2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -483,27 +483,27 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$filter = new \Tainacan\Entities\Filter();
$filter->set_name('teste');
$filter->set_metadatum($metadatum2);
$filter->set_status('publish');
$this->assertFalse($filter->validate());
$this->assertArrayHasKey('status', $filter->get_errors()[0]);
$filter->set_status('private');
$this->assertTrue($filter->validate());
}
function test_private_metadatum_update() {
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
@ -512,7 +512,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$metadatum2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -524,7 +524,7 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
@ -537,18 +537,18 @@ class Filters extends TAINACAN_UnitTestCase {
),
true
);
$this->assertEquals('publish', $filter->get_status());
$metadatum2->set_status('private');
$metadatum2->validate();
$Tainacan_Metadata->insert($metadatum2);
$check_filter = $Tainacan_Filters->fetch( $filter->get_id() );
$this->assertEquals('private', $check_filter->get_status());
}
}
}