Update on DbAcl ticket #2976

27 08 2007

Wow – ask and you shall recieve. Not long after I posted this, changset 5588 implemented Simons patch.

One of the things that I have noticed about DbAcl, and other people have mentioned it as well on the Google Group, is that apart from not handling non-unique aliases very well, DbAcl node lookup will fail if the url does not have the full path in the ACO tree.

For example, consider the following tree.

|_ controller1
|_ controller 2
  |_action 1

If you then access http://localhost/controller1/ everything is fine. But when you try to access http://localhost/controller1/action1 you will get errors from DbAcl something like:
Warning (512): DB_ACL::check() - Failed ACO node lookup in permissions check.

Ok so just put all the actions in the database was my first solution. That is until I realised that something like /posts/view/id is going to need an ACO for every id, which seems a bit overkill.

What I would like is for non-existent children ACOs to automatically inherit from the parent and so on. Obviously this is only suitable for ACOs based on urls.

Simon Jaillet has submitted a new patch to the the CakePHP Trac Ticket #2976. Simon describes his reasons for creating the patch in his post and goes on to describe his own ACL implementation.

The patch that Simon has submitted resolves the inheritence problem. Simon also submitted an updated test case that contains tests specifically for non-existent children. I have tested this patch against the updated test cases and on some actual applications and I highly recommend updating to the latest svn trunk (5588 at time of update).applying this patch – at least until it makes it into the core. Which I sincerely hope that it does.

Kudos to Simon Jaillet, you are my new Acl hero having solved the inheritence problem for me.


CakePHP Test Suite Shell

24 06 2007

In addition to my changes to the core Test Suite to add support for plugins, I have now created a console shell to run test suites via the command line.

To use the Test Suite Shell simply place testsuite.php in /vendors/shells.

cake testsuite help
this message
cake testsuite run section test_type [case_type] test
– section – app, core or plugin_name
– test_type – case, group or all
– case_type – only with case, one of behaviors, components, controllers, helpers or models
– test – file without (test|group).php

cake testsuite run core all – will run all core tests
cake testsuite run app group models – will exexute /app/tests/groups/models.group.php
cake testsuite run contents case model content – will execute /app/plugins/contents/tests/cases/models/content.test.php

Testing CakePHP Plugins

19 06 2007

With the official Test Suite bundled with CakePHP, it is pretty easy to write unit tests for your models and controllers. The Testing Models with CakePHP Test Suite tutorial on the Bakery is a good introduction to the CakePHP Test Suite.

Now this is great until it comes time to test your plugins. It seems that the official test suite does not like plugins. So I patched my cake install so that I can run plugins test cases and groups that are logically stored in /app/plugins/plugin_name/tests.

Here are the files for those interested. Please leave bugs or issues in the comments for now.

My apologies to those who downloaded 0.1, as it did not contain app/webroot/test.php – instead I had incorrectly included app/webroot/index.php

Plugin tests are exactly the same as those described at Testing Models with CakePHP Test Suite except that the loadModel(‘ModelName’) is left out becomes loadPluginModels(‘plugin’). Here is an example test case for a plugin:


class ContentTest extends Content {
  var $name = 'ContentTest';
  var $useDbConfig = 'test_suite';

class ContentTestCase extends CakeTestCase {
  var $TestObject = null;
  var $fixtures = array( 'content_test' );

  function startTest() {
    $this->TestObject = new ContentTest();

  function endTest() {

  function testSlugBehaviour(){
    $data = ContentTestFixture::$slugTest;
      $data = $this->TestObject->findById($this->TestObject->getInsertID());
      $expected = 'slug-test';
      $this->assertEqual($data['ContentTest']['slug'], $expected);
    } else {
      $this->fail('Could not save the Test Data');

Currently my patch only supports the HtmlManager – web view – and not the TextManager. Also ‘All’ under Test Groups of a plugin will not run the plugin tests, it will run the App Test Cases. I will fix these issues in the next release. The patch supports All under Group Tests and combined with my Test Suite Shell it also supports cli testing

And finally here are some screeshots of Plugin Tests in action.