2017-11-14 10:17:28 +00:00
|
|
|
<?php
|
2017-11-15 18:50:11 +00:00
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2017-11-14 10:17:28 +00:00
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
2017-12-04 14:58:19 +00:00
|
|
|
class Filters extends TAINACAN_UnitTestCase {
|
2017-11-14 10:17:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
function teste_add(){
|
2017-12-04 14:58:19 +00:00
|
|
|
global $Tainacan_Filters;
|
2017-11-14 14:46:22 +00:00
|
|
|
|
2017-12-04 14:58:19 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
2018-01-03 19:39:10 +00:00
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'Filter teste colletion'
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
2018-01-03 19:39:10 +00:00
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'Teste Filtro'
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$test = $Tainacan_Filters->fetch($filter->get_id());
|
2017-11-14 14:46:22 +00:00
|
|
|
|
2017-11-15 21:37:34 +00:00
|
|
|
$this->assertEquals('filtro', $test->get_name());
|
|
|
|
$this->assertEquals($collection->get_id(), $test->get_collection_id());
|
2017-11-14 14:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_add_with_metadata_and_type(){
|
2017-12-04 14:58:19 +00:00
|
|
|
global $Tainacan_Filters;
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-12-04 14:58:19 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
2018-01-03 19:39:10 +00:00
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'Filter teste colletion'
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$field = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'field',
|
2017-12-04 14:58:19 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'collection_id' => $collection->get_id(),
|
2018-02-21 17:04:25 +00:00
|
|
|
'field_type' => 'Tainacan\Field_Types\Text',
|
2018-01-03 19:39:10 +00:00
|
|
|
'description' => 'descricao',
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-02-27 12:03:34 +00:00
|
|
|
$filter_list_type = $this->tainacan_filter_factory->create_filter('selectbox');
|
2017-12-04 14:58:19 +00:00
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
2018-01-03 19:39:10 +00:00
|
|
|
'description' => 'descricao',
|
2018-01-31 14:47:59 +00:00
|
|
|
'field' => $field,
|
2017-12-05 17:42:15 +00:00
|
|
|
'filter_type' => $filter_list_type
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-03-01 19:32:42 +00:00
|
|
|
$filter_range_type = $this->tainacan_filter_factory->create_filter('custom_interval');
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
//nao devera permitir um filtro Range para o tipo string
|
2017-12-05 17:42:15 +00:00
|
|
|
$this->assertTrue( $filter->set_filter_type( $filter_range_type ) === null );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-20 15:40:26 +00:00
|
|
|
$test = $Tainacan_Filters->fetch( $filter->get_id() );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-15 21:37:34 +00:00
|
|
|
$this->assertEquals( 'filtro', $test->get_name() );
|
|
|
|
$this->assertEquals( $collection->get_id(), $test->get_collection_id() );
|
2018-01-31 14:47:59 +00:00
|
|
|
$this->assertEquals( $field->get_id(), $test->get_field()->get_id() );
|
2017-11-15 21:37:34 +00:00
|
|
|
$objClass = get_class( $filter_list_type );
|
|
|
|
$storedObjClass = get_class( $test->get_filter_type_object() );
|
|
|
|
$this->assertEquals($objClass , $storedObjClass );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
}
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
function test_get_filters_type(){
|
|
|
|
global $Tainacan_Filters;
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-29 18:06:22 +00:00
|
|
|
$all_filter_types = $Tainacan_Filters->fetch_filter_types();
|
2018-03-05 18:41:32 +00:00
|
|
|
$this->assertEquals( 3, count( $all_filter_types ) );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-29 18:06:22 +00:00
|
|
|
$float_filters = $Tainacan_Filters->fetch_supported_filter_types('float');
|
2017-11-14 14:46:22 +00:00
|
|
|
$this->assertTrue( count( $float_filters ) > 0 );
|
2017-11-14 10:17:28 +00:00
|
|
|
}
|
2018-03-05 18:41:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group filter
|
|
|
|
*/
|
|
|
|
function test_validate_supported_filters(){
|
|
|
|
global $Tainacan_Filters;
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$field2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'field',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'field_type' => 'Tainacan\Field_Types\Text',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$autocomplete = $this->tainacan_filter_factory->create_filter('autocomplete');
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'field' => $field2,
|
|
|
|
'filter_type' => $autocomplete
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$test = $Tainacan_Filters->fetch( $filter->get_id() );
|
|
|
|
|
|
|
|
$this->assertEquals( 'Tainacan\Filter_Types\Autocomplete', $test->get_filter_type());
|
|
|
|
|
|
|
|
$custom_interval = $this->tainacan_filter_factory->create_filter('custom_interval');
|
|
|
|
|
|
|
|
$this->expectException('ErrorException');
|
|
|
|
$filter2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro 2',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'field' => $field2,
|
|
|
|
'filter_type' => $custom_interval
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2017-11-14 10:17:28 +00:00
|
|
|
}
|