~tsep-dev/tsep/0.9-beta

« back to all changes in this revision

Viewing changes to branches/symfony/cake/tests/cases/libs/controller/components/acl.test.php

  • Committer: geoffreyfishing
  • Date: 2011-01-11 23:46:12 UTC
  • Revision ID: svn-v4:ae0de26e-ed09-4cbe-9a20-e40b4c60ac6c::125
Created a symfony branch for future migration to symfony

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * AclComponentTest file
 
4
 *
 
5
 * PHP versions 4 and 5
 
6
 *
 
7
 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
 
8
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
9
 *
 
10
 *  Licensed under The Open Group Test Suite License
 
11
 *  Redistributions of files must retain the above copyright notice.
 
12
 *
 
13
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
14
 * @link          http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
 
15
 * @package       cake
 
16
 * @subpackage    cake.tests.cases.libs.controller.components
 
17
 * @since         CakePHP(tm) v 1.2.0.5435
 
18
 * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
 
19
 */
 
20
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
 
21
        define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
 
22
}
 
23
App::import(array('controller' .DS . 'components' . DS . 'acl', 'model' . DS . 'db_acl'));
 
24
 
 
25
/**
 
26
 * AclNodeTwoTestBase class
 
27
 *
 
28
 * @package       cake
 
29
 * @subpackage    cake.tests.cases.libs.controller.components
 
30
 */
 
31
class AclNodeTwoTestBase extends AclNode {
 
32
 
 
33
/**
 
34
 * useDbConfig property
 
35
 *
 
36
 * @var string 'test_suite'
 
37
 * @access public
 
38
 */
 
39
        var $useDbConfig = 'test_suite';
 
40
 
 
41
/**
 
42
 * cacheSources property
 
43
 *
 
44
 * @var bool false
 
45
 * @access public
 
46
 */
 
47
        var $cacheSources = false;
 
48
}
 
49
 
 
50
/**
 
51
 * AroTwoTest class
 
52
 *
 
53
 * @package       cake
 
54
 * @subpackage    cake.tests.cases.libs.controller.components
 
55
 */
 
56
class AroTwoTest extends AclNodeTwoTestBase {
 
57
 
 
58
/**
 
59
 * name property
 
60
 *
 
61
 * @var string 'AroTwoTest'
 
62
 * @access public
 
63
 */
 
64
        var $name = 'AroTwoTest';
 
65
 
 
66
/**
 
67
 * useTable property
 
68
 *
 
69
 * @var string 'aro_twos'
 
70
 * @access public
 
71
 */
 
72
        var $useTable = 'aro_twos';
 
73
 
 
74
/**
 
75
 * hasAndBelongsToMany property
 
76
 *
 
77
 * @var array
 
78
 * @access public
 
79
 */
 
80
        var $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
 
81
}
 
82
 
 
83
/**
 
84
 * AcoTwoTest class
 
85
 *
 
86
 * @package       cake
 
87
 * @subpackage    cake.tests.cases.libs.controller.components
 
88
 */
 
89
class AcoTwoTest extends AclNodeTwoTestBase {
 
90
 
 
91
/**
 
92
 * name property
 
93
 *
 
94
 * @var string 'AcoTwoTest'
 
95
 * @access public
 
96
 */
 
97
        var $name = 'AcoTwoTest';
 
98
 
 
99
/**
 
100
 * useTable property
 
101
 *
 
102
 * @var string 'aco_twos'
 
103
 * @access public
 
104
 */
 
105
        var $useTable = 'aco_twos';
 
106
 
 
107
/**
 
108
 * hasAndBelongsToMany property
 
109
 *
 
110
 * @var array
 
111
 * @access public
 
112
 */
 
113
        var $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
 
114
}
 
115
 
 
116
/**
 
117
 * PermissionTwoTest class
 
118
 *
 
119
 * @package       cake
 
120
 * @subpackage    cake.tests.cases.libs.controller.components
 
121
 */
 
122
class PermissionTwoTest extends CakeTestModel {
 
123
 
 
124
/**
 
125
 * name property
 
126
 *
 
127
 * @var string 'PermissionTwoTest'
 
128
 * @access public
 
129
 */
 
130
        var $name = 'PermissionTwoTest';
 
131
 
 
132
/**
 
133
 * useTable property
 
134
 *
 
135
 * @var string 'aros_aco_twos'
 
136
 * @access public
 
137
 */
 
138
        var $useTable = 'aros_aco_twos';
 
139
 
 
140
/**
 
141
 * cacheQueries property
 
142
 *
 
143
 * @var bool false
 
144
 * @access public
 
145
 */
 
146
        var $cacheQueries = false;
 
147
 
 
148
/**
 
149
 * belongsTo property
 
150
 *
 
151
 * @var array
 
152
 * @access public
 
153
 */
 
154
        var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
 
155
 
 
156
/**
 
157
 * actsAs property
 
158
 *
 
159
 * @var mixed null
 
160
 * @access public
 
161
 */
 
162
        var $actsAs = null;
 
163
}
 
164
 
 
165
/**
 
166
 * DbAclTwoTest class
 
167
 *
 
168
 * @package       cake
 
169
 * @subpackage    cake.tests.cases.libs.controller.components
 
170
 */
 
171
class DbAclTwoTest extends DbAcl {
 
172
 
 
173
/**
 
174
 * construct method
 
175
 *
 
176
 * @access private
 
177
 * @return void
 
178
 */
 
179
        function __construct() {
 
180
                $this->Aro =& new AroTwoTest();
 
181
                $this->Aro->Permission =& new PermissionTwoTest();
 
182
                $this->Aco =& new AcoTwoTest();
 
183
                $this->Aro->Permission =& new PermissionTwoTest();
 
184
        }
 
185
}
 
186
 
 
187
/**
 
188
 * IniAclTest class
 
189
 *
 
190
 * @package       cake
 
191
 * @subpackage    cake.tests.cases.libs.controller.components
 
192
 */
 
193
class IniAclTest extends IniAcl {
 
194
}
 
195
 
 
196
/**
 
197
 * ACL Component Text case
 
198
 *
 
199
 * @package       cake
 
200
 * @subpackage    cake.tests.cases.libs.controller.components
 
201
 */
 
202
class AclComponentTest extends CakeTestCase {
 
203
 
 
204
/**
 
205
 * fixtures property
 
206
 *
 
207
 * @var array
 
208
 * @access public
 
209
 */
 
210
        var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
 
211
 
 
212
/**
 
213
 * startTest method
 
214
 *
 
215
 * @access public
 
216
 * @return void
 
217
 */
 
218
        function startTest() {
 
219
                $this->Acl =& new AclComponent();
 
220
        }
 
221
 
 
222
/**
 
223
 * before method
 
224
 *
 
225
 * @param mixed $method
 
226
 * @access public
 
227
 * @return void
 
228
 */
 
229
        function before($method) {
 
230
                Configure::write('Acl.classname', 'DbAclTwoTest');
 
231
                Configure::write('Acl.database', 'test_suite');
 
232
                parent::before($method);
 
233
        }
 
234
 
 
235
/**
 
236
 * tearDown method
 
237
 *
 
238
 * @access public
 
239
 * @return void
 
240
 */
 
241
        function tearDown() {
 
242
                unset($this->Acl);
 
243
        }
 
244
 
 
245
/**
 
246
 * testAclCreate method
 
247
 *
 
248
 * @access public
 
249
 * @return void
 
250
 */
 
251
        function testAclCreate() {
 
252
                $this->Acl->Aro->create(array('alias' => 'Chotchkey'));
 
253
                $this->assertTrue($this->Acl->Aro->save());
 
254
 
 
255
                $parent = $this->Acl->Aro->id;
 
256
 
 
257
                $this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
 
258
                $this->assertTrue($this->Acl->Aro->save());
 
259
 
 
260
                $this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
 
261
                $this->assertTrue($this->Acl->Aro->save());
 
262
 
 
263
                $root = $this->Acl->Aco->node('ROOT');
 
264
                $parent = $root[0]['AcoTwoTest']['id'];
 
265
 
 
266
                $this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
 
267
                $this->assertTrue($this->Acl->Aco->save());
 
268
 
 
269
                $this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
 
270
                $this->assertTrue($this->Acl->Aco->save());
 
271
        }
 
272
 
 
273
/**
 
274
 * testAclCreateWithParent method
 
275
 *
 
276
 * @access public
 
277
 * @return void
 
278
 */
 
279
        function testAclCreateWithParent() {
 
280
                $parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
 
281
                $this->Acl->Aro->create();
 
282
                $this->Acl->Aro->save(array(
 
283
                        'alias' => 'Subordinate',
 
284
                        'model' => 'User',
 
285
                        'foreign_key' => 7,
 
286
                        'parent_id' => $parent['AroTwoTest']['id']
 
287
                ));
 
288
                $result = $this->Acl->Aro->findByAlias('Subordinate', null, null, -1);
 
289
                $this->assertEqual($result['AroTwoTest']['lft'], 16);
 
290
                $this->assertEqual($result['AroTwoTest']['rght'], 17);
 
291
        }
 
292
 
 
293
/**
 
294
 * testDbAclAllow method
 
295
 *
 
296
 * @access public
 
297
 * @return void
 
298
 */
 
299
        function testDbAclAllow() {
 
300
                $this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'read'));
 
301
                $this->assertTrue($this->Acl->allow('Micheal', 'tpsReports', array('read', 'delete', 'update')));
 
302
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'update'));
 
303
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
 
304
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
 
305
 
 
306
                $this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
 
307
                $this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
 
308
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
 
309
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
 
310
                $this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
 
311
                // Michael no longer has his delete permission for tpsReports!
 
312
                $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
 
313
                $this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
 
314
 
 
315
                $this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
 
316
                $this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
 
317
                $this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
 
318
                $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
 
319
 
 
320
                $this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
 
321
                $this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
 
322
                $this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
 
323
                $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
 
324
                // Samir should still have his tpsReports/view permissions, but does not
 
325
                $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
 
326
 
 
327
                $this->expectError('DbAcl::allow() - Invalid node');
 
328
                $this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
 
329
 
 
330
                $this->expectError('DbAcl::allow() - Invalid node');
 
331
                $this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
 
332
        }
 
333
 
 
334
/**
 
335
 * testDbAclCheck method
 
336
 *
 
337
 * @access public
 
338
 * @return void
 
339
 */
 
340
        function testDbAclCheck() {
 
341
                $this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
 
342
                $this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
 
343
                $this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
 
344
                $this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
 
345
 
 
346
                $this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check.  Node references:\nAro: WRONG\nAco: tpsReports");
 
347
                $this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
 
348
 
 
349
                $this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");
 
350
                $this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
 
351
 
 
352
                $this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check.  Node references:\nAro: users\nAco: NonExistant");
 
353
                $this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
 
354
 
 
355
                $this->assertFalse($this->Acl->check(null, 'printers', 'create'));
 
356
                $this->assertFalse($this->Acl->check('managers', null, 'read'));
 
357
 
 
358
                $this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));
 
359
                $this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));
 
360
 
 
361
                $this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
 
362
        }
 
363
 
 
364
/**
 
365
 * testDbAclCascadingDeny function
 
366
 *
 
367
 * Setup the acl permissions such that Bobs inherits from admin.
 
368
 * deny Admin delete access to a specific resource, check the permisssions are inherited.
 
369
 *
 
370
 * @access public
 
371
 * @return void
 
372
 */
 
373
        function testDbAclCascadingDeny() {
 
374
                $this->Acl->inherit('Bobs', 'ROOT', '*');
 
375
                $this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));
 
376
                $this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));
 
377
                $this->Acl->deny('admin', 'tpsReports', 'delete');
 
378
                $this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
 
379
                $this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
 
380
        }
 
381
 
 
382
/**
 
383
 * testDbAclDeny method
 
384
 *
 
385
 * @access public
 
386
 * @return void
 
387
 */
 
388
        function testDbAclDeny() {
 
389
                $this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
 
390
                $this->Acl->deny('Micheal', 'smash', 'delete');
 
391
                $this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));
 
392
                $this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));
 
393
                $this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));
 
394
                $this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));
 
395
                $this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));
 
396
 
 
397
                $this->assertTrue($this->Acl->check('Samir', 'refill', '*'));
 
398
                $this->Acl->deny('Samir', 'refill', '*');
 
399
                $this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));
 
400
                $this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));
 
401
                $this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));
 
402
                $this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));
 
403
 
 
404
                $result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));
 
405
                $expected = '-1';
 
406
                $this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
 
407
 
 
408
                $this->expectError('DbAcl::allow() - Invalid node');
 
409
                $this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
 
410
        }
 
411
 
 
412
/**
 
413
 * testAclNodeLookup method
 
414
 *
 
415
 * @access public
 
416
 * @return void
 
417
 */
 
418
        function testAclNodeLookup() {
 
419
                $result = $this->Acl->Aro->node('root/users/Samir');
 
420
                $expected = array(
 
421
                        array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),
 
422
                        array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),
 
423
                        array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))
 
424
                );
 
425
                $this->assertEqual($result, $expected);
 
426
 
 
427
                $result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');
 
428
                $expected = array(
 
429
                        array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),
 
430
                        array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),
 
431
                        array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),
 
432
                        array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),
 
433
                );
 
434
                $this->assertEqual($result, $expected);
 
435
        }
 
436
 
 
437
/**
 
438
 * testDbInherit method
 
439
 *
 
440
 * @access public
 
441
 * @return void
 
442
 */
 
443
        function testDbInherit() {
 
444
                //parent doesn't have access inherit should still deny
 
445
                $this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
 
446
                $this->Acl->inherit('Milton', 'smash', 'delete');
 
447
                $this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
 
448
 
 
449
                //inherit parent
 
450
                $this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
 
451
                $this->Acl->inherit('Milton', 'smash', 'read');
 
452
                $this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
 
453
        }
 
454
 
 
455
/**
 
456
 * testDbGrant method
 
457
 *
 
458
 * @access public
 
459
 * @return void
 
460
 */
 
461
        function testDbGrant() {
 
462
                $this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));
 
463
                $this->Acl->grant('Samir', 'tpsReports', 'create');
 
464
                $this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));
 
465
 
 
466
                $this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));
 
467
                $this->Acl->grant('Micheal', 'view', array('read', 'create', 'update'));
 
468
                $this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));
 
469
                $this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));
 
470
                $this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
 
471
                $this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
 
472
 
 
473
                $this->expectError('DbAcl::allow() - Invalid node');
 
474
                $this->assertFalse($this->Acl->grant('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
 
475
        }
 
476
 
 
477
/**
 
478
 * testDbRevoke method
 
479
 *
 
480
 * @access public
 
481
 * @return void
 
482
 */
 
483
        function testDbRevoke() {
 
484
                $this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));
 
485
                $this->Acl->revoke('Bobs', 'tpsReports', 'read');
 
486
                $this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));
 
487
 
 
488
                $this->assertTrue($this->Acl->check('users', 'printers', 'read'));
 
489
                $this->Acl->revoke('users', 'printers', 'read');
 
490
                $this->assertFalse($this->Acl->check('users', 'printers', 'read'));
 
491
                $this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
 
492
                $this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
 
493
 
 
494
                $this->expectError('DbAcl::allow() - Invalid node');
 
495
                $this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
 
496
        }
 
497
 
 
498
/**
 
499
 * testStartup method
 
500
 *
 
501
 * @access public
 
502
 * @return void
 
503
 */
 
504
        function testStartup() {
 
505
                $controller = new Controller();
 
506
                $this->assertTrue($this->Acl->startup($controller));
 
507
        }
 
508
 
 
509
/**
 
510
 * testIniReadConfigFile
 
511
 *
 
512
 * @access public
 
513
 * @return void
 
514
 */
 
515
        function testIniReadConfigFile() {
 
516
                Configure::write('Acl.classname', 'IniAclTest');
 
517
                unset($this->Acl);
 
518
                $this->Acl = new AclComponent();
 
519
                $iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
 
520
                $result = $this->Acl->_Instance->readConfigFile($iniFile);
 
521
                $expected = array(
 
522
                        'admin' => array(
 
523
                                'groups' => 'administrators',
 
524
                                'allow' => '',
 
525
                                'deny' => 'ads',
 
526
                        ),
 
527
                        'paul' => array(
 
528
                                'groups' => 'users',
 
529
                                'allow' =>'',
 
530
                                'deny' => '',
 
531
                        ),
 
532
                        'jenny' => array(
 
533
                                'groups' => 'users',
 
534
                                'allow' => 'ads',
 
535
                                'deny' => 'images, files',
 
536
                        ),
 
537
                        'nobody' => array(
 
538
                                'groups' => 'anonymous',
 
539
                                'allow' => '',
 
540
                                'deny' => '',
 
541
                        ),
 
542
                        'administrators' => array(
 
543
                                'deny' => '',
 
544
                                'allow' => 'posts, comments, images, files, stats, ads',
 
545
                        ),
 
546
                        'users' => array(
 
547
                                'allow' => 'posts, comments, images, files',
 
548
                                'deny' => 'stats, ads',
 
549
                        ),
 
550
                        'anonymous' => array(
 
551
                                'allow' => '',
 
552
                                'deny' => 'posts, comments, images, files, stats, ads',
 
553
                        ),
 
554
                );
 
555
                $this->assertEqual($result, $expected);
 
556
        }
 
557
 
 
558
/**
 
559
 * testIniCheck method
 
560
 *
 
561
 * @access public
 
562
 * @return void
 
563
 */
 
564
        function testIniCheck() {
 
565
                Configure::write('Acl.classname', 'IniAclTest');
 
566
                unset($this->Acl);
 
567
                $iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
 
568
 
 
569
                $this->Acl = new AclComponent();
 
570
                $this->Acl->_Instance->config= $this->Acl->_Instance->readConfigFile($iniFile);
 
571
 
 
572
                $this->assertFalse($this->Acl->check('admin', 'ads'));
 
573
                $this->assertTrue($this->Acl->check('admin', 'posts'));
 
574
 
 
575
                $this->assertTrue($this->Acl->check('jenny', 'posts'));
 
576
                $this->assertTrue($this->Acl->check('jenny', 'ads'));
 
577
 
 
578
                $this->assertTrue($this->Acl->check('paul', 'posts'));
 
579
                $this->assertFalse($this->Acl->check('paul', 'ads'));
 
580
 
 
581
                $this->assertFalse($this->Acl->check('nobody', 'comments'));
 
582
        }
 
583
 
 
584
/**
 
585
 * debug function - to help editing/creating test cases for the ACL component
 
586
 *
 
587
 * To check the overal ACL status at any time call $this->__debug();
 
588
 * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
 
589
 * Only designed to work with the db based ACL
 
590
 *
 
591
 * @param bool $treesToo
 
592
 * @access private
 
593
 * @return void
 
594
 */
 
595
        function __debug ($printTreesToo = false) {
 
596
                $this->Acl->Aro->displayField = 'alias';
 
597
                $this->Acl->Aco->displayField = 'alias';
 
598
                $aros = $this->Acl->Aro->find('list', array('order' => 'lft'));
 
599
                $acos = $this->Acl->Aco->find('list', array('order' => 'lft'));
 
600
                $rights = array('*', 'create', 'read', 'update', 'delete');
 
601
                $permissions['Aros v Acos >'] = $acos;
 
602
                foreach ($aros as $aro) {
 
603
                        $row = array();
 
604
                        foreach ($acos as $aco) {
 
605
                                $perms = '';
 
606
                                foreach ($rights as $right) {
 
607
                                        if ($this->Acl->check($aro, $aco, $right)) {
 
608
                                                if ($right == '*') {
 
609
                                                        $perms .= '****';
 
610
                                                        break;
 
611
                                                }
 
612
                                                $perms .= $right[0];
 
613
                                        } elseif ($right != '*') {
 
614
                                                $perms .= ' ';
 
615
                                        }
 
616
                                }
 
617
                                $row[] = $perms;
 
618
                        }
 
619
                        $permissions[$aro] = $row;
 
620
                }
 
621
                foreach ($permissions as $key => $values) {
 
622
                        array_unshift($values, $key);
 
623
                        $values = array_map(array(&$this, '__pad'), $values);
 
624
                        $permissions[$key] = implode (' ', $values);
 
625
                }
 
626
                $permisssions = array_map(array(&$this, '__pad'), $permissions);
 
627
                array_unshift($permissions, 'Current Permissions :');
 
628
                if ($printTreesToo) {
 
629
                        debug (array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
 
630
                }
 
631
                debug (implode("\r\n", $permissions));
 
632
        }
 
633
 
 
634
/**
 
635
 * pad function
 
636
 * Used by debug to format strings used in the data dump
 
637
 *
 
638
 * @param string $string
 
639
 * @param int $len
 
640
 * @access private
 
641
 * @return void
 
642
 */
 
643
        function __pad($string = '', $len = 14) {
 
644
                return str_pad($string, $len);
 
645
        }
 
646
}