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(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
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(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
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-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-04 14:58:19 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'collection_id' => $collection->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-01-03 19:39:10 +00:00
|
|
|
'description' => 'descricao',
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
2018-01-03 19:39:10 +00:00
|
|
|
'description' => 'descricao',
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum' => $metadatum,
|
2019-06-03 14:41:44 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Selectbox'
|
2017-12-04 14:58:19 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2019-10-23 20:28:48 +00:00
|
|
|
$filter_range_type = $this->tainacan_filter_factory->create_filter('Numeric_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-06-11 15:10:07 +00:00
|
|
|
$this->assertEquals( $metadatum->get_id(), $test->get_metadatum()->get_id() );
|
2017-11-15 21:37:34 +00:00
|
|
|
$storedObjClass = get_class( $test->get_filter_type_object() );
|
2019-06-03 14:41:44 +00:00
|
|
|
$this->assertEquals('Tainacan\Filter_Types\Selectbox' , $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(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-29 18:06:22 +00:00
|
|
|
$all_filter_types = $Tainacan_Filters->fetch_filter_types();
|
2019-10-10 19:20:03 +00:00
|
|
|
$this->assertEquals( 11, 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(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
2018-03-05 18:41:32 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-03-05 18:41:32 +00:00
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-03-05 18:41:32 +00:00
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
2018-05-21 16:56:50 +00:00
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum' => $metadatum2,
|
2019-06-03 14:41:44 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete'
|
2018-05-21 16:56:50 +00:00
|
|
|
),
|
2018-03-05 18:41:32 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$test = $Tainacan_Filters->fetch( $filter->get_id() );
|
|
|
|
|
|
|
|
$this->assertEquals( 'Tainacan\Filter_Types\Autocomplete', $test->get_filter_type());
|
|
|
|
|
2018-05-22 21:09:34 +00:00
|
|
|
$filter2 = new \Tainacan\Entities\Filter();
|
|
|
|
$filter2->set_name('filter 2');
|
|
|
|
$filter2->set_collection($collection);
|
|
|
|
$filter2->set_description('description');
|
2018-06-11 15:10:07 +00:00
|
|
|
$filter2->set_metadatum($metadatum2);
|
2019-10-23 20:28:48 +00:00
|
|
|
$filter2->set_filter_type('Tainacan\Filter_Types\Numeric_Interval');
|
2018-05-22 21:09:34 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertFalse($filter2->validate(), 'filter with a metadatum with unsupported primitive type should not validate');
|
2018-03-05 18:41:32 +00:00
|
|
|
|
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2018-11-14 13:43:24 +00:00
|
|
|
/**
|
|
|
|
* test if parent metadatum are visible for children collection
|
|
|
|
*/
|
|
|
|
function test_hierarchy_filters(){
|
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
|
|
|
|
|
|
$meta_repo = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'metadatum default',
|
|
|
|
'collection_id' => $Tainacan_Metadata->get_default_metadata_attribute(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2018-11-14 13:43:24 +00:00
|
|
|
$this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filter default',
|
2019-09-30 21:00:44 +00:00
|
|
|
'collection_id' => 'default',
|
2018-11-14 13:43:24 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Selectbox',
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $meta_repo->get_id(),
|
2018-11-14 13:43:24 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_grandfather = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection grandfather'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$meta_grand = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'metadatum grandfather',
|
|
|
|
'collection_id' => $collection_grandfather->get_id(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filter grandfather',
|
|
|
|
'collection_id' => $collection_grandfather->get_id(),
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Selectbox',
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $meta_grand->get_id(),
|
2018-11-14 13:43:24 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_father = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection father',
|
|
|
|
'parent' => $collection_grandfather->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$meta_father = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'metadatum father',
|
|
|
|
'collection_id' => $collection_father->get_id(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filter father',
|
|
|
|
'collection_id' => $collection_father->get_id(),
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Selectbox',
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $meta_father->get_id(),
|
2018-11-14 13:43:24 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_son = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection son',
|
|
|
|
'parent' => $collection_father->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $collection_grandfather->get_id(), $collection_father->get_parent() );
|
|
|
|
$this->assertEquals( $collection_father->get_id(), $collection_son->get_parent() );
|
|
|
|
|
|
|
|
$meta_son = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'metadatum son',
|
|
|
|
'collection_id' => $collection_son->get_id(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filter son',
|
|
|
|
'collection_id' => $collection_son->get_id(),
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Selectbox',
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $meta_son->get_id(),
|
2018-11-14 13:43:24 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2019-10-21 22:11:41 +00:00
|
|
|
$retrieve_filters = $Tainacan_Filters->fetch_by_collection( $collection_son );
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2018-11-14 13:43:24 +00:00
|
|
|
$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 ) );
|
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
function test_metadatum_getter_setter(){
|
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter2 = new \Tainacan\Entities\Filter();
|
|
|
|
$filter2->set_name('filter 2');
|
|
|
|
$filter2->set_collection($collection);
|
|
|
|
$filter2->set_description('description');
|
|
|
|
$filter2->set_metadatum($metadatum2);
|
|
|
|
$filter2->set_filter_type('Tainacan\Filter_Types\Selectbox');
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter2->validate();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter = $Tainacan_Filters->insert($filter2);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$this->assertEquals($metadatum2->get_id(), $filter->get_metadatum_id());
|
|
|
|
$this->assertEquals($metadatum2->get_name(), $filter->get_metadatum()->get_name());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$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');
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter3->validate();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter = $Tainacan_Filters->insert($filter3);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$this->assertEquals($metadatum2->get_id(), $filter->get_metadatum_id());
|
|
|
|
$this->assertEquals($metadatum2->get_name(), $filter->get_metadatum()->get_name());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$metadatum3 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter4 = new \Tainacan\Entities\Filter();
|
|
|
|
$filter4->set_name('filter 4');
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$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());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
$filter4->set_metadatum($metadatum2);
|
|
|
|
$this->assertEquals($metadatum2->get_id(), $filter4->get_metadatum_id());
|
|
|
|
$this->assertEquals($metadatum2->get_name(), $filter4->get_metadatum()->get_name());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
|
|
|
|
2019-06-03 14:41:44 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
function test_delete_filter_when_metadata_deleted() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'metadatum' => $metadatum2,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$Tainacan_Metadata->delete($metadatum2);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$x = $Tainacan_Filters->fetch( $filter->get_id() );
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
$this->assertEmpty($x);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-06-26 17:36:47 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
function test_trash_filter_when_metadata_trashed() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'metadatum' => $metadatum2,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$Tainacan_Metadata->trash($metadatum2);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$x = $Tainacan_Filters->fetch( $filter->get_id() );
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
$this->assertEquals('trash', $x->get_status());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-07-01 14:33:53 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
function test_private_metadatum() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'private',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$filter = new \Tainacan\Entities\Filter();
|
|
|
|
$filter->set_name('teste');
|
|
|
|
$filter->set_metadatum($metadatum2);
|
|
|
|
$filter->set_status('publish');
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$this->assertFalse($filter->validate());
|
|
|
|
$this->assertArrayHasKey('status', $filter->get_errors()[0]);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$filter->set_status('private');
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$this->assertTrue($filter->validate());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_private_metadatum_update() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection_id' => $collection->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'metadatum' => $metadatum2,
|
|
|
|
'status' => 'publish',
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$this->assertEquals('publish', $filter->get_status());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$metadatum2->set_status('private');
|
|
|
|
$metadatum2->validate();
|
|
|
|
$Tainacan_Metadata->insert($metadatum2);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$check_filter = $Tainacan_Filters->fetch( $filter->get_id() );
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
$this->assertEquals('private', $check_filter->get_status());
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-10 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 20:28:48 +00:00
|
|
|
|
|
|
|
}
|