2017-11-14 10:17:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
|
|
|
class Test_Filters extends WP_UnitTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
function teste_add(){
|
|
|
|
global $Tainacan_Collections, $Tainacan_Filters;
|
|
|
|
|
|
|
|
$collection = new Tainacan_Collection();
|
|
|
|
$filter = new Tainacan_Filter();
|
|
|
|
|
|
|
|
$collection->set_name('teste');
|
|
|
|
$collection = $Tainacan_Collections->insert($collection);
|
|
|
|
|
|
|
|
//setando os valores na classe do metadado
|
2017-11-14 14:46:22 +00:00
|
|
|
$filter->set_name('filtro');
|
2017-11-14 10:17:28 +00:00
|
|
|
$filter->set_collection( $collection );
|
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
//inserindo o metadado
|
|
|
|
$filter = $Tainacan_Filters->insert( $filter );
|
|
|
|
|
|
|
|
$test = $Tainacan_Filters->get_filter_by_id( $filter->get_id() );
|
|
|
|
|
|
|
|
$this->assertEquals($test->get_name(), 'filtro');
|
|
|
|
$this->assertEquals($test->get_collection_id(), $collection->get_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_add_with_metadata_and_type(){
|
|
|
|
global $Tainacan_Collections, $Tainacan_Filters,$Tainacan_Metadatas;
|
|
|
|
|
|
|
|
$collection = new Tainacan_Collection();
|
|
|
|
$metadata = new Tainacan_Metadata();
|
|
|
|
$filter = new Tainacan_Filter();
|
|
|
|
$type = new Tainacan_Text_Field_Type();
|
|
|
|
$filter_list_type = new Tainacan_List_Filter_Type();
|
|
|
|
$filter_range_type = new Tainacan_Range_Filter_Type();
|
|
|
|
|
|
|
|
$collection->set_name('teste');
|
|
|
|
$collection = $Tainacan_Collections->insert($collection);
|
|
|
|
|
|
|
|
//setando os valores na classe do metadado
|
|
|
|
$metadata->set_name('metadado');
|
|
|
|
$metadata->set_collection_id( $collection->get_id() );
|
|
|
|
$metadata->set_type( $type );
|
|
|
|
|
|
|
|
|
2017-11-14 10:17:28 +00:00
|
|
|
//inserindo o metadado
|
|
|
|
$metadata = $Tainacan_Metadatas->insert($metadata);
|
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
//inserindo o filtro
|
|
|
|
$filter->set_name('filtro');
|
|
|
|
$filter->set_collection( $collection );
|
|
|
|
$filter->set_metadata( $metadata );
|
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_widget( $filter_range_type ) === null );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
$filter->set_widget( $filter_list_type );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
$filter = $Tainacan_Filters->insert( $filter );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
$test = $Tainacan_Filters->get_filter_by_id( $filter->get_id() );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
$this->assertEquals( $test->get_name(), 'filtro');
|
|
|
|
$this->assertEquals( $test->get_collection_id(), $collection->get_id() );
|
|
|
|
$this->assertEquals( $test->get_metadata()->get_id(), $metadata->get_id() );
|
|
|
|
$this->assertEquals( get_class( $test->get_widget() ), get_class( $filter_list_type ) );
|
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-14 14:46:22 +00:00
|
|
|
$all_filter_types = $Tainacan_Filters->get_all_filters_type();
|
|
|
|
$this->assertEquals( count( $all_filter_types ), 2 );
|
2017-11-14 10:17:28 +00:00
|
|
|
|
2017-11-14 14:46:22 +00:00
|
|
|
$float_filters = $Tainacan_Filters->get_filters_by_metadata_type('float');
|
|
|
|
$this->assertTrue( count( $float_filters ) > 0 );
|
2017-11-14 10:17:28 +00:00
|
|
|
}
|
|
|
|
}
|