quick clarification in globals description
[openemr.git] / gacl / admin / test.php
blob513019a28f466d4b5c08c094e38d6deef144f0d9
1 <?php
2 $debug=1;
3 require_once("gacl_admin.inc.php");
5 /*
6 $test = $gacl->add_group_object(10, 'user','10');
7 $gacl->showarray($test);
9 $test = $gacl->add_group_object(10, 'user','10');
10 $gacl->showarray($test);
12 $test = $gacl->del_group_object(10, 'user','10');
13 $gacl->showarray($test);
15 $test = $gacl->del_group_object(10, 'user','10');
16 $gacl->showarray($test);
19 //$test = $gacl->acl_query('system','login','users','john_doe',NULL, NULL, NULL, NULL, TRUE);
20 //showarray($test);
23 $test = $gacl_api->get_group_objects(14,'ARO','RECURSE');
24 showarray($test);
26 $test = $gacl_api->get_group_objects(14,'ARO');
27 showarray($test);
30 $group_ids = array(14);
31 $test = $gacl_api->acl_get_group_path($group_ids);
32 showarray($test);
33 $test = $gacl_api->get_group_objects(14,'ARO');
34 showarray($test);
37 //$gacl_api->clean_path_to_root(ARO);
38 //$gacl_api->clean_path_to_root(AXO);
41 $gacl_api->add_acl( array('system' => array('login', 'enabled', 'login')),
42 array('users' => array(1)),
43 array(10,12,10),
44 NULL,
45 NULL,
46 TRUE,
47 TRUE,
48 666,
49 'NOTE');
53 $gacl_api->is_conflicting_acl(
54 array('system' => array('login')),
55 array('accounts' => array(1)),
56 array(99),
57 array('projects' => array(99)),
58 array(99));
60 //$gacl_api->consolidated_edit_acl('system', 'add_pop','accounts',1, 99);
62 //$gacl_api->search_acl('system','add_pop','accounts',1, 'Browsers','projects',5599,'Projects',99);
65 $gacl_api->shift_acl( 18,
66 array('accounts' => array(1)),
67 array(14),
68 array('projects' => array(5599)),
69 array(23),
70 array('system' => array('add_pop'))
74 $gacl_api->append_acl( 18,
75 array('accounts' => array(1,2,3,4)),
76 array(14),
77 array('projects' => array(5599)),
78 array(23),
79 array('system' => array('add_pop'))
84 $gacl_api->add_acl( array('system' => array(99)),
85 array('accounts' => array(99)),
86 array(99),
87 array('projects' => array(99)),
88 array(99),
89 TRUE,
90 TRUE,
91 666,
92 'NOTE');
95 //$rows = $rs->GetRows();
96 //showarray($rows);
100 $query = '
101 SELECT a.value AS a_value, a.name AS a_name,
102 b.value AS b_value, b.name AS b_name,
103 c.value AS c_value, c.name AS c_name,
104 d.value AS d_value, d.name AS d_name
105 FROM aco_sections a,
106 aco b,
107 aro_sections c,
108 aro d
109 WHERE a.value=b.section_value
110 AND c.value=d.section_value
111 ORDER BY a.value, b.value, c.value, d.value';
112 //$rs = $db->Execute($query);
113 //$rows = $rs->GetRows();
114 $rs = $db->pageexecute($query, 100, 2);
115 showarray($rows);
116 $rows = $rs->GetRows();
117 showarray($rows);
120 //$test=$gacl-> acl_query('system', 'email_pw', 'users', '1');
121 //showarray($test);
123 //Test object deleting.
124 //$gacl_api->del_object(10,'ARO', TRUE);
125 //$gacl_api->del_object_section(10,'ACO',TRUE);
128 //Test AXO's
129 //function acl_query($aco_section_value, $aco_value, $aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL, $root_aro_group_id=NULL, $root_axo_group_id=NULL) {
130 $test1= acl_query('system','login','users', '1');
131 showarray($test1);
133 $test2=acl_query('system','login','users', '1','projects','1');
134 showarray($test2);
137 //Test subtree'ing
139 $test=acl_get_groups('test_section2','user1',0);
140 showarray($test);
142 $test=acl_get_groups('test_section2','user1');
143 showarray($test);
147 //require_once('../Cache_Lite.php');
148 require_once('./profiler.inc');
149 $profiler = new Profiler(true,true);
151 $options = array(
152 'caching' => true,
153 'cacheDir' => '/tmp/phpgacl_cache',
154 'lifeTime' => 100
157 //$Cache_Lite = new Hashed_Cache_Lite($options);
158 $Cache_Lite = new Cache_Lite($options);
160 $data = '0123456789';
161 $Cache_Lite->save($data,'123');
163 $profiler->startTimer( "acl_query()");
164 //Test memory caching.
165 for ($i=0; $i < 2; $i++) {
166 //$Cache_Lite->save($data,'123'.$i);
168 $data = $Cache_Lite->get('123');
169 //echo "$data<br>\n";
171 $profiler->stopTimer( "acl_query()");
173 $profiler->printTimers();
176 //Test multi-layer ACOs
177 $test = acl_query(array(21,19), 10);
178 showarray($test);
181 //Stress test.
183 //Cleanup
184 $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test");
185 $del_aco_ids = $gacl_api->get_aco($aco_section_id);
186 foreach ($del_aco_ids as $del_aco_id) {
187 $gacl_api->del_aco($del_aco_id);
189 $gacl_api->del_aco_section($aco_section_id);
191 $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test");
192 $del_aro_ids = $gacl_api->get_aro($aro_section_id);
193 foreach ($del_aro_ids as $del_aro_id) {
194 $gacl_api->del_aro($del_aro_id);
196 $gacl_api->del_aro_section($aro_section_id);
198 //Get all ACLs
199 $query = "select id from acl";
200 $rs = $db->GetCol($query);
202 foreach($rs as $del_acl_id) {
203 $gacl_api->del_acl($del_acl_id);
208 $max_aco=10;
209 $max_aro=50;
211 $max_acl=100;
212 $min_rand_aco=1;
213 $max_rand_aco=9;
214 $min_rand_aro=1;
215 $max_rand_aro=9;
217 //Seed random.
218 srand ((float) microtime() * 10000000);
220 //Grab ACO Section_id
221 $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test");
223 if (!$aco_section_id) {
224 //Add an ACO section.
225 $aco_section_id = $gacl_api->add_aco_section("Stress Test", 999,999);
226 $gacl_api->debug_text("Stress Test: ACO Section ID: $aco_section_id");
229 //Add 100 random ACO's
230 if ($aco_section_id) {
232 for ($i=0; $i < $max_aco; $i++) {
233 $aco_id = $gacl_api->get_aco_id("Stress Test ACO #$i");
235 if (!$aco_id) {
236 //Add ACO.
237 $aco_id = $gacl_api->add_aco($aco_section_id, "Stress Test ACO #$i",$i, $i);
241 $aco_ids = $gacl_api->get_aco($aco_section_id);
242 //showarray($aco_ids);
244 //Grab ARO section id
245 $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test");
247 if (!$aro_section_id) {
248 //Add an ACO section.
249 $aro_section_id = $gacl_api->add_aro_section("Stress Test", 999,999);
250 $gacl_api->debug_text("Stress Test: ARO Section ID: $aro_section_id");
253 //Add 10,000 random ARO's
254 if ($aro_section_id) {
256 for ($i=0; $i < $max_aro; $i++) {
257 $aro_id = $gacl_api->get_aro_id("Stress Test ARO #$i");
259 if (!$aro_id) {
260 //Add ARO.
261 $aro_id = $gacl_api->add_aro($aro_section_id, "Stress Test ARO #$i",$i, $i);
265 $aro_ids = $gacl_api->get_aro($aro_section_id);
266 //showarray($aro_ids);
268 //Create random ACL's using the above stress test ACO/AROs
269 if (count($aco_ids) > 1 AND count($aro_ids) > 1) {
270 for ($i=0; $i < $max_acl; $i++) {
271 //Get random ACO IDS
272 $rand_aco_keys = array_rand($aco_ids, mt_rand($min_rand_aco, $max_rand_aco) );
274 unset($rand_aco_ids);
275 foreach ($rand_aco_keys as $rand_aco_key) {
276 $rand_aco_ids[] = $aco_ids[$rand_aco_key];
279 //Get random ARO IDS
280 $rand_aro_keys = array_rand($aro_ids, mt_rand($min_rand_aro, $max_rand_aro));
282 unset($rand_aro_ids);
283 foreach ($rand_aro_keys as $rand_aro_key) {
284 $rand_aro_ids[] = $aro_ids[$rand_aro_key];
287 //Random ALLOW
288 $allow = mt_rand(0,1);
290 $gacl_api->debug_text("Inserting ACL with ". count($rand_aco_ids) ." ACOs and ". count($rand_aro_ids) ." AROs - Allow: $allow");
291 $gacl_api->add_acl($rand_aco_ids, $rand_aro_ids, NULL, $allow, 1);
296 //Create much more Decoy data
297 $max_aco=100;
298 $max_aro=4000;
300 $max_acl=1000;
301 $min_rand_aco=1;
302 $max_rand_aco=10;
303 $min_rand_aro=1;
304 $max_rand_aro=10;
306 //Seed random.
307 srand ((float) microtime() * 10000000);
309 //Grab ACO Section_id
310 $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test Decoy");
312 if (!$aco_section_id) {
313 //Add an ACO section.
314 $aco_section_id = $gacl_api->add_aco_section("Stress Test Decoy", 1000,1000);
315 $gacl_api->debug_text("Stress Test: ACO Section ID: $aco_section_id");
318 //Add 100 random ACO's
319 if ($aco_section_id) {
321 for ($i=0; $i < $max_aco; $i++) {
322 $aco_id = $gacl_api->get_aco_id("Stress Test Decoy ACO #$i");
324 if (!$aco_id) {
325 //Add ACO.
326 $aco_id = $gacl_api->add_aco($aco_section_id, "Stress Test ACO Decoy #$i",$i, $i);
330 $aco_ids = $gacl_api->get_aco($aco_section_id);
331 //showarray($aco_ids);
333 //Grab ARO section id
334 $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test Decoy");
336 if (!$aro_section_id) {
337 //Add an ACO section.
338 $aro_section_id = $gacl_api->add_aro_section("Stress Test Decoy", 1000,1000);
339 $gacl_api->debug_text("Stress Test: ARO Section ID: $aro_section_id");
342 //Add 10,000 random ARO's
343 if ($aro_section_id) {
345 for ($i=0; $i < $max_aro; $i++) {
346 $aro_id = $gacl_api->get_aro_id("Stress Test Decoy ARO #$i");
348 if (!$aro_id) {
349 //Add ARO.
350 $aro_id = $gacl_api->add_aro($aro_section_id, "Stress Test Decoy ARO #$i",$i, $i);
354 $aro_ids = $gacl_api->get_aro($aro_section_id);
355 //showarray($aro_ids);
357 //Create random ACL's using the above stress test ACO/AROs
358 if (count($aco_ids) > 1 AND count($aro_ids) > 1) {
359 for ($i=0; $i < $max_acl; $i++) {
360 //Get random ACO IDS
361 $rand_aco_keys = array_rand($aco_ids, mt_rand($min_rand_aco, $max_rand_aco) );
363 unset($rand_aco_ids);
364 foreach ($rand_aco_keys as $rand_aco_key) {
365 $rand_aco_ids[] = $aco_ids[$rand_aco_key];
368 //Get random ARO IDS
369 $rand_aro_keys = array_rand($aro_ids, mt_rand($min_rand_aro, $max_rand_aro));
371 unset($rand_aro_ids);
372 foreach ($rand_aro_keys as $rand_aro_key) {
373 $rand_aro_ids[] = $aro_ids[$rand_aro_key];
376 //Random ALLOW
377 $allow = mt_rand(0,1);
379 $gacl_api->debug_text("Inserting ACL with ". count($rand_aco_ids) ." ACOs and ". count($rand_aro_ids) ." AROs - Allow: $allow");
380 $gacl_api->add_acl($rand_aco_ids, $rand_aro_ids, NULL, $allow, 1);
392 //Test subtree'ing
393 $aco_id=10;
394 $aro_id=22;
395 $root_group_id=30;
397 $test=acl_query($aco_id,$aro_id,$root_group_id);
398 showarray($test);
400 $aco_id=10;
401 $aro_id=22;
402 $root_group_id=33;
404 $test=acl_query($aco_id,$aro_id,$root_group_id);
405 showarray($test);
409 //Populate the ARO's
410 $max_aros = 100;
411 for ($i=0; $i < $max_aros; $i++) {
413 $aro_id = $gacl_api->add_aro(41,"$i First $i Last", $i, $i);
415 if ($aro_id) {
416 $gacl_api->debug_text("ARO ID: $aro_id");
417 } else {
418 $gacl_api->debug_text("Insert ARO ID FAILED!");