From dbc3349d4699894b68f8f43cf8033a500908d9fa Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Fri, 9 Feb 2018 16:04:39 -0200 Subject: [PATCH] fix and test deleting entities attributes --- .../entities/class-tainacan-entity.php | 2 +- src/classes/entities/class-tainacan-term.php | 5 ++-- tests/test-objects.php | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index 6ce3e139c..7a3bfc843 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -129,7 +129,7 @@ class Entity { * @return mixed property value */ public function get_mapped_property($prop) { - if (isset($this->$prop) && !empty($this->$prop)){ + if (isset($this->$prop) ){ return $this->$prop; } //prop is not set at object, try to get from database diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 7b05e9568..bf5f8bfc6 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -22,9 +22,10 @@ class Term extends Entity { * @param int $which * @param string $taxonomy */ - function __construct($which = 0, $taxonomy = '' ) { + function __construct($which = 0, $taxonomy = false ) { - $this->set_taxonomy( $taxonomy ); + if ($taxonomy) + $this->set_taxonomy( $taxonomy ); if ( is_numeric( $which ) && $which > 0) { $post = get_term_by('id', $which, $taxonomy); diff --git a/tests/test-objects.php b/tests/test-objects.php index da0e2e71b..e22c3b472 100644 --- a/tests/test-objects.php +++ b/tests/test-objects.php @@ -111,4 +111,27 @@ class Objects extends TAINACAN_UnitTestCase { $entity = Repository::get_entity_by_post($test); $this->assertEquals($item_metadata->get_field()->get_db_identifier(), $entity->get_db_identifier()); } + + function test_delete_attributes() { + + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'test title', + 'description' => 'test description', + 'status' => 'draft' + ), + true + ); + + $collection->set_name(''); + $this->assertEquals('', $collection->get_name()); + + global $Tainacan_Collections; + $this->assertTrue($collection->validate()); + $newCol = $Tainacan_Collections->insert($collection); + $this->assertEquals('', $newCol->get_name()); + + + } }