Back to index

plone3  3.1.7
testURLTool.py
Go to the documentation of this file.
00001 #
00002 # Tests the workflow tool
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 portal_name = PloneTestCase.portal_name
00008 
00009 
00010 class TestURLTool(PloneTestCase.PloneTestCase):
00011 
00012     def afterSetUp(self):
00013         self.url = self.portal.portal_url
00014         self.folder.invokeFactory('Folder', id='foo')
00015         self.folder.foo.invokeFactory('Document', id='doc1')
00016         
00017     def test_isURLInPortal(self):
00018         iURLiP = self.url.isURLInPortal
00019         self.failUnless(iURLiP(
00020                                'http://nohost/%s/foo' % portal_name))
00021         self.failUnless(iURLiP(
00022                                'http://nohost/%s' % portal_name))
00023         self.failIf(iURLiP(
00024                            'http://nohost2/%s/foo' % portal_name))
00025         self.failUnless(iURLiP(
00026                                'https://nohost/%s/bar' % portal_name))
00027         self.failIf(iURLiP(
00028                            'http://nohost:8080/%s/baz' % portal_name))
00029         self.failIf(iURLiP(
00030                            'http://nohost/'))
00031         self.failIf(iURLiP(
00032                            '/images'))
00033         self.failUnless(iURLiP(
00034                                '/%s/foo' % portal_name))
00035     
00036     def test_isURLInPortalRelative(self):
00037         iURLiP = self.url.isURLInPortal
00038         #non-root relative urls will need a current context to be passed in
00039         self.failUnless(iURLiP(
00040                                'images/img1.jpg'))
00041         self.failUnless(iURLiP(
00042                                './images/img1.jpg'))
00043         self.failUnless(iURLiP( #/plone/Members/test_user_1_/something
00044                                '../something', self.folder.foo.doc1))
00045         self.failUnless(iURLiP( #/plone/Members/afolder
00046                                '../../afolder', self.folder.foo.doc1))
00047         self.failUnless(iURLiP( #/plone/afolder
00048                                '../../../afolder', self.folder.foo.doc1))
00049         self.failIf(iURLiP( #/afolder
00050                            '../../../../afolder', self.folder.foo.doc1))
00051         self.failIf(iURLiP( #/../afolder? How do we have more ../'s than there are parts in the URL?
00052                            '../../../../../afolder', self.folder.foo.doc1))
00053         self.failUnless(iURLiP( #/plone/afolder
00054                                '../../../../%s/afolder' % portal_name ,self.folder.foo.doc1))
00055 
00056 
00057 def test_suite():
00058     from unittest import TestSuite, makeSuite
00059     suite = TestSuite()
00060     suite.addTest(makeSuite(TestURLTool))
00061     return suite