Skip to content

Updating the acl menu comp #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h2. Acl Menu Plugin
h2. Acl Menu Plugin 0.2

This plugin provides a component for generating menus based off of the current user session and integrates well with the "AcoExtras Plugin":http://github.com/markstory/acl_extras/tree/master I also maintain. See "mark-story.com for additional info and usage":http://mark-story.com/posts/view/acl-menu-component

Expand All @@ -7,3 +7,5 @@ To use the menu once in a @acl_menu@ dir on your pluginPaths.
var $components = array('AclMenu.Menu');

When checking out this repo place it into an @acl_menu@ directory in one of your plugin paths.

updated for cake 1.3
12 changes: 6 additions & 6 deletions controllers/components/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class MenuComponent extends Object {
*
* @return bool
**/
public function initialize(&$Controller, $settings) {
public function initialize($Controller, $settings) {
if (!empty($settings)) {
$this->_set($settings);
}
Expand All @@ -133,8 +133,8 @@ public function initialize(&$Controller, $settings) {
*
* @param Object $Controller
*/
public function startup(&$Controller) {
$this->Controller =& $Controller;
public function startup($Controller) {
$this->Controller = $Controller;

Cache::config($this->cacheConfig, array('engine' => 'File', 'duration' => $this->cacheTime, 'prefix' => $this->cacheKey));

Expand Down Expand Up @@ -208,7 +208,7 @@ public function constructMenu($aro) {
$size = count($this->rawMenus);
for ($i = 0; $i < $size; $i++) {
$item = $this->rawMenus[$i];
$aco = Inflector::underscore($item['url']['controller']);
$aco = Inflector::camelize($item['url']['controller']);
if (isset($item['url']['action'])) {
$aco = $this->aclPath . $aco . $this->aclSeparator . $item['url']['action'];
}
Expand Down Expand Up @@ -239,7 +239,7 @@ public function constructMenu($aro) {
*/
public function generateRawMenus() {
$Controllers = $this->getControllers();
$cakeAdmin = Configure::read('Routing.admin');
$cakeAdmin = Configure::read('Routing.prefixes.0');
$this->createExclusions();

//go through the controllers folder and make an array of every menu that could be used.
Expand Down Expand Up @@ -353,7 +353,7 @@ public function filterMethods($methods, $remove = array()) {
* @return mixed. Array of options or false on total exclusion
**/
public function setOptions($controllerVars) {
$cakeAdmin = Configure::read('Routing.admin');
$cakeAdmin = Configure::read('Routing.prefixes.0');
$menuOptions = isset($controllerVars['menuOptions']) ? $controllerVars['menuOptions'] : array();

$exclude = array('view', 'edit', 'delete', $cakeAdmin . '_edit',
Expand Down
23 changes: 19 additions & 4 deletions tests/cases/components/menu.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Mark Story <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Component', array('AclMenu.Menu', 'Acl', 'Auth'));
App::import('Component', array('AclMenu.Menu', 'Acl', 'Auth', 'Session'));
App::import('Controller', 'AppController');

class TestMenuComponent extends MenuComponent {
Expand Down Expand Up @@ -58,6 +58,19 @@ function admin_action(){}
}

Mock::generate('AclComponent', 'MenuTestMockAclComponent');



Cache::config('my_test_key', array(
'engine' => 'File',
'duration'=> '+1 day',
'probability'=> 100,
'path' => CACHE . 'menu',
'prefix' => 'cake_',
'lock' => false,
'serialize' => true)
);

/**
* Menu Component Test Case
*
Expand All @@ -76,8 +89,10 @@ function startTest() {
$this->Controller = new TestMenuController();
$this->Menu->Acl = new MenuTestMockAclComponent();
$this->Menu->Auth = new AuthComponent();
$this->_admin = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
$this->Menu->Auth->Session = new SessionComponent();
$this->_admin = Configure::read('Routing.prefixes.0');
Configure::write('Routing.prefixes.0', 'admin');
$this->Menu->startup($this->Controller);
}

/**
Expand Down Expand Up @@ -428,7 +443,7 @@ function testWeightSorting() {
function endTest() {
ClassRegistry::flush();
$this->Menu->clearCache();
Configure::write('Routing.admin', $this->_admin);
Configure::write('Routing.prefixes.0', $this->_admin);
unset($this->Menu, $this->Controller);
}
}
Expand Down