From b1f81ce5ad195d6f1cd31100b3b4e9ed9f3d92c0 Mon Sep 17 00:00:00 2001 From: brettp Date: Sun, 20 Feb 2011 15:58:01 +0000 Subject: Fixes #2963: Rewrote ElggEntity->setMetadata() because yikes. Wrote unit tests for setting metadata on saved / unsaved entities. git-svn-id: http://code.elgg.org/elgg/trunk@8359 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/tests/objects/entities.php | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'engine/tests') diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php index 824b47a8a..ca3abb274 100644 --- a/engine/tests/objects/entities.php +++ b/engine/tests/objects/entities.php @@ -267,6 +267,80 @@ class ElggCoreEntityTest extends ElggCoreUnitTest { $this->assertIdentical($exportables, $this->entity->getExportableValues()); } + public function testElggEntityMultipleMetadata() { + foreach (array(false, true) as $save) { + if ($save) { + $this->save_entity(); + } + $md = array('brett', 'bryan', 'brad'); + $name = 'test_md_' . rand(); + + $this->entity->$name = $md; + + $this->assertEqual($md, $this->entity->$name); + } + } + + public function testElggEntitySingleElementArrayMetadata() { + foreach (array(false, true) as $save) { + if ($save) { + $this->save_entity(); + } + $md = array('test'); + $name = 'test_md_' . rand(); + + $this->entity->$name = $md; + + $this->assertEqual($md[0], $this->entity->$name); + } + } + + public function testElggEntityAppendMetadata() { + foreach (array(false, true) as $save) { + if ($save) { + $this->save_entity(); + } + $md = 'test'; + $name = 'test_md_' . rand(); + + $this->entity->$name = $md; + $this->entity->setMetaData($name, 'test2', '', true); + + $this->assertEqual(array('test', 'test2'), $this->entity->$name); + } + } + + public function testElggEntitySingleElementArrayAppendMetadata() { + foreach (array(false, true) as $save) { + if ($save) { + $this->save_entity(); + } + $md = 'test'; + $name = 'test_md_' . rand(); + + $this->entity->$name = $md; + $this->entity->setMetaData($name, array('test2'), '', true); + + $this->assertEqual(array('test', 'test2'), $this->entity->$name); + } + } + + public function testElggEntityArrayAppendMetadata() { + foreach (array(false, true) as $save) { + if ($save) { + $this->save_entity(); + } + $md = array('brett', 'bryan', 'brad'); + $md2 = array('test1', 'test2', 'test3'); + $name = 'test_md_' . rand(); + + $this->entity->$name = $md; + $this->entity->setMetaData($name, $md2, '', true); + + $this->assertEqual(array_merge($md, $md2), $this->entity->$name); + } + } + protected function save_entity($type='site') { $this->entity->type = $type; -- cgit v1.2.3