Back to index

plone3  3.1.7
test_skins.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 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 """Skins tool xml adapter and setup handler unit tests.
00014 
00015 $Id: test_skins.py 76996 2007-06-24 00:18:49Z hannosch $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 ZopeTestCase.installProduct('CMFCore', 1)
00021 
00022 import os
00023 
00024 from OFS.Folder import Folder
00025 from zope.interface import implements
00026 
00027 from Products.GenericSetup.testing import BodyAdapterTestCase
00028 from Products.GenericSetup.testing import NodeAdapterTestCase
00029 from Products.GenericSetup.tests.common import BaseRegistryTests
00030 from Products.GenericSetup.tests.common import DummyExportContext
00031 from Products.GenericSetup.tests.common import DummyImportContext
00032 
00033 from Products.CMFCore.interfaces import ISkinsTool
00034 from Products.CMFCore.testing import ExportImportZCMLLayer
00035 
00036 _TESTS_PATH = os.path.split(__file__)[0]
00037 
00038 _DIRECTORYVIEW_XML = """\
00039 <object name="foo_directoryview" meta_type="Filesystem Directory View"
00040    directory="CMFCore/exportimport/tests/one"/>
00041 """
00042 
00043 _SKINSTOOL_BODY = """\
00044 <?xml version="1.0"?>
00045 <object name="portal_skins" meta_type="CMF Skins Tool" allow_any="False"
00046    cookie_persistence="False" default_skin="" request_varname="portal_skin">
00047  <object name="foo_directoryview" meta_type="Filesystem Directory View"
00048     directory="Products.CMFCore.exportimport.tests:one"/>
00049  <skin-path name="foo_path">
00050   <layer name="one"/>
00051  </skin-path>
00052 </object>
00053 """
00054 
00055 _EMPTY_EXPORT = """\
00056 <?xml version="1.0"?>
00057 <object name="portal_skins" meta_type="Dummy Skins Tool" allow_any="False"
00058    cookie_persistence="False" default_skin="default_skin"
00059    request_varname="request_varname"/>
00060 """
00061 
00062 _NORMAL_EXPORT = """\
00063 <?xml version="1.0"?>
00064 <object name="portal_skins" meta_type="Dummy Skins Tool" allow_any="True"
00065    cookie_persistence="True" default_skin="basic" request_varname="skin_var">
00066  <object name="one" meta_type="Filesystem Directory View"
00067     directory="Products.CMFCore.exportimport.tests:one"/>
00068  <object name="three" meta_type="Filesystem Directory View"
00069     directory="Products.CMFCore.exportimport.tests:three"/>
00070  <object name="two" meta_type="Filesystem Directory View"
00071     directory="Products.CMFCore.exportimport.tests:two"/>
00072  <skin-path name="basic">
00073   <layer name="one"/>
00074  </skin-path>
00075  <skin-path name="fancy">
00076   <layer name="three"/>
00077   <layer name="two"/>
00078   <layer name="one"/>
00079  </skin-path>
00080 </object>
00081 """
00082 
00083 _FRAGMENT1_IMPORT = """\
00084 <?xml version="1.0"?>
00085 <object name="portal_skins" meta_type="Dummy Skins Tool">
00086  <object name="three" meta_type="Filesystem Directory View"
00087     package="Products.CMFCore" path="exportimport/tests/three"/>
00088  <skin-path name="*">
00089   <layer name="three" insert-before="two"/>
00090  </skin-path>
00091 </object>
00092 """
00093 
00094 _FRAGMENT2_IMPORT = """\
00095 <?xml version="1.0"?>
00096 <object name="portal_skins" meta_type="Dummy Skins Tool">
00097  <object name="four" meta_type="Filesystem Directory View"
00098     directory="Products.CMFCore.exportimport.tests:four"/>
00099  <skin-path name="*">
00100   <layer name="four" insert-after="three"/>
00101  </skin-path>
00102 </object>
00103 """
00104 
00105 _FRAGMENT3_IMPORT = """\
00106 <?xml version="1.0"?>
00107 <object name="portal_skins" meta_type="Dummy Skins Tool">
00108  <object name="three" meta_type="Filesystem Directory View"
00109     directory="CMFCore/exportimport/tests/three"/>
00110  <object name="four" meta_type="Filesystem Directory View"
00111     directory="CMFCore/exportimport/tests/four"/>
00112  <skin-path name="*">
00113   <layer name="three" insert-before="*"/>
00114   <layer name="four" insert-after="*"/>
00115  </skin-path>
00116 </object>
00117 """
00118 
00119 _FRAGMENT4_IMPORT = """\
00120 <?xml version="1.0"?>
00121 <object name="portal_skins" meta_type="Dummy Skins Tool">
00122  <skin-path name="*">
00123   <layer name="three" remove="1"/>
00124  </skin-path>
00125 </object>
00126 """
00127 
00128 _FRAGMENT5_IMPORT = """\
00129 <?xml version="1.0"?>
00130 <object name="portal_skins" meta_type="Dummy Skins Tool">
00131  <skin-path name="existing" based-on="basic">
00132  </skin-path>
00133  <skin-path name="new" based-on="basic">
00134   <layer name="two" insert-before="three"/>
00135  </skin-path>
00136  <skin-path name="wrongbase" based-on="invalid_base_id">
00137   <layer name="two" insert-before="three"/>
00138  </skin-path>
00139 </object>"""
00140 
00141 
00142 _FRAGMENT6_IMPORT = """\
00143 <?xml version="1.0"?>
00144 <object name="portal_skins" meta_type="Dummy Skins Tool" allow_any="True"
00145    cookie_persistence="True" default_skin="basic" request_varname="skin_var">
00146  <object name="one" meta_type="Filesystem Directory View"
00147     directory="Products.CMFCore.exportimport.tests:one"/>
00148  <object name="three" meta_type="Filesystem Directory View"
00149     directory="Products.CMFCore.exportimport.tests:three"/>
00150  <object name="two" meta_type="Filesystem Directory View"
00151     directory="Products.CMFCore.exportimport.tests:two"/>
00152  <skin-path name="basic">
00153   <layer name="one"/>
00154  </skin-path>
00155  <skin-path name="fancy" remove="True"/>
00156  <skin-path name="invalid" remove="True"/>
00157 </object>
00158 """
00159 
00160 
00161 class DummySite(Folder):
00162 
00163     _skin_setup_called = False
00164 
00165     def clearCurrentSkin(self):
00166         pass
00167 
00168     def setupCurrentSkin(self, REQUEST):
00169         self._skin_setup_called = True
00170 
00171 
00172 class DummySkinsTool(Folder):
00173 
00174     implements(ISkinsTool)
00175 
00176     meta_type = 'Dummy Skins Tool'
00177     default_skin = 'default_skin'
00178     request_varname = 'request_varname'
00179     allow_any = False
00180     cookie_persistence = False
00181 
00182     def __init__(self, selections=None, fsdvs=()):
00183         self._selections = selections or {}
00184 
00185         for id, obj in fsdvs:
00186             self._setObject(id, obj)
00187 
00188     def _getSelections(self):
00189         return self._selections
00190 
00191     getSkinSelections = _getSelections
00192 
00193     def getId(self):
00194         return 'portal_skins'
00195 
00196     def getSkinPaths(self):
00197         result = list(self._selections.items())
00198         result.sort()
00199         return result
00200 
00201     def addSkinSelection(self, skinname, skinpath, test=0, make_default=0):
00202         self._selections[skinname] = skinpath
00203 
00204     def manage_skinLayers(self, chosen=(), add_skin=0, del_skin=0,
00205                           skinname='', skinpath='', REQUEST=None):
00206         if del_skin:
00207             for skin_name in chosen:
00208                 del self._selections[skin_name]
00209 
00210 
00211 class _DVRegistrySetup:
00212 
00213     def setUp(self):
00214         from Products.CMFCore import DirectoryView
00215 
00216         self._olddirreg = DirectoryView._dirreg
00217         DirectoryView._dirreg = DirectoryView.DirectoryRegistry()
00218         self._dirreg = DirectoryView._dirreg
00219         self._dirreg.registerDirectory('one', globals())
00220         self._dirreg.registerDirectory('two', globals())
00221         self._dirreg.registerDirectory('three', globals())
00222         self._dirreg.registerDirectory('four', globals())
00223 
00224     def tearDown(self):
00225         from Products.CMFCore import DirectoryView
00226 
00227         DirectoryView._dirreg = self._olddirreg
00228 
00229 
00230 class DirectoryViewAdapterTests(_DVRegistrySetup, NodeAdapterTestCase):
00231 
00232     layer = ExportImportZCMLLayer
00233 
00234     def _getTargetClass(self):
00235         from Products.CMFCore.exportimport.skins \
00236                 import DirectoryViewNodeAdapter
00237 
00238         return DirectoryViewNodeAdapter
00239 
00240     def _populate(self, obj):
00241         obj._dirpath = 'CMFCore/exportimport/tests/one'
00242 
00243     def setUp(self):
00244         from Products.CMFCore.DirectoryView import DirectoryView
00245 
00246         NodeAdapterTestCase.setUp(self)
00247         _DVRegistrySetup.setUp(self)
00248         self._obj = DirectoryView('foo_directoryview').__of__(Folder())
00249         self._XML = _DIRECTORYVIEW_XML
00250 
00251     def tearDown(self):
00252         _DVRegistrySetup.tearDown(self)
00253         NodeAdapterTestCase.tearDown(self)
00254 
00255 
00256 class SkinsToolXMLAdapterTests(_DVRegistrySetup, BodyAdapterTestCase):
00257 
00258     layer = ExportImportZCMLLayer
00259 
00260     def _getTargetClass(self):
00261         from Products.CMFCore.exportimport.skins import SkinsToolXMLAdapter
00262 
00263         return SkinsToolXMLAdapter
00264 
00265     def _populate(self, obj):
00266         from Products.CMFCore.DirectoryView import DirectoryView
00267 
00268         obj._setObject('foo_directoryview',
00269                        DirectoryView('foo_directoryview',
00270                                      'CMFCore/exportimport/tests/one'))
00271         obj.addSkinSelection('foo_path', 'one')
00272 
00273     def _verifyImport(self, obj):
00274         pass
00275 
00276     def setUp(self):
00277         from Products.CMFCore import DirectoryView
00278         from Products.CMFCore.SkinsTool import SkinsTool
00279 
00280         BodyAdapterTestCase.setUp(self)
00281         _DVRegistrySetup.setUp(self)
00282         self._obj = SkinsTool()
00283         self._BODY = _SKINSTOOL_BODY
00284 
00285     def tearDown(self):
00286         _DVRegistrySetup.tearDown(self)
00287         BodyAdapterTestCase.tearDown(self)
00288 
00289 
00290 class _SkinsSetup(_DVRegistrySetup, BaseRegistryTests):
00291 
00292     def _initSite(self, selections={}, ids=()):
00293         from Products.CMFCore.DirectoryView import DirectoryView
00294 
00295         site = DummySite()
00296         fsdvs = [ (id, DirectoryView(id, 'CMFCore/exportimport/tests/%s' %
00297                                          id)) for id in ids ]
00298         site._setObject('portal_skins', DummySkinsTool(selections, fsdvs))
00299 
00300         site.REQUEST = 'exists'
00301         return site
00302 
00303     def setUp(self):
00304         BaseRegistryTests.setUp(self)
00305         _DVRegistrySetup.setUp(self)
00306 
00307     def tearDown(self):
00308         _DVRegistrySetup.tearDown(self)
00309         BaseRegistryTests.tearDown(self)
00310 
00311 
00312 class exportSkinsToolTests(_SkinsSetup):
00313 
00314     layer = ExportImportZCMLLayer
00315 
00316     def test_empty(self):
00317         from Products.CMFCore.exportimport.skins import exportSkinsTool
00318 
00319         site = self._initSite()
00320         context = DummyExportContext(site)
00321         exportSkinsTool(context)
00322 
00323         self.assertEqual(len(context._wrote), 1)
00324         filename, text, content_type = context._wrote[0]
00325         self.assertEqual(filename, 'skins.xml')
00326         self._compareDOM(text, _EMPTY_EXPORT)
00327         self.assertEqual(content_type, 'text/xml')
00328 
00329     def test_normal(self):
00330         from Products.CMFCore.exportimport.skins import exportSkinsTool
00331 
00332         _IDS = ('one', 'two', 'three')
00333         _PATHS = {'basic': 'one', 'fancy': 'three, two, one'}
00334 
00335         site = self._initSite(selections=_PATHS, ids=_IDS)
00336         tool = site.portal_skins
00337         tool.default_skin = 'basic'
00338         tool.request_varname = 'skin_var'
00339         tool.allow_any = True
00340         tool.cookie_persistence = True
00341 
00342         context = DummyExportContext(site)
00343         exportSkinsTool(context)
00344 
00345         self.assertEqual(len(context._wrote), 1)
00346         filename, text, content_type = context._wrote[0]
00347         self.assertEqual(filename, 'skins.xml')
00348         self._compareDOM(text, _NORMAL_EXPORT)
00349         self.assertEqual(content_type, 'text/xml')
00350 
00351 
00352 class importSkinsToolTests(_SkinsSetup):
00353 
00354     layer = ExportImportZCMLLayer
00355 
00356     _EMPTY_EXPORT = _EMPTY_EXPORT
00357     _FRAGMENT1_IMPORT = _FRAGMENT1_IMPORT
00358     _FRAGMENT2_IMPORT = _FRAGMENT2_IMPORT
00359     _FRAGMENT3_IMPORT = _FRAGMENT3_IMPORT
00360     _FRAGMENT4_IMPORT = _FRAGMENT4_IMPORT
00361     _FRAGMENT5_IMPORT = _FRAGMENT5_IMPORT
00362     _FRAGMENT6_IMPORT = _FRAGMENT6_IMPORT
00363     _NORMAL_EXPORT = _NORMAL_EXPORT
00364 
00365 
00366     def test_remove_skin_path(self):
00367         from Products.CMFCore.exportimport.skins import importSkinsTool
00368 
00369         _IDS = ('one', 'two', 'three')
00370         _PATHS = {'basic': 'one', 'fancy': 'three, two, one'}
00371 
00372         site = self._initSite(selections=_PATHS, ids=_IDS)
00373         skins_tool = site.portal_skins
00374         self.failUnless(skins_tool._getSelections().has_key('fancy'))
00375 
00376         context = DummyImportContext(site)
00377         context._files['skins.xml'] = self._FRAGMENT6_IMPORT
00378         importSkinsTool(context)
00379 
00380         self.failIf(skins_tool._getSelections().has_key('fancy'))
00381 
00382 
00383     def test_empty_default_purge(self):
00384         from Products.CMFCore.exportimport.skins import importSkinsTool
00385 
00386         _IDS = ('one', 'two', 'three')
00387         _PATHS = {'basic': 'one', 'fancy': 'three, two, one'}
00388 
00389         site = self._initSite(selections=_PATHS, ids=_IDS)
00390         skins_tool = site.portal_skins
00391 
00392         self.failIf(site._skin_setup_called)
00393         self.assertEqual(len(skins_tool.getSkinPaths()), 2)
00394         self.assertEqual(len(skins_tool.objectItems()), 3)
00395 
00396         context = DummyImportContext(site)
00397         context._files['skins.xml'] = self._EMPTY_EXPORT
00398         importSkinsTool(context)
00399 
00400         self.assertEqual(skins_tool.default_skin, "default_skin")
00401         self.assertEqual(skins_tool.request_varname, "request_varname")
00402         self.failIf(skins_tool.allow_any)
00403         self.failIf(skins_tool.cookie_persistence)
00404         self.failUnless(site._skin_setup_called)
00405         self.assertEqual(len(skins_tool.getSkinPaths()), 0)
00406         self.assertEqual(len(skins_tool.objectItems()), 0)
00407 
00408     def test_empty_explicit_purge(self):
00409         from Products.CMFCore.exportimport.skins import importSkinsTool
00410 
00411         _IDS = ('one', 'two', 'three')
00412         _PATHS = {'basic': 'one', 'fancy': 'three, two, one'}
00413 
00414         site = self._initSite(selections=_PATHS, ids=_IDS)
00415         skins_tool = site.portal_skins
00416 
00417         self.failIf(site._skin_setup_called)
00418         self.assertEqual(len(skins_tool.getSkinPaths()), 2)
00419         self.assertEqual(len(skins_tool.objectItems()), 3)
00420 
00421         context = DummyImportContext(site, True)
00422         context._files['skins.xml'] = self._EMPTY_EXPORT
00423         importSkinsTool(context)
00424 
00425         self.assertEqual(skins_tool.default_skin, "default_skin")
00426         self.assertEqual(skins_tool.request_varname, "request_varname")
00427         self.failIf(skins_tool.allow_any)
00428         self.failIf(skins_tool.cookie_persistence)
00429         self.failUnless(site._skin_setup_called)
00430         self.assertEqual(len(skins_tool.getSkinPaths()), 0)
00431         self.assertEqual(len(skins_tool.objectItems()), 0)
00432 
00433     def test_empty_skip_purge(self):
00434         from Products.CMFCore.exportimport.skins import importSkinsTool
00435 
00436         _IDS = ('one', 'two', 'three')
00437         _PATHS = {'basic': 'one', 'fancy': 'three, two, one'}
00438 
00439         site = self._initSite(selections=_PATHS, ids=_IDS)
00440         skins_tool = site.portal_skins
00441 
00442         self.failIf(site._skin_setup_called)
00443         self.assertEqual(len(skins_tool.getSkinPaths()), 2)
00444         self.assertEqual(len(skins_tool.objectItems()), 3)
00445 
00446         context = DummyImportContext(site, False)
00447         context._files['skins.xml'] = self._EMPTY_EXPORT
00448         importSkinsTool(context)
00449 
00450         self.assertEqual(skins_tool.default_skin, "default_skin")
00451         self.assertEqual(skins_tool.request_varname, "request_varname")
00452         self.failIf(skins_tool.allow_any)
00453         self.failIf(skins_tool.cookie_persistence)
00454         self.failUnless(site._skin_setup_called)
00455         self.assertEqual(len(skins_tool.getSkinPaths()), 2)
00456         self.assertEqual(len(skins_tool.objectItems()), 3)
00457 
00458     def test_normal(self):
00459         from Products.CMFCore.exportimport.skins import importSkinsTool
00460 
00461         site = self._initSite()
00462         skins_tool = site.portal_skins
00463 
00464         self.failIf(site._skin_setup_called)
00465         self.assertEqual(len(skins_tool.getSkinPaths()), 0)
00466         self.assertEqual(len(skins_tool.objectItems()), 0)
00467 
00468         context = DummyImportContext(site)
00469         context._files['skins.xml'] = self._NORMAL_EXPORT
00470         importSkinsTool(context)
00471 
00472         self.assertEqual(skins_tool.default_skin, "basic")
00473         self.assertEqual(skins_tool.request_varname, "skin_var")
00474         self.failUnless(skins_tool.allow_any)
00475         self.failUnless(skins_tool.cookie_persistence)
00476         self.failUnless(site._skin_setup_called)
00477         self.assertEqual(len(skins_tool.getSkinPaths()), 2)
00478         self.assertEqual(len(skins_tool.objectItems()), 3)
00479 
00480     def test_fragment_skip_purge(self):
00481         from Products.CMFCore.exportimport.skins import importSkinsTool
00482 
00483         _IDS = ('one', 'two')
00484         _PATHS = {'basic': 'one', 'fancy': 'two,one'}
00485 
00486         site = self._initSite(selections=_PATHS, ids=_IDS)
00487         skins_tool = site.portal_skins
00488 
00489         self.failIf(site._skin_setup_called)
00490         skin_paths = skins_tool.getSkinPaths()
00491         self.assertEqual(len(skin_paths), 2)
00492         self.assertEqual(skin_paths[0], ('basic', 'one'))
00493         self.assertEqual(skin_paths[1], ('fancy', 'two,one'))
00494         self.assertEqual(len(skins_tool.objectItems()), 2)
00495 
00496         context = DummyImportContext(site, False)
00497         context._files['skins.xml'] = self._FRAGMENT1_IMPORT
00498         importSkinsTool(context)
00499 
00500         self.assertEqual(skins_tool.default_skin, "default_skin")
00501         self.assertEqual(skins_tool.request_varname, "request_varname")
00502         self.failIf(skins_tool.allow_any)
00503         self.failIf(skins_tool.cookie_persistence)
00504         self.failUnless(site._skin_setup_called)
00505         skin_paths = skins_tool.getSkinPaths()
00506         self.assertEqual(len(skin_paths), 2)
00507         self.assertEqual(skin_paths[0], ('basic', 'one,three'))
00508         self.assertEqual(skin_paths[1], ('fancy', 'three,two,one'))
00509         self.assertEqual(len(skins_tool.objectItems()), 3)
00510 
00511         context._files['skins.xml'] = self._FRAGMENT2_IMPORT
00512         importSkinsTool(context)
00513 
00514         self.assertEqual(skins_tool.default_skin, "default_skin")
00515         self.assertEqual(skins_tool.request_varname, "request_varname")
00516         self.failIf(skins_tool.allow_any)
00517         self.failIf(skins_tool.cookie_persistence)
00518         self.failUnless(site._skin_setup_called)
00519         skin_paths = skins_tool.getSkinPaths()
00520         self.assertEqual(len(skin_paths), 2)
00521         self.assertEqual(skin_paths[0], ('basic', 'one,three,four'))
00522         self.assertEqual(skin_paths[1], ('fancy', 'three,four,two,one'))
00523         self.assertEqual(len(skins_tool.objectItems()), 4)
00524 
00525     def test_fragment3_skip_purge(self):
00526         from Products.CMFCore.exportimport.skins import importSkinsTool
00527 
00528         _IDS = ('one', 'two')
00529         _PATHS = {'basic': 'one', 'fancy': 'two,one'}
00530 
00531         site = self._initSite(selections=_PATHS, ids=_IDS)
00532         skins_tool = site.portal_skins
00533 
00534         self.failIf(site._skin_setup_called)
00535         skin_paths = skins_tool.getSkinPaths()
00536         self.assertEqual(len(skin_paths), 2)
00537         self.assertEqual(skin_paths[0], ('basic', 'one'))
00538         self.assertEqual(skin_paths[1], ('fancy', 'two,one'))
00539         self.assertEqual(len(skins_tool.objectItems()), 2)
00540 
00541         context = DummyImportContext(site, False)
00542         context._files['skins.xml'] = self._FRAGMENT3_IMPORT
00543         importSkinsTool(context)
00544 
00545         self.assertEqual(skins_tool.default_skin, "default_skin")
00546         self.assertEqual(skins_tool.request_varname, "request_varname")
00547         self.failIf(skins_tool.allow_any)
00548         self.failIf(skins_tool.cookie_persistence)
00549         self.failUnless(site._skin_setup_called)
00550         skin_paths = skins_tool.getSkinPaths()
00551         self.assertEqual(len(skin_paths), 2)
00552         self.assertEqual(skin_paths[0], ('basic', 'three,one,four'))
00553         self.assertEqual(skin_paths[1],
00554                           ('fancy', 'three,two,one,four'))
00555         self.assertEqual(len(skins_tool.objectItems()), 4)
00556 
00557     def test_fragment4_removal(self):
00558         from Products.CMFCore.exportimport.skins import importSkinsTool
00559 
00560         _IDS = ('one', 'two')
00561         _PATHS = {'basic': 'one', 'fancy': 'two,one'}
00562 
00563         site = self._initSite(selections=_PATHS, ids=_IDS)
00564         skins_tool = site.portal_skins
00565 
00566         skin_paths = skins_tool.getSkinPaths()
00567         self.assertEqual(len(skin_paths), 2)
00568         self.assertEqual(skin_paths[0], ('basic', 'one'))
00569         self.assertEqual(skin_paths[1], ('fancy', 'two,one'))
00570         self.assertEqual(len(skins_tool.objectItems()), 2)
00571 
00572         context = DummyImportContext(site, False)
00573         context._files['skins.xml'] = self._FRAGMENT3_IMPORT
00574         importSkinsTool(context)
00575 
00576         self.failUnless(site._skin_setup_called)
00577         skin_paths = skins_tool.getSkinPaths()
00578         self.assertEqual(len(skin_paths), 2)
00579         self.assertEqual(skin_paths[0], ('basic', 'three,one,four'))
00580         self.assertEqual(skin_paths[1], ('fancy', 'three,two,one,four'))
00581         self.assertEqual(len(skins_tool.objectItems()), 4)
00582 
00583         context = DummyImportContext(site, False)
00584         context._files['skins.xml'] = self._FRAGMENT4_IMPORT
00585 
00586         importSkinsTool(context)
00587 
00588         self.failUnless(site._skin_setup_called)
00589         skin_paths = skins_tool.getSkinPaths()
00590         self.assertEqual(len(skin_paths), 2)
00591         self.assertEqual(skin_paths[0], ('basic', 'one,four'))
00592         self.assertEqual(skin_paths[1], ('fancy', 'two,one,four'))
00593         self.assertEqual(len(skins_tool.objectItems()), 4)
00594 
00595     def test_fragment5_based_skin(self):
00596         from Products.CMFCore.exportimport.skins import importSkinsTool
00597 
00598         _IDS = ('one', 'two', 'three', 'four')
00599         _PATHS = {'basic': 'one,three,four', 'existing': 'one,two,four'}
00600 
00601         site = self._initSite(selections=_PATHS, ids=_IDS)
00602         skins_tool = site.portal_skins
00603 
00604         skin_paths = skins_tool.getSkinPaths()
00605         self.assertEqual(len(skin_paths), 2)
00606         self.assertEqual(skin_paths[0], ('basic', 'one,three,four'))
00607         self.assertEqual(skin_paths[1], ('existing', 'one,two,four'))
00608         self.assertEqual(len(skins_tool.objectItems()), 4)
00609 
00610         context = DummyImportContext(site, False)
00611         context._files['skins.xml'] = self._FRAGMENT5_IMPORT
00612 
00613         importSkinsTool(context)
00614 
00615         self.failUnless(site._skin_setup_called)
00616         skin_paths = skins_tool.getSkinPaths()
00617         self.assertEqual(len(skin_paths), 4)
00618         self.assertEqual(skin_paths[0], ('basic', 'one,three,four'))
00619         self.assertEqual(skin_paths[1], ('existing', 'one,two,three,four'))
00620         self.assertEqual(skin_paths[2], ('new', 'one,two,three,four'))
00621         self.assertEqual(skin_paths[3], ('wrongbase', 'two'))
00622         self.assertEqual(len(skins_tool.objectItems()), 4)
00623 
00624 
00625 def test_suite():
00626     # reimport to make sure tests are run from Products
00627     from Products.CMFCore.exportimport.tests.test_skins \
00628             import DirectoryViewAdapterTests
00629     from Products.CMFCore.exportimport.tests.test_skins \
00630             import exportSkinsToolTests
00631     from Products.CMFCore.exportimport.tests.test_skins \
00632             import importSkinsToolTests
00633     from Products.CMFCore.exportimport.tests.test_skins \
00634             import SkinsToolXMLAdapterTests
00635 
00636     return unittest.TestSuite((
00637         unittest.makeSuite(DirectoryViewAdapterTests),
00638         unittest.makeSuite(SkinsToolXMLAdapterTests),
00639         unittest.makeSuite(exportSkinsToolTests),
00640         unittest.makeSuite(importSkinsToolTests),
00641         ))
00642 
00643 if __name__ == '__main__':
00644     from Products.CMFCore.testing import run
00645     run(test_suite())