Tag Archive: dojo grid


Here are some tests functions I wrote for testing the validity of the access control lists of my website. Nothing fancy but it’s an exemple that may be usefull for begginners.

  1. private function CanAccess($url)
  2. {
  3. $this->dispatch($url);
  4. $this->assertNotResponseCode(‘404’);
  5. list($controller, $action) = explode(“/”, ereg_replace(“^/”, “”, $url));
  6. $this->assertController($controller);
  7. $this->assertAction($action);
  8. }
  9. private function CanNotAccess($url)
  10. {
  11. $this->dispatch($url);
  12. // if the user is Guest
  13. if(!Zend_Auth::getInstance()->hasIdentity())
  14. {
  15. $this->assertController(‘user’);
  16. $this->assertAction(‘login’);
  17. // CustomAclManager Should show a Login form
  18. $this->assertQueryCountMin(‘form’, 1);
  19. $this->assertQueryCountMin(‘input[name~=”email”]’, 1);
  20. $this->assertQueryCountMin(‘input[name~=”password”]’, 1);
  21. $this->assertQueryCountMin(‘input[name~=”submit”]’, 1);
  22. }
  23. // If user is logged In he’ll only get redirected
  24. else
  25. $this->assertRedirect;
  26. }
  27. private function LoginRealUser()
  28. {
  29. $this->request->setMethod(‘POST’)
  30. ->setPost(array(
  31. ’email’ => ‘regularuser@nowhere.com’,
  32. ‘password’ => ‘usertests’,
  33. ));
  34. $this->dispatch(‘/user/login’);
  35. $this->assertRedirect;
  36. $this->assertTrue(Zend_Auth::getInstance()->hasIdentity());
  37. }
  38. // ok, now let’s run some tests
  39. public function testGuestAccessRightsAreOk()
  40. {
  41. $this->CanAccess(‘/user/login’);
  42. }
  43. public function testLoggedInUserAccessRightsAreOk()
  44. {
  45. $this->LoginRealUser();
  46. $this->CanAccess(‘/user/logout’);
  47. }
  48. // testing where users can not go
  49. public function testGuestRestrictionsAreOk()
  50. {
  51. $this->CanNotAccess(‘/user/logout’);
  52. $this->CanNotAccess(‘/user/index’);
  53. }
  54. public function testLoggedInRestrictionsAreOk()
  55. {
  56. $this->LoginRealUser();
  57. $this->CanNotAccess(‘/user/login’);
  58. }

A simple way to test your user access rights !

Damn, I spent so much time building this, I’m happy I could find the solution ! Here’s a dojo grid working with Zend framework. I fist tried this on the view controller, but it got me nowhere :

  1. // My function that is supposed to add the
  2. // OD column to ID, it never gets fired…
  3. <script type=”text/javascript”>
  4. function getODtoID()  {  alert(“test”);   }
  5. </script>
  6. /* My grid, it’s working except get=”getODtoID” */
  7. <table id=”grid” dojotype=”dojox.grid.Grid” store=”pStore” query=”{ post_id: ‘*’}”>
  8. <thead>
  9. <tr>
  10. <th field=”status” width=”30px”>Status</th>
  11. <th width=”5em” get=”getODtoID”>OD to ID</th>
  12. </tr>
  13. </thead>
  14. </table>
  15. dojo()->enable()
  16. ->setDjConfigOption(‘parseOnLoad’, true)
  17. ->requireModule(‘dojo.parser’)
  18. ->requireModule(‘dojo.data.ItemFileReadStore’)
  19. ->requireModule(‘dojox.grid.Grid’)
  20. ->requireModule(‘dojox.grid._data.model’);
  21. ?>

The problem was that I couldn’t get the function getODtoID to be executed. I wanted to build a link on my grid, and for that I needed some very basic calculation. So what’s the solution ? I still can’t figure out why it’s not working this way, but I tryied something else :

  1. <script type=”text/javascript”>
  2. var customColumn = function(inRowIndex) {
  3. // This is standard for many grid handlers
  4. if (! dijit.byId(‘grid’).model.data[inRowIndex]) {
  5. return;
  6. }
  7. return “<a href=\”/blogmanager/edit?id=” +
  8. model.getRow(inRowIndex).post_id + “\”>edit</a>”;
  9. }
  10. var view = {
  11. cells:  [[
  12. { name: “Post id”, field: “post_id” },
  13. { name: ‘Link’, get: customColumn }
  14. ],
  15. ]};
  16. var layout = [ view ];
  17. </script>
  18. <div dojotype=”dojox.grid.data.DojoData” jsid=”model” store=”pStore” query=”{ post_id: ‘*’ }” clientsort=”true”></div>
  19. <div id=”grid” dojotype=”dojox.Grid” model=”model” structure=”layout”></div>
  20. dojo()->enable()
  21. ->setDjConfigOption(‘parseOnLoad’, true)
  22. ->setDjConfigOption(‘isDebug’, true)
  23. ->requireModule(‘dojo.parser’)
  24. ->requireModule(‘dojo.data.ItemFileReadStore’)
  25. ->requireModule(‘dojox.grid.Grid’);
  26. ?>

And that’s working fine, fine fine. So now it’s easy to build custom cells withing your grids !