def test_constructContent(self): from Products.CMFCore.TypesTool \ import ScriptableTypeInformation as STI site = self.site acl_users = self.acl_users ttool = self.ttool setSecurityPolicy(self._oldPolicy) newSecurityManager(None, acl_users.all_powerful_Oz) self.site._owner = (['acl_users'], 'all_powerful_Oz') sti_baz = STI('Baz', permission='Add portal content', constructor_path='addBaz') ttool._setObject('Baz', sti_baz) ttool._setObject('addBaz', PythonScript('addBaz')) s = ttool.addBaz s.write(STI_SCRIPT) f = site._setObject('folder', PortalFolder(id='folder')) f.manage_addProduct = {'FooProduct': DummyFactory(f)} f._owner = (['acl_users'], 'user_foo') self.assertEqual(f.getOwner(), acl_users.user_foo) ttool.constructContent('Dummy Content', container=f, id='page1') try: ttool.constructContent('Baz', container=f, id='page2') except Unauthorized: self.fail('CMF Collector issue #165 (Ownership bug): ' 'Unauthorized raised')
def test_invokeFactory( self ): f = self._makeOne( 'container' ) self.failIf( 'foo' in f.objectIds() ) f.manage_addProduct = { 'FooProduct' : DummyFactory(f) } f.invokeFactory( type_name='Dummy Content', id='foo' ) self.failUnless( 'foo' in f.objectIds() ) foo = f.foo self.assertEqual( foo.getId(), 'foo' ) self.assertEqual( foo.getPortalTypeName(), 'Dummy Content' ) self.assertEqual( foo.Type(), 'Dummy Content Title' )
def test_processActions( self ): """ Are the correct, permitted methods returned for actions? """ site = self.site portal = site._setObject( 'portal', PortalFolder(id='portal') ) portal.manage_addProduct = { 'FooProduct' : DummyFactory(portal) } portal.invokeFactory( 'Dummy Content', 'actions_dummy' ) dummy = portal._getOb( 'actions_dummy' ) # so we can traverse to it: dummy.view = DummyObject("view") dummy.view2 = DummyObject("view2") dummy.edit = DummyObject("edit") default_view = dummy() custom_view = _getViewFor( dummy, view='view2' )() unpermitted_view = _getViewFor( dummy, view='edit' )() self.failUnlessEqual(default_view, 'view') self.failUnlessEqual(custom_view, 'view2') self.failIf(unpermitted_view == 'edit') self.failUnlessEqual(unpermitted_view, 'view')