tainacan/tests/test-metadata.php

70 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/**
* Class TestCollections
*
* @package Test_Tainacan
*/
/**
* Sample test case.
*/
class Test_Metadata extends WP_UnitTestCase {
/**
* Teste da insercao de um metadado simples sem o tipo
*/
function test_add() {
global $Tainacan_Collections, $Tainacan_Metadatas;
$collection = new Tainacan_Collection();
$metadata = new Tainacan_Metadata();
$collection->set_name('teste');
$collection = $Tainacan_Collections->insert($collection);
//setando os valores na classe do metadado
2017-11-09 15:51:16 +00:00
$metadata->set_name('metadado');
$metadata->set_description('descricao');
2017-11-12 23:14:47 +00:00
$metadata->set_collection( $collection );
//inserindo o metadado
2017-11-12 23:14:47 +00:00
$metadata = $Tainacan_Metadatas->insert($metadata);
2017-11-12 23:14:47 +00:00
$test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id());
2017-11-09 15:51:16 +00:00
$this->assertEquals($test->get_name(), 'metadado');
$this->assertEquals($test->get_description(), 'descricao');
2017-11-12 23:14:47 +00:00
$this->assertEquals($test->get_collection_id(), $collection->get_id());
}
2017-11-09 15:51:16 +00:00
/**
* Teste da insercao de um metadado simples com o tipo
*/
function teste_add_type(){
global $Tainacan_Collections, $Tainacan_Metadatas;
2017-11-09 15:51:16 +00:00
$collection = new Tainacan_Collection();
2017-11-09 15:51:16 +00:00
$metadata = new Tainacan_Metadata();
$type = new Tainacan_Text_Field_Type();
$collection->set_name('teste');
$collection = $Tainacan_Collections->insert($collection);
2017-11-09 15:51:16 +00:00
//setando os valores na classe do metadado
$metadata->set_name('metadado');
2017-11-12 23:14:47 +00:00
$metadata->set_collection_id( $collection->get_id() );
2017-11-14 18:44:04 +00:00
$metadata->set_field_type_object( $type );
2017-11-09 15:51:16 +00:00
2017-11-12 23:14:47 +00:00
2017-11-09 15:51:16 +00:00
//inserindo o metadado
2017-11-12 23:14:47 +00:00
$metadata = $Tainacan_Metadatas->insert($metadata);
2017-11-09 15:51:16 +00:00
2017-11-12 23:14:47 +00:00
$test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id());
2017-11-09 15:51:16 +00:00
$this->assertEquals($test->get_name(), 'metadado');
2017-11-12 23:14:47 +00:00
$this->assertEquals($test->get_collection_id(), $collection->get_id());
2017-11-14 18:44:04 +00:00
$this->assertEquals($test->get_field_type(), 'Tainacan_Text_Field_Type');
$this->assertEquals($test->get_field_type_object(), $type);
2017-11-09 15:51:16 +00:00
}
}