Back to index

plone3  3.1.7
test_Expression.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for Expression module.
00014 
00015 $Id: test_Expression.py 77113 2007-06-26 20:36:26Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from Products.CMFCore.ActionInformation import ActionInformation
00022 from Products.CMFCore.Expression import createExprContext
00023 from Products.CMFCore.Expression import Expression
00024 from Products.CMFCore.tests.base.dummy import DummyContent
00025 from Products.CMFCore.tests.base.dummy import DummyTool as DummyMembershipTool
00026 from Products.CMFCore.tests.base.testcase import SecurityTest
00027 
00028 
00029 class ExpressionTests( SecurityTest ):
00030 
00031     def setUp( self ):
00032 
00033         SecurityTest.setUp(self)
00034         root = self.root
00035         root._setObject('portal', DummyContent('portal', url='url_portal'))
00036         portal = self.portal = root.portal
00037         self.folder = DummyContent('foo', url='url_foo')
00038         self.object = DummyContent('bar', url='url_bar')
00039         self.ai = ActionInformation(id='view'
00040                                   , title='View'
00041                                   , action=Expression(
00042                   text='view')
00043                                   , condition=Expression(
00044                   text='member')
00045                                   , category='global'
00046                                   , visible=1)
00047 
00048     def test_anonymous_ec(self):
00049         self.portal.portal_membership = DummyMembershipTool()
00050         ec = createExprContext(self.folder, self.portal, self.object)
00051         member = ec.contexts['member']
00052         self.failIf(member)
00053 
00054     def test_authenticatedUser_ec(self):
00055         self.portal.portal_membership = DummyMembershipTool(anon=0)
00056         ec = createExprContext(self.folder, self.portal, self.object)
00057         member = ec.contexts['member']
00058         self.assertEqual(member.getId(), 'dummy')
00059 
00060     def test_ec_context(self):
00061         self.portal.portal_membership = DummyMembershipTool()
00062         ec = createExprContext(self.folder, self.portal, self.object)
00063         object = ec.contexts['object']
00064         portal = ec.contexts['portal']
00065         folder = ec.contexts['folder']
00066         self.failUnless(object)
00067         self.assertEqual(object.id, 'bar')
00068         self.assertEqual(object.absolute_url(), 'url_bar')
00069         self.failUnless(portal)
00070         self.assertEqual(portal.id, 'portal')
00071         self.assertEqual(portal.absolute_url(), 'url_portal')
00072         self.failUnless(folder)
00073         self.assertEqual(folder.id, 'foo')
00074         self.assertEqual(folder.absolute_url(), 'url_foo')
00075 
00076 
00077 def test_suite():
00078     return unittest.TestSuite((
00079         unittest.makeSuite(ExpressionTests),
00080         ))
00081 
00082 if __name__ == '__main__':
00083     unittest.main(defaultTest='test_suite')