Back to index

plone3  3.1.7
testCSSRegistry.py
Go to the documentation of this file.
00001 #
00002 # CSSRegistry Tests
00003 #
00004 from zope.component import getUtility, getMultiAdapter
00005 from zope.contentprovider.interfaces import IContentProvider
00006 
00007 from App.Common import rfc1123_date
00008 from DateTime import DateTime
00009 from AccessControl import Unauthorized
00010 from zope.interface.verify import verifyObject
00011 
00012 from Products.CMFCore.utils import getToolByName
00013 
00014 from Products.PloneTestCase.PloneTestCase import PLONE21, portal_owner, default_password
00015 
00016 from Products.ResourceRegistries.config import CSSTOOLNAME
00017 from Products.ResourceRegistries.interfaces import ICSSRegistry
00018 from Products.ResourceRegistries.tests.RegistryTestCase import RegistryTestCase
00019 from Products.ResourceRegistries.tests.RegistryTestCase import FunctionalRegistryTestCase
00020 
00021 
00022 class TestImplementation(RegistryTestCase):
00023 
00024     def test_interfaces(self):
00025         tool = getattr(self.portal, CSSTOOLNAME)
00026         self.failUnless(ICSSRegistry.providedBy(tool))
00027         self.failUnless(verifyObject(ICSSRegistry, tool))
00028 
00029 class TestTool(RegistryTestCase):
00030 
00031     def testToolExists(self):
00032         self.failUnless(CSSTOOLNAME in self.portal.objectIds())
00033 
00034     def testZMIForm(self):
00035         tool = getattr(self.portal, CSSTOOLNAME)
00036         self.setRoles(['Manager'])
00037         self.failUnless(tool.manage_cssForm())
00038         self.failUnless(tool.manage_cssComposition())
00039 
00040 
00041 class TestSkin(RegistryTestCase):
00042 
00043     def testSkins(self):
00044         skins = self.portal.portal_skins.objectIds()
00045         self.failUnless('ResourceRegistries' in skins)
00046 
00047     def testSkinExists(self):
00048         self.failUnless(getattr(self.portal, 'test_rr_1.css'))
00049 
00050 
00051 class testZMIMethods(RegistryTestCase):
00052 
00053     def afterSetUp(self):
00054         self.tool = getattr(self.portal, CSSTOOLNAME)
00055         self.tool.clearResources()
00056 
00057     def testAdd(self):
00058         self.tool.manage_addStylesheet(id='joe')
00059         self.assertEqual(len(self.tool.getResources()), 1)
00060         self.failUnless(self.tool.getResources())
00061 
00062 
00063 class TestStylesheetRegistration(RegistryTestCase):
00064 
00065     def afterSetUp(self):
00066         self.tool = getattr(self.portal, CSSTOOLNAME)
00067         self.tool.clearResources()
00068 
00069     def testStoringStylesheet(self):
00070         self.tool.registerStylesheet('foo')
00071         self.assertEqual(len(self.tool.getResources()), 1)
00072         self.assertEqual(self.tool.getResources()[0].getId(), 'foo')
00073 
00074     def testDefaultStylesheetAttributes(self):
00075         self.tool.registerStylesheet('foodefault')
00076         self.assertEqual(self.tool.getResources()[0].getId(), 'foodefault')
00077         self.assertEqual(self.tool.getResources()[0].getExpression(), '')
00078         self.assertEqual(self.tool.getResources()[0].getMedia(), None)
00079         self.assertEqual(self.tool.getResources()[0].getRel(), 'stylesheet')
00080         self.assertEqual(self.tool.getResources()[0].getTitle(), None)
00081         self.assertEqual(self.tool.getResources()[0].getRendering(), 'import')
00082         self.failUnless(self.tool.getResources()[0].getEnabled())
00083 
00084     def testStylesheetAttributes(self):
00085         self.tool.registerStylesheet('foo', expression='python:1',
00086                                      media='print', rel='alternate stylesheet',
00087                                      title='Foo', rendering='inline', enabled=0)
00088         self.assertEqual(self.tool.getResources()[0].getId(), 'foo')
00089         self.assertEqual(self.tool.getResources()[0].getExpression(), 'python:1')
00090         self.assertEqual(self.tool.getResources()[0].getMedia(), 'print')
00091         self.assertEqual(self.tool.getResources()[0].getRel(), 'alternate stylesheet')
00092         self.assertEqual(self.tool.getResources()[0].getTitle(), 'Foo')
00093         self.assertEqual(self.tool.getResources()[0].getRendering(), 'inline')
00094         self.failIf(self.tool.getResources()[0].getEnabled())
00095 
00096     def testDisallowingDuplicateIds(self):
00097         self.tool.registerStylesheet('foo')
00098         self.assertRaises(ValueError, self.tool.registerStylesheet, 'foo')
00099 
00100     def testPloneCustomStaysOnTop(self):
00101         self.tool.registerStylesheet('foo')
00102         self.tool.registerStylesheet('ploneCustom.css')
00103         self.tool.registerStylesheet('bar')
00104         self.assertEqual(len(self.tool.getResources()), 3)
00105         self.assertEqual(self.tool.getResourceIds(),
00106                          ('foo', 'bar', 'ploneCustom.css'))
00107 
00108     def testUnregisterStylesheet(self):
00109         self.tool.registerStylesheet('foo')
00110         self.assertEqual(len(self.tool.getResources()), 1)
00111         self.assertEqual(self.tool.getResources()[0].getId(), 'foo')
00112         self.tool.unregisterResource('foo')
00113         self.assertEqual(len(self.tool.getResources()), 0)
00114 
00115     def testStylesheetsDict(self):
00116         self.tool.registerStylesheet('spam')
00117         self.tool.registerStylesheet('ham')
00118         keys = self.tool.getResourcesDict().keys()
00119         keys.sort()
00120         res = ['ham', 'spam']
00121         res.sort()
00122         self.assertEqual(res, keys)
00123         self.assertEqual(self.tool.getResourcesDict()['ham'].getId(), 'ham')
00124 
00125 
00126 class TestStylesheetRenaming(RegistryTestCase):
00127 
00128     def afterSetUp(self):
00129         self.tool = getattr(self.portal, CSSTOOLNAME)
00130         self.tool.clearResources()
00131 
00132     def testRenaming(self):
00133         self.tool.registerStylesheet('ham')
00134         self.tool.registerStylesheet('spam')
00135         self.tool.registerStylesheet('eggs')
00136         self.assertEqual(self.tool.concatenatedresources[
00137                          self.tool.cookedresources[0].getId()],
00138                          ['ham', 'spam', 'eggs'])
00139         self.tool.renameResource('spam', 'bacon')
00140         self.assertEqual(self.tool.concatenatedresources[
00141                          self.tool.cookedresources[0].getId()],
00142                          ['ham', 'bacon', 'eggs'])
00143 
00144     def testRenamingIdClash(self):
00145         self.tool.registerStylesheet('ham')
00146         self.tool.registerStylesheet('spam')
00147         self.tool.registerStylesheet('eggs')
00148         self.assertRaises(ValueError, self.tool.renameResource, 'spam', 'eggs')
00149 
00150     def testDoubleRenaming(self):
00151         self.tool.registerStylesheet('ham')
00152         self.tool.registerStylesheet('spam')
00153         self.tool.registerStylesheet('eggs')
00154         self.tool.renameResource('spam', 'bacon')
00155         self.assertRaises(ValueError, self.tool.renameResource, 'spam', 'bacon')
00156 
00157 
00158 class TestToolSecurity(RegistryTestCase):
00159 
00160     def afterSetUp(self):
00161         self.tool = getattr(self.portal, CSSTOOLNAME)
00162         self.tool.clearResources()
00163 
00164     def testRegistrationSecurity(self):
00165         self.assertRaises(Unauthorized, self.tool.restrictedTraverse,
00166                           'registerStylesheet')
00167         self.assertRaises(Unauthorized, self.tool.restrictedTraverse,
00168                           'unregisterResource')
00169         self.setRoles(['Manager'])
00170         try:
00171             self.tool.restrictedTraverse('registerStylesheet')
00172             self.tool.restrictedTraverse('unregisterResource')
00173         except Unauthorized:
00174             self.fail()
00175 
00176 
00177 class TestToolExpression(RegistryTestCase):
00178 
00179     def afterSetUp(self):
00180         self.tool = getattr(self.portal, CSSTOOLNAME)
00181         self.tool.clearResources()
00182 
00183     def testSimplestExpression(self):
00184         context = self.portal
00185         self.failUnless(self.tool.evaluateExpression('python:1', context))
00186         self.failIf(self.tool.evaluateExpression('python:0', context))
00187         self.failUnless(self.tool.evaluateExpression('python:0+1', context))
00188 
00189     def testNormalExpression(self):
00190         context = self.portal
00191         self.failUnless(self.tool.evaluateExpression('object/absolute_url',
00192                                                      context))
00193 
00194     def testExpressionInFolder(self):
00195         self.folder.invokeFactory('Document', 'eggs')
00196         context = self.folder
00197         self.failUnless(self.tool.evaluateExpression(
00198                         'python:"eggs" in object.objectIds()', context))
00199 
00200 
00201 class TestStylesheetCooking(RegistryTestCase):
00202 
00203     def afterSetUp(self):
00204         self.tool = getattr(self.portal, CSSTOOLNAME)
00205         self.tool.clearResources()
00206 
00207     def testStylesheetCooking(self):
00208         self.tool.registerStylesheet('ham')
00209         self.tool.registerStylesheet('spam')
00210         self.tool.registerStylesheet('eggs')
00211         self.assertEqual(len(self.tool.getResources()), 3)
00212         self.assertEqual(len(self.tool.cookedresources), 1)
00213         self.assertEqual(len(self.tool.concatenatedresources.keys()), 4)
00214         self.tool.setAutoGroupingMode(True)
00215         self.assertEqual(len(self.tool.getResources()), 3)
00216         self.assertEqual(len(self.tool.cookedresources), 1)
00217         self.assertEqual(len(self.tool.concatenatedresources.keys()), 4)
00218 
00219     def testStylesheetCookingValues(self):
00220         self.tool.registerStylesheet('ham')
00221         self.tool.registerStylesheet('spam')
00222         self.tool.registerStylesheet('eggs')
00223         self.assertEqual(self.tool.concatenatedresources[
00224                          self.tool.cookedresources[0].getId()],
00225                          ['ham', 'spam', 'eggs'])
00226 
00227     def testGetEvaluatedStylesheetsCollapsing(self):
00228         self.tool.registerStylesheet('ham')
00229         self.tool.registerStylesheet('spam')
00230         self.tool.registerStylesheet('eggs')
00231         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00232 
00233     def testMoreComplexStylesheetsCollapsing(self):
00234         self.tool.registerStylesheet('ham')
00235         self.tool.registerStylesheet('spam', expression='string:spam')
00236         self.tool.registerStylesheet('spam spam', expression='string:spam')
00237         self.tool.registerStylesheet('spam spam spam', expression='string:spam')
00238         self.tool.registerStylesheet('eggs')
00239         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 3)
00240         magic_ids = [item.getId() for item in self.tool.getEvaluatedResources(self.folder)]
00241         self.failUnless('ham' in self.tool.concatenatedresources[magic_ids[0]])
00242         self.failUnless('eggs' in self.tool.concatenatedresources[magic_ids[2]])
00243         self.failUnless('spam' in self.tool.concatenatedresources[magic_ids[1]])
00244         self.failUnless('spam spam' in self.tool.concatenatedresources[magic_ids[1]])
00245         self.failUnless('spam spam spam' in self.tool.concatenatedresources[magic_ids[1]])
00246 
00247         self.tool.setAutoGroupingMode(True)
00248         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 2)
00249         magic_ids = [item.getId() for item in self.tool.getEvaluatedResources(self.folder)]
00250         self.failUnless('ham' in self.tool.concatenatedresources[magic_ids[0]])
00251         self.failUnless('eggs' in self.tool.concatenatedresources[magic_ids[0]])
00252         self.failUnless('spam' in self.tool.concatenatedresources[magic_ids[1]])
00253         self.failUnless('spam spam' in self.tool.concatenatedresources[magic_ids[1]])
00254         self.failUnless('spam spam spam' in self.tool.concatenatedresources[magic_ids[1]])
00255 
00256     def testConcatenatedStylesheetsHaveNoMedia(self):
00257         self.tool.registerStylesheet('ham')
00258         self.tool.registerStylesheet('spam', media='print')
00259         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00260         self.failIf(self.tool.getEvaluatedResources(self.folder)[0].getMedia())
00261 
00262     def testGetEvaluatedStylesheetsWithExpression(self):
00263         self.tool.registerStylesheet('ham')
00264         self.tool.registerStylesheet('spam', expression='python:1')
00265         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 2)
00266         self.tool.setAutoGroupingMode(True)
00267         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 2)
00268 
00269     def testGetEvaluatedStylesheetsWithFailingExpression(self):
00270         self.tool.registerStylesheet('ham')
00271         self.tool.registerStylesheet('spam', expression='python:0')
00272         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00273         self.tool.setAutoGroupingMode(True)
00274         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00275 
00276     def testGetEvaluatedStylesheetsWithContextualExpression(self):
00277         self.folder.invokeFactory('Document', 'eggs')
00278         self.tool.registerStylesheet('spam', expression='python:"eggs" in object.objectIds()')
00279         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00280         self.tool.setAutoGroupingMode(True)
00281         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00282 
00283     def testCollapsingStylesheetsLookup(self):
00284         self.tool.registerStylesheet('ham')
00285         self.tool.registerStylesheet('spam', expression='string:ham')
00286         self.tool.registerStylesheet('spam spam', expression='string:ham')
00287         evaluated = self.tool.getEvaluatedResources(self.folder)
00288         self.assertEqual(len(evaluated), 2)
00289         self.tool.setAutoGroupingMode(True)
00290         evaluated = self.tool.getEvaluatedResources(self.folder)
00291         self.assertEqual(len(evaluated), 2)
00292 
00293     def testRenderingIsInTheRightOrder(self):
00294         self.tool.registerStylesheet('ham', expression='string:ham')
00295         self.tool.registerStylesheet('spam', expression='string:spam')
00296         evaluated = self.tool.getEvaluatedResources(self.folder)
00297         magic_ids = [item.getId() for item in evaluated]
00298         ids = []
00299         for magic_id in magic_ids:
00300             self.assertEqual(len(self.tool.concatenatedresources[magic_id]), 1)
00301             ids.append(self.tool.concatenatedresources[magic_id][0])
00302         self.failUnless(ids[0] == 'ham')
00303         self.failUnless(ids[1] == 'spam')
00304 
00305     def testConcatenatedSheetsAreInTheRightOrderToo(self):
00306         self.tool.registerStylesheet('ham')
00307         self.tool.registerStylesheet('spam')
00308         self.tool.registerStylesheet('eggs')
00309         evaluated = self.tool.getEvaluatedResources(self.folder)
00310         results = self.tool.concatenatedresources[evaluated[0].getId()]
00311         self.failUnless(results[0] == 'ham')
00312         self.failUnless(results[1] == 'spam')
00313         self.failUnless(results[2] == 'eggs')
00314         self.tool.setAutoGroupingMode(True)
00315         evaluated = self.tool.getEvaluatedResources(self.folder)
00316         results = self.tool.concatenatedresources[evaluated[0].getId()]
00317         self.failUnless(results[0] == 'ham')
00318         self.failUnless(results[1] == 'spam')
00319         self.failUnless(results[2] == 'eggs')
00320 
00321     def testRenderingStylesheetLinks(self):
00322         self.tool.registerStylesheet('ham', rendering='link')
00323         self.tool.registerStylesheet('ham 2 b merged', rendering='link')
00324         self.tool.registerStylesheet('spam', expression='string:ham', rendering='link')
00325         self.tool.registerStylesheet('test_rr_1.css', rendering='inline')
00326         view = self.portal.restrictedTraverse('@@plone')
00327         viewletmanager = getMultiAdapter((self.portal, self.portal.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
00328         viewletmanager.update()
00329         all = viewletmanager.render()
00330         evaluated = self.tool.getEvaluatedResources(self.folder)
00331         magic_ids = [item.getId() for item in evaluated]
00332         self.failUnless('background-color' in all)
00333         self.failUnless('<link' in all)
00334         self.failUnless('/%s' % magic_ids[1] in all)
00335         self.failIf('/test_rr_1.css"' in all)
00336 
00337     def testReenderingConcatenatesInline(self):
00338         self.tool.registerStylesheet('test_rr_1.css', rendering='inline')
00339         self.tool.registerStylesheet('test_rr_2.css', rendering='inline')
00340         view = self.portal.restrictedTraverse('@@plone')
00341         viewletmanager = getMultiAdapter((self.portal, self.portal.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
00342         viewletmanager.update()
00343         all = viewletmanager.render()
00344         self.failUnless('background-color' in all)
00345         self.failUnless('blue' in all)
00346 
00347     def testDifferentMediaAreCollapsed(self):
00348         self.tool.registerStylesheet('test_rr_1.css', media='print')
00349         self.tool.registerStylesheet('test_rr_2.css', media='all')
00350         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00351 
00352     def testDifferentRenderingAreNotCollapsed(self):
00353         self.tool.registerStylesheet('ham', rendering='inline')
00354         self.tool.registerStylesheet('spam', rendering='link')
00355         self.tool.registerStylesheet('egg', rendering='inline')
00356         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 3)
00357         self.tool.setAutoGroupingMode(True)
00358         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 2)
00359 
00360     def testRenderingWorksInMainTemplate(self):
00361         renderedpage = getattr(self.portal, 'index_html')()
00362         self.failIf('background-color' in renderedpage)
00363         self.tool.registerStylesheet('test_rr_1.css', rendering='inline')
00364         renderedpage = getattr(self.portal, 'index_html')()
00365         self.failUnless('background-color' in renderedpage)
00366 
00367 
00368 class TestStylesheetMoving(RegistryTestCase):
00369 
00370     def afterSetUp(self):
00371         self.tool = getattr(self.portal, CSSTOOLNAME)
00372         self.tool.clearResources()
00373 
00374     def testStylesheetMoveDown(self):
00375         self.tool.registerStylesheet('ham')
00376         self.tool.registerStylesheet('spam')
00377         self.tool.registerStylesheet('eggs')
00378         self.assertEqual(self.tool.getResourceIds(),
00379                          ('ham', 'spam', 'eggs'))
00380         self.tool.moveResourceDown('spam')
00381         self.assertEqual(self.tool.getResourceIds(),
00382                          ('ham', 'eggs', 'spam'))
00383 
00384     def testStylesheetMoveDownAtEnd(self):
00385         self.tool.registerStylesheet('ham')
00386         self.tool.registerStylesheet('spam')
00387         self.tool.registerStylesheet('eggs')
00388         self.assertEqual(self.tool.getResourceIds(),
00389                          ('ham', 'spam', 'eggs'))
00390         self.tool.moveResourceDown('eggs')
00391         self.assertEqual(self.tool.getResourceIds(),
00392                          ('ham', 'spam', 'eggs'))
00393 
00394     def testStylesheetMoveUp(self):
00395         self.tool.registerStylesheet('ham')
00396         self.tool.registerStylesheet('spam')
00397         self.tool.registerStylesheet('eggs')
00398         self.assertEqual(self.tool.getResourceIds(),
00399                          ('ham', 'spam', 'eggs'))
00400         self.tool.moveResourceUp('spam')
00401         self.assertEqual(self.tool.getResourceIds(),
00402                          ('spam', 'ham', 'eggs'))
00403 
00404     def testStylesheetMoveUpAtStart(self):
00405         self.tool.registerStylesheet('ham')
00406         self.tool.registerStylesheet('spam')
00407         self.tool.registerStylesheet('eggs')
00408         self.assertEqual(self.tool.getResourceIds(),
00409                          ('ham', 'spam', 'eggs'))
00410         self.tool.moveResourceUp('ham')
00411         self.assertEqual(self.tool.getResourceIds(),
00412                          ('ham', 'spam', 'eggs'))
00413 
00414     def testStylesheetMoveIllegalId(self):
00415         self.tool.registerStylesheet('ham')
00416         self.tool.registerStylesheet('spam')
00417         self.tool.registerStylesheet('eggs')
00418         self.assertEqual(self.tool.getResourceIds(),
00419                          ('ham', 'spam', 'eggs'))
00420         self.assertRaises(ValueError, self.tool.moveResourceUp, 'foo')
00421 
00422     def testStylesheetMoveToBottom(self):
00423         self.tool.registerStylesheet('ham')
00424         self.tool.registerStylesheet('spam')
00425         self.tool.registerStylesheet('eggs')
00426         self.assertEqual(self.tool.getResourceIds(),
00427                          ('ham', 'spam', 'eggs'))
00428         self.tool.moveResourceToBottom('ham')
00429         self.assertEqual(self.tool.getResourceIds(),
00430                          ('spam', 'eggs', 'ham'))
00431 
00432     def testStylesheetMoveToTop(self):
00433         self.tool.registerStylesheet('ham')
00434         self.tool.registerStylesheet('spam')
00435         self.tool.registerStylesheet('eggs')
00436         self.assertEqual(self.tool.getResourceIds(),
00437                          ('ham', 'spam', 'eggs'))
00438         self.tool.moveResourceToTop('eggs')
00439         self.assertEqual(self.tool.getResourceIds(),
00440                          ('eggs', 'ham', 'spam'))
00441 
00442     def testStylesheetMoveBefore(self):
00443         self.tool.registerStylesheet('ham')
00444         self.tool.registerStylesheet('spam')
00445         self.tool.registerStylesheet('eggs')
00446         self.tool.registerStylesheet('bacon')
00447         self.assertEqual(self.tool.getResourceIds(),
00448                          ('ham', 'spam', 'eggs', 'bacon'))
00449         self.tool.moveResourceBefore('bacon', 'ham')
00450         self.assertEqual(self.tool.getResourceIds(),
00451                          ('bacon', 'ham', 'spam', 'eggs'))
00452         self.tool.moveResourceBefore('bacon', 'eggs')
00453         self.assertEqual(self.tool.getResourceIds(),
00454                          ('ham', 'spam', 'bacon', 'eggs'))
00455 
00456     def testStylesheetMoveAfter(self):
00457         self.tool.registerStylesheet('ham')
00458         self.tool.registerStylesheet('spam')
00459         self.tool.registerStylesheet('eggs')
00460         self.tool.registerStylesheet('bacon')
00461         self.assertEqual(self.tool.getResourceIds(),
00462                          ('ham', 'spam', 'eggs', 'bacon'))
00463         self.tool.moveResourceAfter('bacon', 'ham')
00464         self.assertEqual(self.tool.getResourceIds(),
00465                          ('ham', 'bacon', 'spam', 'eggs'))
00466         self.tool.moveResourceAfter('bacon', 'spam')
00467         self.assertEqual(self.tool.getResourceIds(),
00468                          ('ham', 'spam', 'bacon', 'eggs'))
00469 
00470     def testStylesheetMove(self):
00471         self.tool.registerStylesheet('ham')
00472         self.tool.registerStylesheet('spam')
00473         self.tool.registerStylesheet('eggs')
00474         self.tool.registerStylesheet('bacon')
00475         self.assertEqual(self.tool.getResourceIds(),
00476                          ('ham', 'spam', 'eggs', 'bacon'))
00477         self.tool.moveResource('ham', 2)
00478         self.assertEqual(self.tool.getResourceIds(),
00479                          ('spam', 'eggs', 'ham', 'bacon'))
00480         self.tool.moveResource('bacon', 0)
00481         self.assertEqual(self.tool.getResourceIds(),
00482                          ('bacon', 'spam', 'eggs', 'ham'))
00483 
00484 
00485 class TestTraversal(RegistryTestCase):
00486 
00487     def afterSetUp(self):
00488         self.tool = getattr(self.portal, CSSTOOLNAME)
00489         self.tool.clearResources()
00490         self.tool.registerStylesheet('test_rr_1.css')
00491 
00492     def testGetItemTraversal(self):
00493         self.failUnless(self.tool['test_rr_1.css'])
00494 
00495     def testGetItemTraversalContent(self):
00496         self.failUnless('background-color' in str(self.tool['test_rr_1.css']))
00497 
00498     def testRestrictedTraverseContent(self):
00499         self.failUnless('background-color' in str(
00500                         self.portal.restrictedTraverse('portal_css/test_rr_1.css')))
00501 
00502     def testRestrictedTraverseComposition(self):
00503         self.tool.registerStylesheet('test_rr_2.css')
00504         styles = self.tool.getEvaluatedResources(self.portal)
00505         self.assertEqual(len(styles), 1)
00506         magicId = styles[0].getId()
00507         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00508         self.failUnless('background-color' in content)
00509         self.failUnless('blue' in content)
00510 
00511     def testCompositesWithBrokedId(self):
00512         self.tool.registerStylesheet('nonexistant.css')
00513         stylesheets = self.tool.getEvaluatedResources(self.portal)
00514         self.assertEqual(len(stylesheets), 1)
00515         magicId = stylesheets[0].getId()
00516         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00517 
00518     def testMediadescriptorsInConcatenatedStylesheets(self):
00519         self.tool.registerStylesheet('test_rr_2.css', media='print')
00520         styles = self.tool.getEvaluatedResources(self.portal)
00521         self.assertEqual(len(styles), 1)
00522         magicId = styles[0].getId()
00523         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00524         self.failUnless('@media print' in content)
00525         self.failUnless('background-color : red' in content)
00526         self.failUnless('H1 { color: blue; }' in content)
00527 
00528 class TestZODBTraversal(RegistryTestCase):
00529 
00530     def afterSetUp(self):
00531         self.tool = getattr(self.portal, CSSTOOLNAME)
00532         self.tool.clearResources()
00533         self.setRoles(['Manager'])
00534         self.portal.invokeFactory('File',
00535                                    id='testroot.css',
00536                                    format='text/css',
00537                                    content_type='text/css',
00538                                    file='body { background-color : red }')
00539         self.portal.invokeFactory('Folder', 'subfolder')
00540         self.portal.subfolder.invokeFactory('File',
00541                                    id='testsubfolder.css',
00542                                    format='text/css',
00543                                    content_type='text/css',
00544                                    file='body { background-color : blue }')
00545 
00546         self.tool.registerStylesheet('testroot.css')
00547         self.tool.registerStylesheet('subfolder/testsubfolder.css')
00548         self.setRoles(['Member'])
00549 
00550     def testGetItemTraversal(self):
00551         self.failUnless(self.tool['testroot.css'])
00552         self.failUnless(self.tool['subfolder/testsubfolder.css'])
00553 
00554     def testGetItemTraversalContent(self):
00555         self.failUnless('red' in str(self.tool['testroot.css']))
00556         self.failUnless('blue' in str(self.tool['subfolder/testsubfolder.css']))
00557         self.failIf('blue' in str(self.tool['testroot.css']))
00558         self.failIf('red' in str(self.tool['subfolder/testsubfolder.css']))
00559 
00560 
00561     def testRestrictedTraverseContent(self):
00562         self.failUnless('red' in str(
00563                         self.portal.restrictedTraverse('portal_css/testroot.css')))
00564         self.failUnless('blue' in str(
00565                         self.portal.restrictedTraverse('portal_css/subfolder/testsubfolder.css')))
00566         self.failIf('blue' in str(
00567                         self.portal.restrictedTraverse('portal_css/testroot.css')))
00568         self.failIf('red' in str(
00569                         self.portal.restrictedTraverse('portal_css/subfolder/testsubfolder.css')))
00570 
00571     def testRestrictedTraverseComposition(self):
00572         styles = self.tool.getEvaluatedResources(self.portal)
00573         self.assertEqual(len(styles), 1)
00574         magicId = styles[0].getId()
00575         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00576         self.failUnless('background-color' in content)
00577         self.failUnless('red' in content)
00578         self.failUnless('blue' in content)
00579 
00580     def testContextDependantInlineCSS(self):
00581         self.tool.clearResources()
00582         self.setRoles(['Manager'])
00583         self.portal.invokeFactory('Folder', 'folder1')
00584         self.portal.invokeFactory('Folder', 'folder2')
00585         self.portal.folder1.invokeFactory('File',
00586                                    id='context.css',
00587                                    format='text/css',
00588                                    content_type='text/css',
00589                                    file='body { background-color : pink }')
00590         self.portal.folder2.invokeFactory('File',
00591                                    id='context.css',
00592                                    format='text/css',
00593                                    content_type='text/css',
00594                                    file='body { background-color : purple }')
00595         self.tool.registerStylesheet('context.css', rendering='inline')
00596         self.setRoles(['Member'])
00597         view = self.portal.restrictedTraverse('@@plone')
00598         viewletmanager = getMultiAdapter((self.portal.folder1, self.portal.folder1.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
00599         viewletmanager.update()
00600         content = viewletmanager.render()
00601         self.failUnless('pink' in content)
00602         self.failIf('purple' in content)
00603         view = self.portal.restrictedTraverse('@@plone')
00604         viewletmanager = getMultiAdapter((self.portal.folder2, self.portal.folder2.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
00605         viewletmanager.update()
00606         content = viewletmanager.render()
00607         self.failUnless('purple' in content)
00608         self.failIf('pink' in content)
00609 
00610 class TestMergingDisabled(RegistryTestCase):
00611 
00612     def afterSetUp(self):
00613         self.tool = getattr(self.portal, CSSTOOLNAME)
00614         self.tool.clearResources()
00615         self.tool.registerStylesheet('testroot.css')
00616         self.tool.registerStylesheet('test_rr_1.css')
00617         self.tool.registerStylesheet('test_rr_2.css', cookable=False)
00618         self.setRoles(['Manager'])
00619         self.portal.invokeFactory('File',
00620                                    id='testroot.css',
00621                                    format='text/css',
00622                                    content_type='text/css',
00623                                    file='body { background-color : green }')
00624         self.setRoles(['Member'])
00625 
00626     def testDefaultStylesheetCookableAttribute(self):
00627         self.failUnless(self.tool.getResources()[self.tool.getResourcePosition('test_rr_1.css')].getCookable())
00628         self.failUnless(self.tool.getResources()[self.tool.getResourcePosition('testroot.css')].getCookable())
00629 
00630     def testStylesheetCookableAttribute(self):
00631         self.failIf(self.tool.getResources()[self.tool.getResourcePosition('test_rr_2.css')].getCookable())
00632 
00633     def testNumberOfResources(self):
00634         self.assertEqual(len(self.tool.getResources()), 3)
00635         self.assertEqual(len(self.tool.cookedresources), 2)
00636         self.assertEqual(len(self.tool.concatenatedresources), 5)
00637         styles = self.tool.getEvaluatedResources(self.portal)
00638         self.assertEqual(len(styles), 2)
00639 
00640     def testCompositionWithLastUncooked(self):
00641         self.tool.moveResourceToBottom('test_rr_2.css')
00642         self.assertEqual(len(self.tool.getResources()), 3)
00643         self.assertEqual(len(self.tool.cookedresources), 2)
00644         self.assertEqual(len(self.tool.concatenatedresources), 5)
00645         styles = self.tool.getEvaluatedResources(self.portal)
00646         self.assertEqual(len(styles), 2)
00647         magicIds = []
00648         for style in styles:
00649             id = style.getId()
00650             if '-cachekey' in id:
00651                 magicIds.append(id)
00652         self.failUnless(magicIds[-1].startswith('test_rr_2'))
00653         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicIds[-2]))
00654         self.failUnless('red' in content)
00655         self.failUnless('green' in content)
00656         self.failIf('blue' in content)
00657         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicIds[-1]))
00658         self.failIf('red' in content)
00659         self.failIf('green' in content)
00660         self.failUnless('blue' in content)
00661         content = str(self.portal.restrictedTraverse('portal_css/test_rr_2.css'))
00662         self.failUnless('blue' in content)
00663 
00664     def testCompositionWithFirstUncooked(self):
00665         self.tool.moveResourceToTop('test_rr_2.css')
00666         self.assertEqual(len(self.tool.getResources()), 3)
00667         self.assertEqual(len(self.tool.cookedresources), 2)
00668         self.assertEqual(len(self.tool.concatenatedresources), 5)
00669         styles = self.tool.getEvaluatedResources(self.portal)
00670         self.assertEqual(len(styles), 2)
00671         magicId = None
00672         for style in styles:
00673             id = style.getId()
00674             if '-cachekey' in id:
00675                 magicId = id
00676         self.failUnless(magicId)
00677         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00678         self.failUnless('red' in content)
00679         self.failUnless('green' in content)
00680         self.failIf('blue' in content)
00681         content = str(self.portal.restrictedTraverse('portal_css/test_rr_2.css'))
00682         self.failUnless('blue' in content)
00683 
00684     def testCompositionWithMiddleUncooked(self):
00685         self.tool.moveResourceToTop('test_rr_2.css')
00686         self.tool.moveResourceDown('test_rr_2.css')
00687         self.assertEqual(len(self.tool.getResources()), 3)
00688         self.assertEqual(len(self.tool.cookedresources), 3)
00689         self.assertEqual(len(self.tool.concatenatedresources), 6)
00690         styles = self.tool.getEvaluatedResources(self.portal)
00691         self.assertEqual(len(styles), 3)
00692         content = str(self.portal.restrictedTraverse('portal_css/test_rr_2.css'))
00693         self.failUnless('blue' in content)
00694         content = str(self.portal.restrictedTraverse('portal_css/test_rr_1.css'))
00695         self.failUnless('red' in content)
00696         content = str(self.portal.restrictedTraverse('portal_css/testroot.css'))
00697         self.failUnless('green' in content)
00698 
00699     def testLargerCompositionWithMiddleUncooked(self):
00700         self.setRoles(['Manager'])
00701         self.portal.invokeFactory('File',
00702                                    id='testpurple.css',
00703                                    format='text/css',
00704                                    content_type='text/css',
00705                                    file='body { background-color : purple }')
00706         self.portal.invokeFactory('File',
00707                                    id='testpink.css',
00708                                    format='text/css',
00709                                    content_type='text/css',
00710                                    file='body { background-color : pink }')
00711         self.setRoles(['Member'])
00712         self.tool.registerStylesheet('testpurple.css')
00713         self.tool.registerStylesheet('testpink.css')
00714         self.tool.moveResourceToTop('test_rr_2.css')
00715         self.tool.moveResourceDown('test_rr_2.css', 2)
00716         #Now have [[green,red],blue,[purple,pink]]
00717         self.assertEqual(len(self.tool.getResources()), 5)
00718         self.assertEqual(len(self.tool.cookedresources), 3)
00719         self.assertEqual(len(self.tool.concatenatedresources), 8)
00720         styles = self.tool.getEvaluatedResources(self.portal)
00721         self.assertEqual(len(styles), 3)
00722         magicIds = []
00723         for style in styles:
00724             id = style.getId()
00725             if '-cachekey' in id:
00726                 magicIds.append(id)
00727         self.assertEqual(len(magicIds), 3)
00728         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicIds[0]))
00729         self.failUnless('red' in content)
00730         self.failUnless('green' in content)
00731         self.failIf('pink' in content)
00732         self.failIf('purple' in content)
00733         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicIds[2]))
00734         self.failUnless('pink' in content)
00735         self.failUnless('purple' in content)
00736         self.failIf('red' in content)
00737         self.failIf('green' in content)
00738         content = str(self.portal.restrictedTraverse('portal_css/test_rr_2.css'))
00739         self.failUnless('blue' in content)
00740 
00741 class TestPublishing(FunctionalRegistryTestCase):
00742 
00743     def afterSetUp(self):
00744         self.tool = getattr(self.portal, CSSTOOLNAME)
00745         self.tool.clearResources()
00746         self.tool.registerStylesheet('plone_styles.css')
00747         self.toolpath = '/' + self.tool.absolute_url(1)
00748         self.portalpath = '/' + getToolByName(self.portal, 'portal_url')(1)
00749         self.setRoles(['Manager'])
00750         self.portal.invokeFactory('Document', 'index_html')
00751         self.setRoles(['Member'])
00752 
00753     def testPublishCSSThroughTool(self):
00754         response = self.publish(self.toolpath + '/plone_styles.css')
00755         self.assertEqual(response.getStatus(), 200)
00756         self.assertEqual(response.getHeader('Content-Type'), 'text/css;charset=utf-8')
00757 
00758     def testPublishNonMagicCSSThroughTool(self):
00759         self.setRoles(['Manager'])
00760         body = """<dtml-var "'joined' + 'string'">"""
00761         self.portal.addDTMLMethod('testmethod', file=body)
00762         self.tool.registerStylesheet('testmethod')
00763         response = self.publish(self.toolpath + '/testmethod')
00764         self.assertEqual(response.getStatus(), 200)
00765         self.assertEqual(response.getHeader('Content-Type'), 'text/css;charset=utf-8')
00766 
00767     def testPublishPageWithInlineCSS(self):
00768         response = self.publish(self.portalpath)
00769         self.assertEqual(response.getStatus(), 200)
00770         self.assertEqual(response.getHeader('Content-Type'),
00771                          'text/html;charset=utf-8')
00772         self.tool.clearResources()
00773         # Test that the main page retains its content-type
00774         self.setRoles(['Manager'])
00775         body = """<dtml-call "REQUEST.RESPONSE.setHeader('Content-Type', 'text/css')">/*and some css comments too*/"""
00776         self.portal.addDTMLMethod('testmethod', file=body)
00777         self.tool.registerStylesheet('testmethod', rendering='inline')
00778         response = self.publish(self.portalpath)
00779         self.assertEqual(response.getHeader('Content-Type'), 'text/html;charset=utf-8')
00780         self.assertEqual(response.getStatus(), 200)
00781 
00782 
00783 class TestFivePublishing(FunctionalRegistryTestCase):
00784     'Publishing with Five'
00785 
00786     def afterSetUp(self):
00787         # Define some resource
00788         from Products.Five.zcml import load_config
00789         import Products.ResourceRegistries.tests
00790         load_config('test.zcml', Products.ResourceRegistries.tests)
00791         self.tool = getattr(self.portal, CSSTOOLNAME)
00792         self.tool.clearResources()
00793         self.tool.registerStylesheet('++resource++test_rr_1.css')
00794         self.toolpath = '/' + self.tool.absolute_url(1)
00795         self.portalpath = '/' + getToolByName(self.portal, 'portal_url')(1)
00796         self.setRoles(['Manager'])
00797         self.portal.invokeFactory('Document', 'index_html')
00798         self.setRoles(['Member'])
00799 
00800     def testPublishFiveResource(self):
00801         response = self.publish(self.toolpath + '/++resource++test_rr_1.css')
00802         self.assertEqual(response.getStatus(), 200)
00803         self.assertEqual(response.getHeader('Content-Type')[:8], 'text/css')
00804         self.assertEqual('body { background-color : red }' in response.getBody(), True)
00805 
00806 
00807 class TestResourcePermissions(FunctionalRegistryTestCase):
00808 
00809     def afterSetUp(self):
00810         self.tool = getattr(self.portal, CSSTOOLNAME)
00811         self.toolpath = '/' + self.tool.absolute_url(1)
00812         self.tool.clearResources()
00813         self.tool.registerStylesheet('testroot.css', cookable=False)
00814         self.tool.registerStylesheet('test_rr_1.css')
00815         self.setRoles(['Manager'])
00816         self.portal.invokeFactory('File',
00817                                    id='testroot.css',
00818                                    format='text/css',
00819                                    content_type='text/css',
00820                                    file='body { background-color : green }')
00821 
00822         stylesheet = getattr(self.portal, 'testroot.css')
00823 
00824         stylesheet.manage_permission('View',['Manager'], acquire=0)
00825         stylesheet.manage_permission('Access contents information',['Manager'], acquire=0)
00826         self.setRoles(['Member'])
00827 
00828 
00829     def testUnauthorizedGetItem(self):
00830         try:
00831             content = str(self.tool['testroot.css'])
00832         except Unauthorized:
00833             return
00834 
00835         self.fail()
00836 
00837     def testUnauthorizedTraversal(self):
00838         try:
00839             content = str(self.portal.restrictedTraverse('portal_css/testroot.css'))
00840         except Unauthorized:
00841             return
00842 
00843         self.fail()
00844 
00845     def testUnauthorizedOnPublish(self):
00846         response = self.publish(self.toolpath + '/testroot.css')
00847         #Will be 302 if CookieCrumbler is enabled
00848         self.failUnless(response.getStatus() in [302, 403, 401])
00849 
00850     def testRemovedFromResources(self):
00851         styles = self.tool.getEvaluatedResources(self.portal)
00852         ids = [item.getId() for item in styles]
00853         self.assertEqual(len(self.tool.concatenatedresources), 4)
00854         self.failIf('testroot.css' in ids)
00855         self.failUnless('test_rr_1.css' in self.tool.concatenatedresources[ids[1]])
00856 
00857     def testRemovedFromMergedResources(self):
00858         self.tool.unregisterResource('testroot.css')
00859         self.tool.registerStylesheet('testroot.css')
00860         styles = self.tool.getEvaluatedResources(self.portal)
00861         magicId = None
00862         for style in styles:
00863             id = style.getId()
00864             if '-cachekey' in id:
00865                 magicId = id
00866         self.failUnless(magicId)
00867         content = str(self.portal.restrictedTraverse('portal_css/%s' % magicId))
00868         self.failIf('green' in content)
00869         self.failUnless('not authorized' in content)
00870         self.failUnless('red' in content)
00871 
00872     def testAuthorizedGetItem(self):
00873         self.setRoles(['Manager'])
00874         try:
00875             content = str(self.tool['testroot.css'])
00876         except Unauthorized:
00877             self.fail()
00878 
00879     def testAuthorizedTraversal(self):
00880         self.setRoles(['Manager'])
00881         try:
00882             content = str(self.portal.restrictedTraverse('portal_css/testroot.css'))
00883         except Unauthorized:
00884             self.fail()
00885 
00886     def testAuthorizedOnPublish(self):
00887         authstr = "%s:%s" % (portal_owner, default_password)
00888         response = self.publish(self.toolpath + '/testroot.css', basic=authstr)
00889         self.failUnlessEqual(response.getStatus(), 200)
00890 
00891 class TestDebugMode(FunctionalRegistryTestCase):
00892 
00893     def afterSetUp(self):
00894         self.tool = getattr(self.portal, CSSTOOLNAME)
00895         self.tool.clearResources()
00896         self.portalpath = '/' + getToolByName(self.portal, 'portal_url')(1)
00897         self.toolpath = '/' + self.tool.absolute_url(1)
00898 
00899     def testDebugModeSplitting(self):
00900         self.tool.registerStylesheet('ham')
00901         self.tool.registerStylesheet('spam')
00902         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 1)
00903         self.tool.setDebugMode(True)
00904         self.tool.cookResources()
00905         self.assertEqual(len(self.tool.getEvaluatedResources(self.folder)), 2)
00906 
00907     def testDebugModeSplitting2(self):
00908         self.tool.registerStylesheet('ham')
00909         # Publish in normal mode
00910         response = self.publish(self.toolpath+'/ham')
00911         now = DateTime()
00912         days = 7
00913         soon = now + days
00914         self.assertEqual(response.getStatus(), 200)
00915         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
00916         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
00917 
00918         # Set debug mode
00919         self.tool.setDebugMode(True)
00920         self.tool.cookResources()
00921         # Publish in debug mode
00922         response = self.publish(self.toolpath+'/ham')
00923         self.failIfEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
00924         self.assertEqual(response.getHeader('Expires'), rfc1123_date(now.timeTime()))
00925         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=0')
00926 
00927 
00928 class TestResourceObjects(RegistryTestCase):
00929 
00930     def afterSetUp(self):
00931         self.tool = getattr(self.portal, CSSTOOLNAME)
00932         self.tool.clearResources()
00933 
00934     def testSetEnabled(self):
00935         self.tool.registerStylesheet('ham')
00936         self.tool.registerStylesheet('spam')
00937         self.tool.registerStylesheet('eggs')
00938         self.assertEqual(self.tool.concatenatedresources[
00939                          self.tool.cookedresources[0].getId()],
00940                          ['ham', 'spam', 'eggs'])
00941         spam = self.tool.getResource('spam')
00942         spam.setEnabled(False)
00943         self.assertEqual(self.tool.concatenatedresources[
00944                          self.tool.cookedresources[0].getId()],
00945                          ['ham', 'spam', 'eggs'])
00946         self.tool.cookResources()
00947         self.assertEqual(self.tool.concatenatedresources[
00948                          self.tool.cookedresources[0].getId()],
00949                          ['ham', 'eggs'])
00950 
00951     def testSetCookable(self):
00952         self.tool.registerStylesheet('ham')
00953         self.tool.registerStylesheet('spam')
00954         self.tool.registerStylesheet('eggs')
00955         self.assertEqual(self.tool.concatenatedresources[
00956                          self.tool.cookedresources[0].getId()],
00957                          ['ham', 'spam', 'eggs'])
00958         spam = self.tool.getResource('spam')
00959         spam.setCookable(False)
00960         self.assertEqual(self.tool.concatenatedresources[
00961                          self.tool.cookedresources[0].getId()],
00962                          ['ham', 'spam', 'eggs'])
00963         self.tool.cookResources()
00964         self.assertEqual(self.tool.concatenatedresources[
00965                          self.tool.cookedresources[0].getId()],
00966                          ['ham'])
00967         self.assertEqual(self.tool.concatenatedresources[
00968                          self.tool.cookedresources[1].getId()],
00969                          ['spam'])
00970         self.assertEqual(self.tool.concatenatedresources[
00971                          self.tool.cookedresources[2].getId()],
00972                          ['eggs'])
00973 
00974 
00975 class TestSkinAwareness(FunctionalRegistryTestCase):
00976 
00977     def afterSetUp(self):
00978         self.tool = getattr(self.portal, CSSTOOLNAME)
00979         self.skinstool = getattr(self.portal, 'portal_skins')
00980         self.tool.clearResources()
00981         self.portalpath = '/' + getToolByName(self.portal, 'portal_url')(1)
00982         self.toolpath = '/' + self.tool.absolute_url(1)
00983         self.setRoles(['Manager'])
00984         self.skinstool.manage_addFolder(id='pink')
00985         self.skinstool.manage_addFolder(id='purple')
00986         self.skinstool.pink.manage_addFile(id='skin.css',
00987                                    content_type='text/css',
00988                                    file='body { background-color : pink }')
00989         self.skinstool.purple.manage_addFile(id='skin.css',
00990                                     content_type='text/css',
00991                                     file='body { background-color : purple }')
00992         self.tool.registerStylesheet('skin.css')
00993         self.skinstool.addSkinSelection('PinkSkin', 'pink,ResourceRegistries')
00994         self.skinstool.addSkinSelection('PurpleSkin', 'purple,ResourceRegistries')
00995         self.setRoles(['Member'])
00996         
00997     def testRenderIncludesSkinInPath(self):
00998         self.portal.changeSkin('PinkSkin', REQUEST=self.portal.REQUEST)
00999         view = self.portal.restrictedTraverse('@@plone')
01000         viewletmanager = getMultiAdapter((self.portal, self.portal.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
01001         viewletmanager.update()
01002         content = viewletmanager.render()
01003         self.failUnless('/PinkSkin/' in content)
01004         self.failIf('/PurpleSkin/' in content)
01005         self.portal.changeSkin('PurpleSkin', REQUEST=self.portal.REQUEST)
01006         view = self.portal.restrictedTraverse('@@plone')
01007         viewletmanager = getMultiAdapter((self.portal, self.portal.REQUEST, view), IContentProvider, name = u'plone.resourceregistries.styles')
01008         viewletmanager.update()
01009         content = viewletmanager.render()
01010         self.failUnless('/PurpleSkin/' in content)
01011         self.failIf('/PinkSkin/' in content)
01012 
01013     def testPublishWithSkin(self):
01014         response = self.publish(self.toolpath + '/PinkSkin/skin.css')
01015         self.assertEqual(response.getStatus(), 200)
01016         self.failUnless('pink' in str(response))
01017         response = self.publish(self.toolpath + '/PurpleSkin/skin.css')
01018         self.assertEqual(response.getStatus(), 200)
01019         self.failUnless('purple' in str(response))
01020 
01021 
01022 class TestCachingHeaders(FunctionalRegistryTestCase):
01023     def afterSetUp(self):
01024         self.tool = getattr(self.portal, CSSTOOLNAME)
01025         self.skins_tool = getToolByName(self.portal, 'portal_skins')
01026         self.tool.clearResources()
01027         self.portalpath = '/' + getToolByName(self.portal, 'portal_url')(1)
01028         self.toolpath = '/' + self.tool.absolute_url(1)
01029 
01030     def testCachingHeadersFromTool(self):
01031         self.tool.registerStylesheet('ham')
01032         # Publish
01033         response = self.publish(self.toolpath+'/ham')
01034         now = DateTime()
01035         days = 7
01036         soon = now + days
01037         self.assertEqual(response.getStatus(), 200)
01038         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01039         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01040 
01041         # Publish again
01042         response = self.publish(self.toolpath+'/ham')
01043         now = DateTime()
01044         days = 7
01045         soon = now + days
01046         self.assertEqual(response.getStatus(), 200)
01047         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01048         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01049 
01050     def testCachingHeadersFromSkin(self):
01051         self.tool.registerStylesheet('ham')
01052         # Publish in normal mode
01053         skinpath = self.skins_tool.getDefaultSkin()
01054         url = '%s/%s/ham' % (self.toolpath, skinpath)
01055         response = self.publish(url)
01056         now = DateTime()
01057         days = 7
01058         soon = now + days
01059         self.assertEqual(response.getStatus(), 200)
01060         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01061         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01062 
01063         # Publish again
01064         response = self.publish(url)
01065         now = DateTime()
01066         days = 7
01067         soon = now + days
01068         self.assertEqual(response.getStatus(), 200)
01069         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01070         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01071 
01072     def testCachingHeadersFromToolWithRAMCache(self):
01073         ram_cache_id = 'RAMCache'
01074         self.tool.ZCacheable_setManagerId(ram_cache_id)
01075         self.tool.ZCacheable_setEnabled(1)
01076         self.tool.registerStylesheet('ham')
01077         # Publish
01078         response = self.publish(self.toolpath+'/ham')
01079         now = DateTime()
01080         days = 7
01081         soon = now + days
01082         self.assertEqual(response.getStatus(), 200)
01083         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01084         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01085 
01086         # Publish again
01087         response = self.publish(self.toolpath+'/ham')
01088         now = DateTime()
01089         days = 7
01090         soon = now + days
01091         self.assertEqual(response.getStatus(), 200)
01092         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01093         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01094 
01095     def testCachingHeadersFromSkinWithRAMCache(self):
01096         ram_cache_id = 'RAMCache'
01097         self.tool.ZCacheable_setManagerId(ram_cache_id)
01098         self.tool.ZCacheable_setEnabled(1)
01099         self.tool.registerStylesheet('ham')
01100         # Publish in normal mode
01101         skinpath = self.skins_tool.getDefaultSkin()
01102         url = '%s/%s/ham' % (self.toolpath, skinpath)
01103         response = self.publish(url)
01104         now = DateTime()
01105         days = 7
01106         soon = now + days
01107         self.assertEqual(response.getStatus(), 200)
01108         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01109         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01110 
01111         # Publish again
01112         response = self.publish(url)
01113         now = DateTime()
01114         days = 7
01115         soon = now + days
01116         self.assertEqual(response.getStatus(), 200)
01117         self.assertEqual(response.getHeader('Expires'), rfc1123_date(soon.timeTime()))
01118         self.assertEqual(response.getHeader('Cache-Control'), 'max-age=%d' % int(days*24*3600))
01119 
01120 
01121 def test_suite():
01122     from unittest import TestSuite, makeSuite
01123     suite = TestSuite()
01124     suite.addTest(makeSuite(TestImplementation))
01125     suite.addTest(makeSuite(TestTool))
01126     suite.addTest(makeSuite(TestSkin))
01127     suite.addTest(makeSuite(testZMIMethods))
01128     suite.addTest(makeSuite(TestStylesheetRegistration))
01129     suite.addTest(makeSuite(TestStylesheetRenaming))
01130     suite.addTest(makeSuite(TestToolSecurity))
01131     suite.addTest(makeSuite(TestToolExpression))
01132     suite.addTest(makeSuite(TestStylesheetCooking))
01133     suite.addTest(makeSuite(TestPublishing))
01134     suite.addTest(makeSuite(TestFivePublishing))
01135     suite.addTest(makeSuite(TestStylesheetMoving))
01136     suite.addTest(makeSuite(TestTraversal))
01137     suite.addTest(makeSuite(TestZODBTraversal))
01138     suite.addTest(makeSuite(TestMergingDisabled))
01139     suite.addTest(makeSuite(TestResourcePermissions))
01140     suite.addTest(makeSuite(TestDebugMode))
01141     suite.addTest(makeSuite(TestResourceObjects))
01142     suite.addTest(makeSuite(TestSkinAwareness))
01143     suite.addTest(makeSuite(TestCachingHeaders))
01144 
01145     return suite