tainacan/tests/test-filters.php

109 lines
3.0 KiB
PHP
Raw Normal View History

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.
*/
class Filters extends TAINACAN_UnitTestCase {
2017-11-14 10:17:28 +00:00
function teste_add(){
global $Tainacan_Filters;
2017-11-14 14:46:22 +00:00
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'Filter teste colletion'
),
true
);
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
'name' => 'filtro',
'collection' => $collection,
'description' => 'Teste Filtro'
),
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(){
global $Tainacan_Filters;
2017-11-14 10:17:28 +00:00
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'Filter teste colletion'
),
true
);
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
array(
'name' => 'metadado',
'collection_id' => $collection->get_id(),
'field_type' => $type,
'description' => 'descricao',
),
true
);
$filter_list_type = $this->tainacan_filter_factory->create_filter('list_filter');
$filter = $this->tainacan_entity_factory->create_entity(
'filter',
array(
'name' => 'filtro',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'filter_type' => $filter_list_type
),
true
);
$filter_range_type = $this->tainacan_filter_factory->create_filter('range');
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
$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() );
$this->assertEquals( $metadata->get_id(), $test->get_metadata()->get_id() );
$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();
2017-11-15 21:37:34 +00:00
$this->assertEquals( 2, 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
}
}