Improves in prepare item for db from fields controller and in test api metadata

This commit is contained in:
weryques 2018-03-01 15:02:53 -03:00
parent 8ec80c9733
commit 84658b1981
2 changed files with 10 additions and 17 deletions

View File

@ -106,24 +106,16 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
public function prepare_item_for_database( $request, $collection_id = null ) { public function prepare_item_for_database( $request, $collection_id = null ) {
$field = new Entities\Field(); $field = new Entities\Field();
if($collection_id) {
$meta = json_decode( $request, true ); $meta = json_decode( $request, true );
foreach ( $meta as $key => $value ) { foreach ( $meta as $key => $value ) {
$set_ = 'set_' . $key; $set_ = 'set_' . $key;
$field->$set_( $value ); $field->$set_( $value );
} }
if($collection_id) {
$collection = new Entities\Collection( $collection_id ); $collection = new Entities\Collection( $collection_id );
$field->set_collection( $collection ); $field->set_collection( $collection );
} else { } else {
$meta = json_decode( $request, true );
foreach ( $meta as $key => $value ) {
$set_ = 'set_' . $key;
$field->$set_( $value );
}
$field->set_collection_id( 'default' ); $field->set_collection_id( 'default' );
} }

View File

@ -2,8 +2,6 @@
namespace Tainacan\Tests; namespace Tainacan\Tests;
use Tainacan\Repositories;
/** /**
* @group api * @group api
*/ */
@ -42,6 +40,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertTrue(is_array($field_added) && array_key_exists('name', $field_added), sprintf('cannot create field, response: %s', print_r($field_added, true))); $this->assertTrue(is_array($field_added) && array_key_exists('name', $field_added), sprintf('cannot create field, response: %s', print_r($field_added, true)));
$this->assertEquals('Moeda', $field_added['name']); $this->assertEquals('Moeda', $field_added['name']);
$this->assertNotEquals('default', $field_added['collection_id']);
} }
public function test_create_default_field(){ public function test_create_default_field(){
@ -64,6 +63,8 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertTrue(is_array($field_added) && array_key_exists('name', $field_added), sprintf('cannot create field, response: %s', print_r($field_added, true))); $this->assertTrue(is_array($field_added) && array_key_exists('name', $field_added), sprintf('cannot create field, response: %s', print_r($field_added, true)));
$this->assertEquals('Ano de Publicação', $field_added['name']); $this->assertEquals('Ano de Publicação', $field_added['name']);
$this->assertEquals('default', $field_added['collection_id']);
} }
public function test_get_item_and_collection_metadata(){ public function test_get_item_and_collection_metadata(){