diff -r d9ebb391782c -r c0ee416040fa doc/book/en/devrepo/testing.rst --- a/doc/book/en/devrepo/testing.rst Wed Sep 15 10:54:25 2010 +0200 +++ b/doc/book/en/devrepo/testing.rst Wed Sep 15 11:00:55 2010 +0200 @@ -184,6 +184,61 @@ mail = MAILBOX[1] self.assertEquals(mail.subject, '[data] yes') +Visible actions tests +````````````````````` + +It is easy to write unit tests to test actions which are visible to +user or to a category of users. Let's take an example in the +`conference cube`_. + +.. _`conference cube`: http://www.cubicweb.org/project/cubicweb-conference +.. sourcecode:: python + + class ConferenceActionsTC(CubicWebTC): + + def setup_database(self): + self.conf = self.create_entity('Conference', + title=u'my conf', + url_id=u'conf', + start_on=date(2010, 1, 27), + end_on = date(2010, 1, 29), + call_open=True, + reverse_is_chair_at=chair, + reverse_is_reviewer_at=reviewer) + + def test_admin(self): + req = self.request() + rset = req.execute('Any C WHERE C is Conference') + self.assertListEquals(self.pactions(req, rset), + [('workflow', workflow.WorkflowActions), + ('edit', confactions.ModifyAction), + ('managepermission', actions.ManagePermissionsAction), + ('addrelated', actions.AddRelatedActions), + ('delete', actions.DeleteAction), + ('generate_badge_action', badges.GenerateBadgeAction), + ('addtalkinconf', confactions.AddTalkInConferenceAction) + ]) + self.assertListEquals(self.action_submenu(req, rset, 'addrelated'), + [(u'add Track in_conf Conference object', + u'http://testing.fr/cubicweb/add/Track' + u'?__linkto=in_conf%%3A%(conf)s%%3Asubject&' + u'__redirectpath=conference%%2Fconf&' + u'__redirectvid=' % {'conf': self.conf.eid}), + ]) + +You just have to execute a rql query corresponding to the view you want to test, +and to compare the result of +:meth:`~cubicweb.devtools.testlib.CubicWebTC.pactions` with the list of actions +that must be visible in the interface. This is a list of tuples. The first +element is the action's `__regid__`, the second the action's class. + +To test actions in submenu, you just have to test the result of +:meth:`~cubicweb.devtools.testlib.CubicWebTC.action_submenu` method. The last +parameter of the method is the action's category. The result is a list of +tuples. The first element is the action's title, and the second element the +action's url. + + .. _automatic_views_tests: Automatic views testing