tainacan/tests/test-filters.php

91 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.
*/
2017-11-15 18:50:11 +00:00
class Filters extends \WP_UnitTestCase {
2017-11-14 10:17:28 +00:00
function teste_add(){
global $Tainacan_Collections, $Tainacan_Filters;
2017-11-15 18:50:11 +00:00
$collection = new \Tainacan\Entities\Collection();
$filter = new \Tainacan\Entities\Filter();
2017-11-14 10:17:28 +00:00
$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;
2017-11-15 18:50:11 +00:00
$collection = new \Tainacan\Entities\Collection();
$metadata = new \Tainacan\Entities\Metadata();
$filter = new \Tainacan\Entities\Filter();
$type = new \Tainacan\Field_Types\Text_Field_Type();
$filter_list_type = new \Tainacan\Filter_Types\List_Filter_Type();
$filter_range_type = new \Tainacan\Filter_Types\Range_Filter_Type();
2017-11-14 14:46:22 +00:00
$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() );
2017-11-14 18:44:04 +00:00
$metadata->set_field_type_object( $type );
2017-11-14 14:46:22 +00:00
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
2017-11-14 18:44:04 +00:00
$this->assertTrue( $filter->set_filter_type_object( $filter_range_type ) === null );
2017-11-14 10:17:28 +00:00
2017-11-14 18:44:04 +00:00
$filter->set_filter_type_object( $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() );
2017-11-14 18:44:04 +00:00
$this->assertEquals( get_class( $test->get_filter_type_object() ), 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
}
}