public function testCreateWithParent() { Fixtures::save('db'); $parent = Aro::find('first', ['conditions' => ['alias' => 'Peter']]); $key = Aro::key(); $aro = Aro::create(); $aro->set(['alias' => 'Subordinate', 'model' => 'User', 'fk_id' => 7, 'parent_id' => $parent->{$key}]); $aro->save(); $result = Aro::find('first', ['conditions' => ['alias' => 'Subordinate']]); $this->assertEqual(16, $result->lft); $this->assertEqual(17, $result->rght); }
/** * debug function - to help editing/creating test cases for the ACL component * * To check the overall 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 * Only designed to work with the db based ACL * * @param bool $treesToo * @return void */ protected function _debug($printTreesToo = false) { Aro::meta('title', 'alias'); Aco::meta('title', 'alias'); $aros = Aro::find('list', ['order' => 'lft']); $acos = Aco::find('list', ['order' => 'lft']); $rights = [$this->_privileges, 'create', 'read', 'update', 'delete']; $permissions['Aros v Acos >'] = $acos; foreach ($aros as $aro) { $row = []; foreach ($acos as $aco) { $perms = ''; foreach ($rights as $right) { if (Permission::check($aro, $aco, $right)) { if ($right == $this->_privileges) { $perms .= '****'; break; } $perms .= $right[0]; } elseif ($right != $this->_privileges) { $perms .= ' '; } } $row[] = $perms; } $permissions[$aro] = $row; } foreach ($permissions as $key => $values) { array_unshift($values, $key); $values = array_map([&$this, '_pad'], $values); $permissions[$key] = implode(' ', $values); } $permissions = array_map([&$this, '_pad'], $permissions); array_unshift($permissions, 'Current Permissions :'); print_r(implode("\r\n", $permissions)); }