]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Creating an ElggObject unit test.
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 9 Oct 2009 17:11:25 +0000 (17:11 +0000)
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 9 Oct 2009 17:11:25 +0000 (17:11 +0000)
Fixing issues with the unit test plugin hooks, as well as infinite looping bugs introduced by the unit test skeleton.

git-svn-id: http://code.elgg.org/elgg/trunk@3519 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/entities.php
engine/lib/objects.php
engine/tests/objects/entities.php
engine/tests/objects/objects.php [new file with mode: 0644]
engine/tests/test_skeleton.php

index 779efb7afd4283350af406090edf4e5850e0f7e4..b72eb6ff07a491ac1b026fc2a4f1ad856be39f5f 100644 (file)
         */
        function entities_test($hook, $type, $value, $params) {
                global $CONFIG;
-               $params[] = $CONFIG->path . 'engine/tests/objects/entities.php';
-               return $params;
+               $value[] = $CONFIG->path . 'engine/tests/objects/entities.php';
+               return $value;
        }
        
        /**
index 7e7e956a41fa44f332a6d19fc02e59579b119b0c..8d09b178b9c86dab7d8a503ac4f8059ceb092d25 100644 (file)
                
                return get_entities_from_relationship("member_of_site", $object_guid, false, "site", "", 0, "time_created desc", $limit, $offset);
        }
-               
-?>
\ No newline at end of file
+
+/**
+ * Runs unit tests for ElggObject
+ */
+register_plugin_hook('unit_test', 'system', 'objects_test');
+function objects_test($hook, $type, $value, $params) {
+       global $CONFIG;
+       $value[] = "{$CONFIG->path}engine/tests/objects/objects.php";
+       return $value;
+}
index be9c11a6fb82673ef006ec65e153d033543d430d..f3f20024beefd5a2f66d579cf19bcbfc4a786687 100644 (file)
@@ -112,6 +112,11 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
                $annotations = $this->entity->getAnnotations('non_existent');
                $this->assertIsA($annotations[0], 'ElggAnnotation');
                $this->assertIdentical($annotations[0]->name, 'non_existent');
+               $this->assertEqual($this->entity->countAnnotations('non_existent'), 1);
+               
+               //  clear annotation
+               $this->assertTrue($this->entity->clearAnnotations());
+               $this->assertEqual($this->entity->countAnnotations('non_existent'), 0);
 
                // clean up
                $this->assertTrue($this->entity->delete());
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php
new file mode 100644 (file)
index 0000000..c9600ab
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Elgg Test ElggObject
+ *
+ * @package Elgg
+ * @subpackage Test
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+class ElggCoreObjectTest extends ElggCoreUnitTest {
+
+       /**
+        * Called before each test object.
+        */
+       public function __construct() {
+               parent::__construct();
+       }
+
+       /**
+        * Called before each test method.
+        */
+       public function setUp() {
+               $this->entity = new ElggObjectTest();
+       }
+
+       /**
+        * Called after each test method.
+        */
+       public function tearDown() {
+               unset($this->entity);
+       }
+
+       /**
+        * Called after each test object.
+        */
+       public function __destruct() {
+               parent::__destruct();
+       }
+
+       /**
+        * A basic test that will be called and fail.
+        */
+       public function testElggEntityConstructor() {
+               $attributes = array();
+               $attributes['guid'] = '';
+               $attributes['type'] = 'object';
+               $attributes['subtype'] = '';
+               $attributes['owner_guid'] = get_loggedin_userid();
+               $attributes['container_guid'] = get_loggedin_userid();
+               $attributes['site_guid'] = 0;
+               $attributes['access_id'] = ACCESS_PRIVATE;
+               $attributes['time_created'] = '';
+               $attributes['time_updated'] = '';
+               $attributes['enabled'] = 'yes';
+               $attributes['tables_split'] = 2;
+               $attributes['tables_loaded'] = 0;
+               $attributes['title'] = '';
+               $attributes['description'] = '';
+
+               $this->assertIdentical($this->entity->expose_attributes(), $attributes);
+       }
+}
+
+class ElggObjectTest extends ElggObject {
+       public function expose_attributes() {
+               return $this->attributes;
+       }
+}
index 494887bc26d43b6ec1ea6cc05bf21d97f9db2818..42bbd4ba593747db221555b6e0fdfbc3ff0ba91c 100644 (file)
@@ -13,8 +13,7 @@ class ElggCoreSkeletonTest extends ElggCoreUnitTest {
         * Called before each test object.
         */
        public function __construct() {
-               // first, hook into ElggCoreUnitTest::__construct()
-               $this->__construct();
+               parent::__construct();
        }
 
        /**
@@ -35,8 +34,7 @@ class ElggCoreSkeletonTest extends ElggCoreUnitTest {
         * Called after each test object.
         */
        public function __destruct() {
-               // hook into ElggCoreUnitTest::__destruct();
-               $this->__destruct();
+               parent::__destruct();
        }
 
        /**