Back to index

plone3  3.1.7
test_URLTool.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 URLTool module.
00014 
00015 $Id: test_URLTool.py 77186 2007-06-28 19:06:19Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from zope.component import getSiteManager
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.interfaces import ISiteRoot
00025 from Products.CMFCore.tests.base.dummy import DummyContent
00026 from Products.CMFCore.tests.base.dummy import DummyFolder
00027 from Products.CMFCore.tests.base.dummy import DummySite
00028 
00029 
00030 class URLToolTests(unittest.TestCase):
00031 
00032     def setUp(self):
00033         self.site = DummySite(id='foo')
00034         sm = getSiteManager()
00035         sm.registerUtility(self.site, ISiteRoot)
00036 
00037     def tearDown(self):
00038         cleanUp()
00039 
00040     def _makeOne(self, *args, **kw):
00041         from Products.CMFCore.URLTool import URLTool
00042 
00043         url_tool = URLTool(*args, **kw)
00044         return url_tool.__of__( self.site )
00045 
00046     def test_z2interfaces(self):
00047         from Interface.Verify import verifyClass
00048         from Products.CMFCore.interfaces.portal_actions \
00049                 import ActionProvider as IActionProvider
00050         from Products.CMFCore.interfaces.portal_url \
00051                 import portal_url as IURLTool
00052         from Products.CMFCore.URLTool import URLTool
00053 
00054         verifyClass(IActionProvider, URLTool)
00055         verifyClass(IURLTool, URLTool)
00056 
00057     def test_z3interfaces(self):
00058         from zope.interface.verify import verifyClass
00059         from Products.CMFCore.interfaces import IActionProvider
00060         from Products.CMFCore.interfaces import IURLTool
00061         from Products.CMFCore.URLTool import URLTool
00062 
00063         verifyClass(IActionProvider, URLTool)
00064         verifyClass(IURLTool, URLTool)
00065 
00066     def test_portal_methods(self):
00067         url_tool = self._makeOne()
00068         self.assertEqual( url_tool()
00069                         , 'http://www.foobar.com/bar/foo' )
00070         self.assertEqual( url_tool.getPortalObject()
00071                         , self.site )
00072         self.assertEqual( url_tool.getPortalPath()
00073                         , '/bar/foo' )
00074 
00075     def test_content_methods(self):
00076         url_tool = self._makeOne()
00077         self.site._setObject( 'folder', DummyFolder(id='buz') )
00078         self.site.folder._setObject( 'item', DummyContent(id='qux.html') )
00079         obj = self.site.folder.item
00080         self.assertEqual( url_tool.getRelativeContentPath(obj)
00081                         , ('buz', 'qux.html') )
00082         self.assertEqual( url_tool.getRelativeContentURL(obj)
00083                         , 'buz/qux.html' )
00084         self.assertEqual( url_tool.getRelativeUrl(obj)
00085                         , 'buz/qux.html' )
00086 
00087 
00088 def test_suite():
00089     return unittest.TestSuite((
00090         unittest.makeSuite( URLToolTests ),
00091         ))
00092 
00093 if __name__ == '__main__':
00094     unittest.main(defaultTest='test_suite')