From 56ce3c0f1c14ca5ccf5af1381dbe4cc3e20077a7 Mon Sep 17 00:00:00 2001 From: AD7six Date: Sat, 17 May 2008 17:33:08 +0000 Subject: [PATCH] adding debug function to acl test case to aide checking permissions whilst writing/debugging tests git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6910 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../libs/controller/components/acl.test.php | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/components/acl.test.php b/cake/tests/cases/libs/controller/components/acl.test.php index 91dc313d3..5ad1d0a38 100644 --- a/cake/tests/cases/libs/controller/components/acl.test.php +++ b/cake/tests/cases/libs/controller/components/acl.test.php @@ -339,6 +339,54 @@ class AclComponentTest extends CakeTestCase { function tearDown() { unset($this->Acl); } +/** + * debug function - to help editing/creating test cases for the ACL component + * + * To check the overal ACL status at any time call $this->__debug(); + * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined + * + * @access private + * @return void + */ + function __debug () { + $this->Acl->Aro->displayField = 'alias'; + $this->Acl->Aco->displayField = 'alias'; + $aros = $this->Acl->Aro->find('list'); + $acos = $this->Acl->Aco->find('list'); + $permissions = array(); + $permissions['Aros v Acos >'] = $acos; + foreach ($aros as $aro) { + $row = array(); + foreach ($acos as $aco) { + $row[] = ($this->Acl->check($aro, $aco))?'y':'n'; + } + $permissions[$aro] = $row; + } + foreach ($permissions as $key => $values) { + array_unshift($values, $key); + $values = array_map(array(&$this, '__pad'), $values); + $permissions[$key] = implode (' ', $values); + } + $permisssions = array_map(array(&$this, '__pad'), $permissions); + array_unshift($permissions, 'Current Permissions :'); + debug (array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList())); + debug (implode("\r\n", $permissions)); + } +/** + * pad function + * Used by debug to format strings used in the data dump + * + * @param string $string + * @param int $len + * @access private + * @return void + */ + function __pad($string = '', $len = 12) { + if (strlen($string) == 1) { + return ' ' . $string . ' '; + } + return str_pad($string, $len); + } } -?> \ No newline at end of file +?>