]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Merged d423aee393458d6827db from 1.7 to master.
authorBrett Profitt <brett.profitt@gmail.com>
Sun, 3 Jul 2011 20:52:33 +0000 (16:52 -0400)
committerBrett Profitt <brett.profitt@gmail.com>
Sun, 3 Jul 2011 20:52:33 +0000 (16:52 -0400)
Fixes #3552. Addess ACL unit tests. These currently fail because of #3522.

git-svn-id: http://code.elgg.org/elgg/branches/1.7@9202 36083f99-b078-4883-b0ff-0f9b5a30f544

Conflicts:

engine/lib/access.php

engine/lib/access.php
engine/tests/api/access_collections.php [new file with mode: 0644]

index cde3d256f5f5e702760deb3bc7f141512f6c00ee..303152816fe7680ab0c250b5958838b53d0b2712 100644 (file)
@@ -956,9 +956,20 @@ function elgg_override_permissions_hook() {
        return NULL;
 }
 
+/**
+ * Runs unit tests for the entities object.
+ */
+function access_test($hook, $type, $value, $params) {
+       global $CONFIG;
+       $value[] = $CONFIG->path . 'engine/tests/api/access_collections.php';
+       return $value;
+}
+
 // This function will let us know when 'init' has finished
 elgg_register_event_handler('init', 'system', 'access_init', 9999);
 
 // For overrided permissions
 elgg_register_plugin_hook_handler('permissions_check', 'all', 'elgg_override_permissions_hook');
 elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'elgg_override_permissions_hook');
+
+elgg_register_plugin_hook('unit_test', 'system', 'access_test');
diff --git a/engine/tests/api/access_collections.php b/engine/tests/api/access_collections.php
new file mode 100644 (file)
index 0000000..060587d
--- /dev/null
@@ -0,0 +1,170 @@
+<?php
+/**
+ * Access Collections tests
+ *
+ * @package Elgg
+ * @subpackage Test
+ */
+class ElggCoreAccessCollectionsTest extends ElggCoreUnitTest {
+
+       /**
+        * Called before each test object.
+        */
+       public function __construct() {
+               parent::__construct();
+
+               $this->dbPrefix = get_config("dbprefix");
+
+               $user = new ElggUser();
+               $user->username = 'test_user_' . rand();
+               $user->email = 'fake_email@fake.com' . rand();
+               $user->name = 'fake user';
+               $user->access_id = ACCESS_PUBLIC;
+               $user->salt = generate_random_cleartext_password();
+               $user->password = generate_user_password($user, rand());
+               $user->owner_guid = 0;
+               $user->container_guid = 0;
+               $user->save();
+
+               $this->user = $user;
+       }
+
+       /**
+        * Called before each test method.
+        */
+       public function setUp() {
+
+       }
+
+       /**
+        * Called after each test method.
+        */
+       public function tearDown() {
+               // do not allow SimpleTest to interpret Elgg notices as exceptions
+               $this->swallowErrors();
+       }
+
+       /**
+        * Called after each test object.
+        */
+       public function __destruct() {
+               // all __destruct() code should go above here
+               $this->user->delete();
+               parent::__destruct();
+       }
+
+       public function testCreateGetDeleteACL() {
+               global $DB_QUERY_CACHE;
+               
+               $acl_name = 'test access collection';
+               $acl_id = create_access_collection($acl_name);
+
+               $this->assertTrue(is_int($acl_id));
+
+               $q = "SELECT * FROM {$this->dbPrefix}access_collections WHERE id = $acl_id";
+               $acl = get_data_row($q);
+
+               $this->assertEqual($acl->id, $acl_id);
+
+               if ($acl) {
+                       $DB_QUERY_CACHE = array();
+                       
+                       $this->assertEqual($acl->name, $acl_name);
+
+                       $result = delete_access_collection($acl_id);
+                       $this->assertTrue($result);
+
+                       $q = "SELECT * FROM {$this->dbPrefix}access_collections WHERE id = $acl_id";
+                       $data = get_data($q);
+                       $this->assertFalse($data);
+               }
+       }
+
+       public function testAddRemoveUserToACL() {
+               $acl_id = create_access_collection('test acl');
+
+               $result = add_user_to_access_collection($this->user->guid, $acl_id);
+               $this->assertTrue($result);
+
+               if ($result) {
+                       $result = remove_user_from_access_collection($this->user->guid, $acl_id);
+                       $this->assertTrue($result);
+               }
+
+               delete_access_collection($acl_id);
+       }
+
+       public function testUpdateACL() {
+               // another fake user to test with
+               $user = new ElggUser();
+               $user->username = 'test_user_' . rand();
+               $user->email = 'fake_email@fake.com' . rand();
+               $user->name = 'fake user';
+               $user->access_id = ACCESS_PUBLIC;
+               $user->salt = generate_random_cleartext_password();
+               $user->password = generate_user_password($user, rand());
+               $user->owner_guid = 0;
+               $user->container_guid = 0;
+               $user->save();
+
+               $acl_id = create_access_collection('test acl');
+
+               $member_lists = array(
+                       // adding
+                       array(
+                               $this->user->guid,
+                               $user->guid
+                       ),
+                       // removing one, keeping one.
+                       array(
+                               $user->guid
+                       ),
+                       // removing one, adding one
+                       array(
+                               $this->user->guid,
+                       ),
+                       // removing all.
+                       array()
+               );
+
+               foreach ($member_lists as $members) {
+                       $result = update_access_collection($acl_id, $members);
+                       $this->assertTrue($result);
+
+                       if ($result) {
+                               $q = "SELECT * FROM {$this->dbPrefix}access_collection_membership
+                                       WHERE access_collection_id = $acl_id";
+                               $data = get_data($q);
+
+                               if (count($members) == 0) {
+                                       $this->assertFalse($data);
+                               } else {
+                                       $this->assertEqual(count($members), count($data));
+                               }
+                               foreach ($data as $row) {
+                                       $this->assertTrue(in_array($row->user_guid, $members));
+                               }
+                       }
+               }
+
+               delete_access_collection($acl_id);
+               $user->delete();
+       }
+
+       // groups interface
+       public function testNewGroupCreateACL() {
+
+       }
+
+       public function testDeleteGroupDeleteACL() {
+
+       }
+
+       public function testJoinGroupJoinACL() {
+
+       }
+
+       public function testLeaveGroupLeaveACL() {
+
+       }
+}