]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Adding unit test methods to the new Entities test.
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 6 Oct 2009 17:02:15 +0000 (17:02 +0000)
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 6 Oct 2009 17:02:15 +0000 (17:02 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3512 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/entities.php
engine/tests/core/entities.php
engine/tests/elgg_unit_test.php
engine/tests/test_skeleton.php

index a73dde60c7c3abc1e7330752f64c5a858a0c5b70..aadbdc835f70dbac5ff15b7c556ec582f7edb785 100644 (file)
         */
        function entities_test($hook, $type, $value, $params) {
                global $CONFIG;
-               $params[] = $CONFIG->path . 'engine/tests/entities.php';
+               $params[] = $CONFIG->path . 'engine/tests/core/entities.php';
                return $params;
        }
        
index e8013b1fc2f907d9dfc34d19012fefadac99616f..37960c3af5951489200ff34b7a84fdcc4651d711 100644 (file)
@@ -1,52 +1,73 @@
 <?php
 /**
  * Elgg Test ElggEntities
- * 
+ *
  * @package Elgg
  * @subpackage Test
  * @author Curverider Ltd
  * @link http://elgg.org/
  */
 class ElggCoreEntityTest extends ElggCoreUnitTest {
-
-       /**
-        * Called before each test object.
-        */
-       public function __construct() {
-
-       }
-
        /**
         * Called before each test method.
         */
        public function setUp() {
-               
-
+               $this->entity = new ElggEntityTest();
        }
 
        /**
         * Called after each test method.
         */
        public function tearDown() {
-
-
+               unset($this->entity);
        }
 
        /**
-        * Called after each test object.
+        * Tests the protected attributes
         */
-       public function __destruct() {
-
+       public function testElggEntityAttributes() {
+               $test_attributes = array();
+               $test_attributes['guid'] = '';
+               $test_attributes['type'] = '';
+               $test_attributes['subtype'] = '';
+               $test_attributes['owner_guid'] = get_loggedin_userid();
+               $test_attributes['container_guid'] = get_loggedin_userid();
+               $test_attributes['site_guid'] = 0;
+               $test_attributes['access_id'] = ACCESS_PRIVATE;
+               $test_attributes['time_created'] = '';
+               $test_attributes['time_updated'] = '';
+               $test_attributes['enabled'] = 'yes';
+               $test_attributes['tables_split'] = 1;
+               $test_attributes['tables_loaded'] = 0;
 
+               $this->assertIdentical($this->entity->expose_attributes(), $test_attributes);
        }
 
-       /**
-        * A basic test that will be called and fail.
-        */
-       public function testElggEntityConstructor() {
-               $this->assertTrue(FALSE);
+       public function testElggEntityGetAndSet() {
+               $this->assertIdentical($this->entity->get('access_id'), ACCESS_PRIVATE);
+               $this->assertTrue($this->entity->set('access_id', ACCESS_PUBLIC));
+               $this->assertIdentical($this->entity->get('access_id'), ACCESS_PUBLIC);
+               $this->assertIdentical($this->entity->access_id, ACCESS_PUBLIC);
+               unset($this->entity->access_id);
+               $this->assertIdentical($this->entity->access_id, '');
+
+               $this->assertFalse($this->entity->set('guid', 'error'));
+
+               $this->assertNull($this->entity->get('non_existent'));
+               $this->assertFalse(isset($this->entity->non_existent));
+               $this->assertTrue($this->entity->non_existent = 'test');
+               $this->assertTrue(isset($this->entity->non_existent));
+               $this->assertIdentical($this->entity->non_existent, 'test');
        }
 }
 
 // ElggEntity is an abstract class with no abstact methods.
-class ElggEntityTest extends ElggEntity { }
+class ElggEntityTest extends ElggEntity {
+       public function __construct() {
+               $this->initialise_attributes();
+       }
+
+       public function expose_attributes() {
+               return $this->attributes;
+       }
+}
index 79c3d375cbe857e7453a10092c9bf0cf32d46fea..d9841099bc0b3fdb648f702e171ae4d81a18ae5c 100755 (executable)
@@ -6,7 +6,7 @@ abstract class ElggCoreUnitTest extends UnitTestCase
        {
                parent::__construct();
        }
-       
+
        public function __destruct()
        {
        }
index b958e7b2570ec85af9faf4941f834a912920445c..494887bc26d43b6ec1ea6cc05bf21d97f9db2818 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Elgg Test Skeleton
- * 
+ *
  * @package Elgg
  * @subpackage Test
  * @author Curverider Ltd
@@ -13,14 +13,14 @@ class ElggCoreSkeletonTest extends ElggCoreUnitTest {
         * Called before each test object.
         */
        public function __construct() {
-
+               // first, hook into ElggCoreUnitTest::__construct()
+               $this->__construct();
        }
 
        /**
         * Called before each test method.
         */
        public function setUp() {
-               
 
        }
 
@@ -29,15 +29,14 @@ class ElggCoreSkeletonTest extends ElggCoreUnitTest {
         */
        public function tearDown() {
 
-
        }
 
        /**
         * Called after each test object.
         */
        public function __destruct() {
-
-
+               // hook into ElggCoreUnitTest::__destruct();
+               $this->__destruct();
        }
 
        /**