Improves in prepare item for db from fields controller and in test api metadata
This commit is contained in:
parent
8ec80c9733
commit
84658b1981
|
@ -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' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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(){
|
||||||
|
|
Loading…
Reference in New Issue