aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-12 15:16:52 +0000
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-12 15:16:52 +0000
commitc499b05093744813a04fe537e0b588a547f3a784 (patch)
tree00ea4ea17073e50b450d27c12fac3a18790d5e2b /engine
parent6008f2d28266f9a5ca1c49bccea4a3a0766105f7 (diff)
downloadelgg-c499b05093744813a04fe537e0b588a547f3a784.tar.gz
elgg-c499b05093744813a04fe537e0b588a547f3a784.tar.bz2
Adding unit tests for the ElggObject class.
Restricting testing suite to only be run as a logged-in user. This will not allow the tests to be run from the command line, but this is already the case due to debug static. git-svn-id: http://code.elgg.org/elgg/trunk@3527 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/tests/objects/entities.php20
-rw-r--r--engine/tests/objects/objects.php119
-rwxr-xr-xengine/tests/suite.php3
3 files changed, 137 insertions, 5 deletions
diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php
index f3f20024b..0827fa24a 100644
--- a/engine/tests/objects/entities.php
+++ b/engine/tests/objects/entities.php
@@ -141,10 +141,9 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
try {
$this->entity->save();
$this->assertTrue(FALSE);
- }
- catch (Exception $e) {
+ } catch (Exception $e) {
$this->assertIsA($e, 'InvalidParameterException');
- $this->assertIdentical($e->getMessage(), 'Entity type must be set.');
+ $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:EntityTypeNotSet'));
}
// set elements
@@ -152,7 +151,7 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->entity->non_existent = 'testing';
// save
- $this->AssertEqual($guid, 0);
+ $this->AssertEqual($this->entity->getGUID(), 0);
$guid = $this->entity->save();
$this->AssertNotEqual($guid, 0);
@@ -192,6 +191,19 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertTrue($this->entity->enable());
$this->assertTrue($this->entity->delete());
}
+
+ public function testElggEntityExportables() {
+ $exportables = array(
+ 'guid',
+ 'type',
+ 'subtype',
+ 'time_created',
+ 'container_guid',
+ 'owner_guid',
+ );
+
+ $this->assertIdentical($exportables, $this->entity->getExportableValues());
+ }
protected function save_entity($type='site')
{
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php
index c9600ab6e..de3c2f1c4 100644
--- a/engine/tests/objects/objects.php
+++ b/engine/tests/objects/objects.php
@@ -40,7 +40,7 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
/**
* A basic test that will be called and fail.
*/
- public function testElggEntityConstructor() {
+ public function testElggObjectConstructor() {
$attributes = array();
$attributes['guid'] = '';
$attributes['type'] = 'object';
@@ -59,6 +59,123 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
$this->assertIdentical($this->entity->expose_attributes(), $attributes);
}
+
+ public function testElggObjectSave() {
+ // new object
+ $this->AssertEqual($this->entity->getGUID(), 0);
+ $guid = $this->entity->save();
+ $this->AssertNotEqual($guid, 0);
+
+ $entity_row = $this->get_entity_row($guid);
+ $this->assertIsA($entity_row, 'stdClass');
+
+ // update existing object
+ $this->entity->title = 'testing';
+ $this->entity->description = 'ElggObject';
+ $this->assertEqual($this->entity->save(), $guid);
+
+ $object_row = $this->get_object_row($guid);
+ $this->assertIsA($object_row, 'stdClass');
+ $this->assertIdentical($object_row->title, 'testing');
+ $this->assertIdentical($object_row->description, 'ElggObject');
+
+ // clean up
+ $this->entity->delete();
+ }
+
+ public function testElggObjectLoad() {
+ // fail on wrong type
+ try {
+ $error = new ElggObjectTest(get_loggedin_userid());
+ $this->assertTrue(FALSE);
+ } catch (Exception $e) {
+ $this->assertIsA($e, 'InvalidClassException');
+ $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), get_loggedin_userid(), 'ElggObject');
+ $this->assertIdentical($e->getMessage(), $message);
+ }
+ }
+
+ public function testElggObjectConstructorByGUID() {
+ $guid = $this->entity->save();
+
+ // load a new object using guid
+ $entity = new ElggObjectTest($guid);
+ $this->assertIdentical($this->entity, $entity);
+
+ // 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));
+
+ // copy attributes of ElggObject
+ $this->assertIdentical($this->entity, new ElggObjectTest($this->entity));
+
+ // 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'));
+ }
+
+ // clean up
+ $this->entity->delete();
+ }
+
+ public function testElggObjectContainer() {
+ $this->assertEqual($this->entity->getContainer(), get_loggedin_userid());
+
+ // fals when container not a group
+ $this->assertFalse($this->entity->getContainerEntity());
+
+ // create and save to group
+ $group = new ElggGroup();
+ $guid = $group->save();
+ $this->assertTrue($this->entity->setContainer($guid));
+
+ // check container
+ $this->assertEqual($this->entity->getContainer(), $guid);
+ $this->assertIdentical($group, $this->entity->getContainerEntity());
+
+ // clean up
+ $group->delete();
+ }
+
+ public function testElggObjectExportables() {
+ $exportables = array(
+ 'guid',
+ 'type',
+ 'subtype',
+ 'time_created',
+ 'container_guid',
+ 'owner_guid',
+ 'title',
+ 'description'
+ );
+
+ $this->assertIdentical($exportables, $this->entity->getExportableValues());
+ }
+
+
+ protected function get_object_row($guid) {
+ global $CONFIG;
+ return get_data_row("SELECT * FROM {$CONFIG->dbprefix}objects_entity WHERE guid='$guid'");
+ }
+
+ protected function get_entity_row($guid) {
+ global $CONFIG;
+ return get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid='$guid'");
+ }
}
class ElggObjectTest extends ElggObject {
diff --git a/engine/tests/suite.php b/engine/tests/suite.php
index c8972a78f..729958527 100755
--- a/engine/tests/suite.php
+++ b/engine/tests/suite.php
@@ -11,6 +11,9 @@
require_once(dirname( __FILE__ ) . '/../start.php');
+// Ensure that only logged-in users can see this page
+gatekeeper();
+
$vendor_path = "$CONFIG->path/vendors/simpletest";
$test_path = "$CONFIG->path/engine/tests";