aboutsummaryrefslogtreecommitdiff
path: root/engine/tests
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-12 12:56:19 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-12 12:56:19 +0000
commit8f5ac5c27f81b04bb71bab930638762c8c3e501e (patch)
tree6b9d1fec66c50b342167d17816f4c8d444406918 /engine/tests
parent70dafccc9b4cdef58a559fc8fa5ec640bf13af1d (diff)
downloadelgg-8f5ac5c27f81b04bb71bab930638762c8c3e501e.tar.gz
elgg-8f5ac5c27f81b04bb71bab930638762c8c3e501e.tar.bz2
closes #1145 - deprecated current "copy constructor" for all entities and implemented a clone method. The clone copies over all metadata but not annotations and private settings. It sets the guid to 0 so saving the cloned entity creates a new database record. The ownership/access of metadata is set during the save and will be the same as that of the entity.
git-svn-id: http://code.elgg.org/elgg/trunk@3802 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests')
-rw-r--r--engine/tests/objects/objects.php48
-rw-r--r--engine/tests/objects/users.php22
2 files changed, 29 insertions, 41 deletions
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php
index d30e4fae4..8209917bf 100644
--- a/engine/tests/objects/objects.php
+++ b/engine/tests/objects/objects.php
@@ -103,30 +103,40 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
// clean up
$this->entity->delete();
}
-
- public function testElggObjectConstructorByObject() {
- $guid = $this->entity->save();
- // stdClass: use guid
- $object_row = $this->get_object_row($guid);
- $entity_row = $this->get_entity_row($guid);
- $this->assertIdentical($this->entity, new ElggObjectTest($object_row));
- $this->assertIdentical($this->entity, new ElggObjectTest($entity_row));
+ public function testElggObjectClone() {
+ $this->entity->title = 'testing';
+ $this->entity->description = 'ElggObject';
+ $this->entity->var1 = "test";
+ $this->entity->var2 = 1;
+ $this->entity->var3 = true;
+ $this->entity->save();
- // copy attributes of ElggObject
- $this->assertIdentical($this->entity, new ElggObjectTest($this->entity));
+ // add tag array
+ $tag_string = 'tag1, tag2, tag3';
+ $tagarray = string_to_tag_array($tag_string);
+ $this->entity->tags = $tagarray;
- // error on ElggEntity
- $entity = new ElggEntityTest($guid);
- try {
- $error = new ElggObjectTest($entity);
- $this->assertTrue(FALSE);
- } catch (Exception $e) {
- $this->assertIsA($e, 'InvalidParameterException');
- $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:NonElggObject'));
- }
+ // a cloned ElggEntity has the guid reset
+ $object = clone $this->entity;
+ $this->assertIdentical(0, (int)$object->guid);
+
+ // make sure attributes were copied over
+ $this->assertIdentical($object->title, 'testing');
+ $this->assertIdentical($object->description, 'ElggObject');
+
+ $guid = $object->save();
+ $this->assertTrue($guid !== 0);
+ $this->assertTrue($guid !== $this->entity->guid);
+
+ // test that metadata was transfered
+ $this->assertIdentical($this->entity->var1, $object->var1);
+ $this->assertIdentical($this->entity->var2, $object->var2);
+ $this->assertIdentical($this->entity->var3, $object->var3);
+ $this->assertIdentical($this->entity->tags, $object->tags);
// clean up
+ $object->delete();
$this->entity->delete();
}
diff --git a/engine/tests/objects/users.php b/engine/tests/objects/users.php
index c1403af1a..c03091a91 100644
--- a/engine/tests/objects/users.php
+++ b/engine/tests/objects/users.php
@@ -119,29 +119,7 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$user = new ElggUser($row->username);
$this->assertIdentical($user, $_SESSION['user']);
}
-
- public function testElggUserConstructorByObject() {
- $obj = new ElggUser(get_loggedin_userid());
- $user = new ElggUser($obj);
- $this->assertIdentical($obj, $user);
- $this->assertIdentical($user, $_SESSION['user']);
-
- // fail on non-user object
- $object = new ElggObject();
- $object->save();
-
- try {
- $error = new ElggUserTest($object);
- $this->assertTrue(FALSE);
- } catch (Exception $e) {
- $this->assertIsA($e, 'InvalidParameterException');
- $message = sprintf(elgg_echo('InvalidParameterException:NonElggUser'));
- $this->assertIdentical($e->getMessage(), $message);
- }
- $object->delete();
- }
-
public function testElggUserSave() {
// new object
$this->AssertEqual($this->user->getGUID(), 0);