Support for larger size codes (such as SNOMED US Extension codes)
[openemr.git] / gacl / test_suite / acl_tests.php
blobb44498ce846a0dabf270db7897d77f8168705eb2
1 <?php
3 class acl_setup {
5 var $gacl_api;
7 var $aco_section = array();
8 var $aco = array();
10 var $aro_section = array();
11 var $aro = array();
12 var $aro_group = array();
14 var $axo_section = array();
15 var $axo = array();
16 var $axo_group = array();
18 var $acl = array();
20 function acl_setup() {
21 $this->gacl_api = &$GLOBALS['gacl_api'];
24 function setup() {
25 // ACO
26 $this->aco_section[] = $this->gacl_api->add_object_section ('Test','test_aco',0,0,'ACO');
27 $this->aco[] = $this->gacl_api->add_object ('test_aco','Access','access',0,0,'ACO');
29 // ARO
30 $this->aro_section[] = $this->gacl_api->add_object_section ('Human', 'test_human',0,0,'ARO');
31 $this->aro[] = $this->gacl_api->add_object ('test_human','Han','han',0,0,'ARO');
32 $this->aro[] = $this->gacl_api->add_object ('test_human','Lando','lando',0,0,'ARO');
33 $this->aro[] = $this->gacl_api->add_object ('test_human','Obi-wan','obiwan',0,0,'ARO');
34 $this->aro[] = $this->gacl_api->add_object ('test_human','Luke','luke',0,0,'ARO');
36 $this->aro_section[] = $this->gacl_api->add_object_section ('Android', 'test_android',0,0,'ARO');
37 $this->aro[] = $this->gacl_api->add_object ('test_android','R2D2','r2d2',0,0,'ARO');
38 $this->aro[] = $this->gacl_api->add_object ('test_android','C3PO','c3po',0,0,'ARO');
40 $this->aro_section[] = $this->gacl_api->add_object_section ('Alien', 'test_alien',0,0,'ARO');
41 $this->aro[] = $this->gacl_api->add_object ('test_alien','Chewie','chewie',0,0,'ARO');
42 $this->aro[] = $this->gacl_api->add_object ('test_alien','Hontook','hontook',0,0,'ARO');
44 // ARO groups
45 $this->aro_group['root'] = $this->gacl_api->add_group('millennium_falcon_passengers', 'Millennium Falcon Passengers',0,'ARO');
46 $this->aro_group['crew'] = $this->gacl_api->add_group('crew', 'Crew',$this->aro_group['root'],'ARO');
47 $this->aro_group['passengers'] = $this->gacl_api->add_group('passengers','Passengers',$this->aro_group['root'],'ARO');
48 $this->aro_group['jedi'] = $this->gacl_api->add_group('jedi', 'Jedi',$this->aro_group['passengers'],'ARO');
49 $this->aro_group['engineers'] = $this->gacl_api->add_group('engineers', 'Engineers',$this->aro_group['root'],'ARO');
51 // add AROs to groups
52 $this->gacl_api->add_group_object($this->aro_group['crew'],'test_alien','chewie','ARO');
53 $this->gacl_api->add_group_object($this->aro_group['crew'],'test_human','han','ARO');
54 $this->gacl_api->add_group_object($this->aro_group['crew'],'test_human','lando','ARO');
56 $this->gacl_api->add_group_object($this->aro_group['passengers'],'test_android','c3po','ARO');
57 $this->gacl_api->add_group_object($this->aro_group['passengers'],'test_android','r2d2','ARO');
59 $this->gacl_api->add_group_object($this->aro_group['jedi'],'test_human','luke','ARO');
60 $this->gacl_api->add_group_object($this->aro_group['jedi'],'test_human','obiwan','ARO');
62 $this->gacl_api->add_group_object($this->aro_group['engineers'],'test_alien','hontook','ARO');
63 $this->gacl_api->add_group_object($this->aro_group['engineers'],'test_android','r2d2','ARO');
64 $this->gacl_api->add_group_object($this->aro_group['engineers'],'test_human','han','ARO');
66 // AXO
67 $this->axo_section[] = $this->gacl_api->add_object_section ('Location', 'test_location',0,0,'AXO');
68 $this->axo[] = $this->gacl_api->add_object ('test_location','Engines','engines',0,0,'AXO');
69 $this->axo[] = $this->gacl_api->add_object ('test_location','Lounge','lounge',0,0,'AXO');
70 $this->axo[] = $this->gacl_api->add_object ('test_location','Cockpit','cockpit',0,0,'AXO');
71 $this->axo[] = $this->gacl_api->add_object ('test_location','Guns','guns',0,0,'AXO');
73 // AXO Groups
74 $this->axo_group['locations'] = $this->gacl_api->add_group('locations', 'Locations',0,'AXO');
76 // add AXOs to groups
77 $this->gacl_api->add_group_object($this->axo_group['locations'],'test_location','engines','AXO');
78 $this->gacl_api->add_group_object($this->axo_group['locations'],'test_location','lounge','AXO');
79 $this->gacl_api->add_group_object($this->axo_group['locations'],'test_location','cockpit','AXO');
80 $this->gacl_api->add_group_object($this->axo_group['locations'],'test_location','guns','AXO');
82 // create ACLs
83 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),NULL,array($this->aro_group['crew']),NULL,array($this->axo_group['locations']),1,1,NULL,'Crew can go anywhere');
84 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),array('test_alien'=>array('chewie')),NULL,array('test_location'=>array('engines')),NULL,0,1,NULL,'Chewie can\'t access the engines');
86 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),NULL,array($this->aro_group['passengers']),array('test_location'=>array('lounge')),NULL,1,1,NULL,'Passengers are allowed in the lounge');
88 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),NULL,array($this->aro_group['jedi']),array('test_location'=>array('cockpit')),NULL,1,1,NULL,'Jedi are allowed in the cockpit');
90 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),array('test_human'=>array('luke')),NULL,array('test_location'=>array('guns')),NULL,1,1,NULL,'Luke can access the guns');
92 $this->acl[] = $this->gacl_api->add_acl(array('test_aco'=>array('access')),NULL,array($this->aro_group['engineers']),array('test_location'=>array('engines','guns')),NULL,1,1,NULL,'Engineers can access the engines and guns');
96 function teardown() {
97 // delete ACLs
98 foreach ($this->acl as $id) {
99 $this->gacl_api->del_acl($id);
102 // delete AXO groups
103 foreach (array_reverse($this->axo_group) as $id) {
104 $this->gacl_api->del_group($id,TRUE,'AXO');
107 // delete AXOs
108 foreach ($this->axo as $id) {
109 $this->gacl_api->del_object($id,'AXO');
112 // delete AXO sections
113 foreach ($this->axo_section as $id) {
114 $this->gacl_api->del_object_section($id,'AXO');
117 // delete ARO groups
118 foreach (array_reverse($this->aro_group) as $id) {
119 $this->gacl_api->del_group($id,TRUE,'ARO');
122 // delete AROs
123 foreach ($this->aro as $id) {
124 $this->gacl_api->del_object($id,'ARO');
127 // delete ARO sections
128 foreach ($this->aro_section as $id) {
129 $this->gacl_api->del_object_section($id,'ARO');
132 // delete ACOs
133 foreach ($this->aco as $id) {
134 $this->gacl_api->del_object($id,'ACO');
137 // delete ACO sections
138 foreach ($this->aco_section as $id) {
139 $this->gacl_api->del_object_section($id,'ACO');
144 class acl_test extends gacl_test_case {
146 var $acl_setup;
148 function acl_test($name) {
149 $this->gacl_test_case($name);
150 $this->acl_setup = &$GLOBALS['acl_setup'];
153 function test_check_luke_lounge() {
154 $result = $this->gacl_api->acl_check('test_aco','access','test_human','luke','test_location','lounge');
155 $message = 'Luke should have access to the Lounge';
156 $this->assertEquals(TRUE, $result, $message);
159 function test_check_luke_engines() {
160 $result = $this->gacl_api->acl_check('test_aco','access','test_human','luke','test_location','engines');
161 $message = 'Luke shouldn\'t have access to the Engines';
162 $this->assertEquals(FALSE, $result, $message);
165 function test_check_chewie_guns() {
166 $result = $this->gacl_api->acl_check('test_aco','access','test_alien','chewie','test_location','guns');
167 $message = 'Chewie should have access to the Guns';
168 $this->assertEquals(TRUE, $result, $message);
171 function test_check_chewie_engines() {
172 $result = $this->gacl_api->acl_check('test_aco','access','test_alien','chewie','test_location','engines');
173 $message = 'Chewie shouldn\'t have access to the Engines';
174 $this->assertEquals(FALSE, $result, $message);
177 function test_query_luke_lounge() {
178 $result = $this->gacl_api->acl_query('test_aco','access','test_human','luke','test_location','lounge');
179 $expected = array(
180 'acl_id' => $this->acl_setup->acl[2],
181 'return_value' => '',
182 'allow' => TRUE
184 $message = 'Luke should have access to the Lounge';
186 $this->assertEquals($expected, $result, $message);
190 // check no previous tests failed
191 if ( $result->failureCount() > 0 )
193 echo '<p>Previous test failed, not running ACL check tests.</p>';
194 return;
197 echo '<p>Running ACL tests...<br />';
199 // set up test environment
200 $acl_setup = new acl_setup;
202 echo '&nbsp;&nbsp;Setting Up... ';
203 $acl_setup->setup();
204 echo 'Done<br/>';
206 // run tests & destroy suite
207 $suite = new gacl_test_suite('acl_test');
209 echo '&nbsp;&nbsp;Running Tests... ';
210 $suite->run($result);
211 echo 'Done<br />';
212 unset ($suite);
214 // tear down test environment;
215 echo '&nbsp;&nbsp;Cleaning Up... ';
216 $acl_setup->teardown();
217 unset ($acl_setup);
218 echo 'Done<br />';
220 echo '<b>Done</b></p>';
221 // done.