Back to index

plone3  3.1.7
test_SkinsTool.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 SkinsTool module.
00014 
00015 $Id: test_SkinsTool.py 77004 2007-06-24 08:57:54Z 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 
00025 class SkinsContainerTests(unittest.TestCase):
00026 
00027     def test_z2interfaces(self):
00028         from Interface.Verify import verifyClass
00029         from Products.CMFCore.interfaces.portal_skins \
00030                 import SkinsContainer as ISkinsContainer
00031         from Products.CMFCore.SkinsContainer import SkinsContainer
00032 
00033         verifyClass(ISkinsContainer, SkinsContainer)
00034 
00035     def test_z3interfaces(self):
00036         from zope.interface.verify import verifyClass
00037         from Products.CMFCore.interfaces import ISkinsContainer
00038         from Products.CMFCore.SkinsContainer import SkinsContainer
00039 
00040         verifyClass(ISkinsContainer, SkinsContainer)
00041 
00042 
00043 class SkinsToolTests(unittest.TestCase):
00044 
00045     def _makeOne(self, *args, **kw):
00046         from Products.CMFCore.SkinsTool import SkinsTool
00047 
00048         return SkinsTool(*args, **kw)
00049 
00050     def test_z2interfaces(self):
00051         from Interface.Verify import verifyClass
00052         from Products.CMFCore.interfaces.portal_actions \
00053                 import ActionProvider as IActionProvider
00054         from Products.CMFCore.interfaces.portal_skins \
00055                 import portal_skins as ISkinsTool
00056         from Products.CMFCore.interfaces.portal_skins \
00057                 import SkinsContainer as ISkinsContainer
00058         from Products.CMFCore.SkinsTool import SkinsTool
00059 
00060         verifyClass(IActionProvider, SkinsTool)
00061         verifyClass(ISkinsContainer, SkinsTool)
00062         verifyClass(ISkinsTool, SkinsTool)
00063 
00064     def test_z3interfaces(self):
00065         from zope.interface.verify import verifyClass
00066         from Products.CMFCore.interfaces import IActionProvider
00067         from Products.CMFCore.interfaces import ISkinsContainer
00068         from Products.CMFCore.interfaces import ISkinsTool
00069         from Products.CMFCore.SkinsTool import SkinsTool
00070 
00071         verifyClass(IActionProvider, SkinsTool)
00072         verifyClass(ISkinsContainer, SkinsTool)
00073         verifyClass(ISkinsTool, SkinsTool)
00074 
00075     def test_add_invalid_path(self):
00076         tool = self._makeOne()
00077 
00078         # We start out with no wkin selections
00079         self.assertEquals(len(tool.getSkinSelections()), 0)
00080 
00081         # Add a skin selection with an invalid path element
00082         paths = 'foo, bar, .svn'
00083         tool.addSkinSelection('fooskin', paths)
00084 
00085         # Make sure the skin selection exists
00086         paths = tool.getSkinPath('fooskin')
00087         self.failIf(paths is None)
00088 
00089         # Test for the contents
00090         self.failIf(paths.find('foo') == -1)
00091         self.failIf(paths.find('bar') == -1)
00092         self.failUnless(paths.find('.svn') == -1)
00093 
00094 
00095 class SkinnableTests(unittest.TestCase):
00096 
00097     def _makeOne(self):
00098         from Products.CMFCore.SkinsTool import SkinsTool
00099         from Products.CMFCore.Skinnable import SkinnableObjectManager
00100 
00101         class TestSkinnableObjectManager(SkinnableObjectManager):
00102             tool = SkinsTool()
00103             # This is needed otherwise REQUEST is the string
00104             # '<Special Object Used to Force Acquisition>'
00105             REQUEST = None
00106             def getSkinsFolderName(self):
00107                 '''tool'''
00108                 return 'tool'
00109 
00110         return TestSkinnableObjectManager()
00111 
00112     def tearDown(self):
00113         from Products.CMFCore.Skinnable import SKINDATA
00114         SKINDATA.clear()
00115         cleanUp()
00116 
00117     def test_getCurrentSkinName(self):
00118         som = self._makeOne()
00119 
00120         pathA = ('foo, bar')
00121         pathB = ('bar, foo')
00122 
00123         som.tool.addSkinSelection('skinA', pathA)
00124         som.tool.addSkinSelection('skinB', pathB)
00125 
00126         som.tool.manage_properties(default_skin='skinA')
00127 
00128         # Expect the default skin name to be returned
00129         self.failUnless(som.getCurrentSkinName() == 'skinA')
00130 
00131         # after a changeSkin the new skin name should be returned
00132         som.changeSkin('skinB', som.REQUEST)
00133         self.failUnless(som.getCurrentSkinName() == 'skinB')
00134 
00135 
00136 def test_suite():
00137     return unittest.TestSuite((
00138         unittest.makeSuite(SkinsContainerTests),
00139         unittest.makeSuite(SkinsToolTests),
00140         unittest.makeSuite(SkinnableTests),
00141         ))
00142 
00143 if __name__ == '__main__':
00144     unittest.main(defaultTest='test_suite')