[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/ Tests added for the icons CSS in the absolut skin.

Charlie Clark charlie at begeistert.org
Fri Jun 25 15:01:47 EDT 2010


Log message for revision 113842:
  Tests added for the icons CSS in the absolut skin.

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/icons.py
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/tests/test_icons.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/icons.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/icons.py	2010-06-25 15:28:30 UTC (rev 113841)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/icons.py	2010-06-25 19:01:47 UTC (rev 113842)
@@ -13,10 +13,17 @@
 from Products.CMFCore.Expression import getExprContext
 from Products.CMFCore.utils import getToolByName
 
-from Products.CMFDefault.browser.utils import memoize
+from Products.CMFDefault.browser.utils import memoize, ViewBase
 
-class View(BrowserView):
+class View(ViewBase):
+    """
+    CSS that dynamically checks whether Action Icons are can be used.
+    Type Icons can always be used.
+    """
     
+    default_style = ".%s {/* %s */}"
+    icon_style = ".%s {background: url(%s) no-repeat 0.1em}"
+    
     def __init__(self, context, request):
         super(View, self).__init__(context, request)
         self.show_icons = self._show_icons
@@ -25,8 +32,8 @@
     @memoize
     def _show_icons(self):
         """Are action icons enabled?"""
-        ptool = getUtility(IPropertiesTool)
-        show = ptool.getProperty('enable_actionicons')
+        ptool = self._getTool('portal_properties')
+        show = ptool.getProperty('enable_actionicons', False)
         if show:
             self.icon = ".icon {padding-left: 1.5em;}\n\n"
         else:
@@ -35,33 +42,34 @@
 
     @property
     @memoize
-    def template(self):
+    def style(self):
         """Always return a template so there are no browser errors"""
-        if self.show_icons:    
-            return ".%s {background: url(%s) no-repeat 0.1em}"
+        if self.show_icons:
+            return self.icon_style
         else:
-            return ".%s {/* %s */}"
+            return self.default_style
 
     @memoize
     def actions(self):
         """List all action icons"""
-        atool = getToolByName(self.context, 'portal_actions')
+        atool = self._getTool('portal_actions')
         all_actions = atool.listFilteredActionsFor(self.context)
         icons = []
         for cat in ['user', 'object', 'folder', 'workflow', 'global']:
             cat_actions = all_actions[cat]
             icons.append("/* %s actions */" % cat)
             for a in cat_actions:
-                icons.append(self.template % (a['id'], a['icon']))
+                icons.append(self.style % (a['id'], a['icon']))
         return "\n\n".join(icons)
 
     @memoize
     def types(self):
-        """List all type icons"""
-        ttool = getToolByName(self.context, 'portal_types')
+        """List all type icons
+        Type actions are always visible"""
+        ttool = self._getTool('portal_types')
         types = ttool.listTypeInfo()
         econtext = getExprContext(self.context)
-        icons = [self.template %  (t.id,
+        icons = [self.icon_style %  (t.id,
                                   t.getIconExprObject()(econtext)) \
                 for t in types]
         return "\n\n".join(icons)

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/tests/test_icons.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/tests/test_icons.py	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/tests/test_icons.py	2010-06-25 19:01:47 UTC (rev 113842)
@@ -0,0 +1,191 @@
+"""
+$Id$
+"""
+
+import unittest
+from zope.component.testing import PlacelessSetup
+
+from test_ursa import (
+                    DummyRequest, DummySite, DummyContext,
+                    DummyPropertiesTool, DummyURLTool, DummyActionsTool
+                    )
+
+class AbsolutIconsTests(unittest.TestCase, PlacelessSetup):
+    
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+
+    def tearDown(self):
+        PlacelessSetup.tearDown(self)
+        
+    def _getTargetClass(self):
+        from Products.CMFDefault.browser.skins.icons import View
+        return View
+
+    def _makeOne(self, site=None):
+        if site is None:
+            site = self._makeSite()
+        request = DummyRequest()
+        return self._getTargetClass()(site, request)
+
+    def _makeSite(self, types=None, actions=None):
+        from zope.component import getSiteManager
+        from Products.CMFCore.interfaces import IPropertiesTool
+        site = DummyContext()
+        tool = site.portal_properties = DummyPropertiesTool()
+        sm = getSiteManager()
+        sm.registerUtility(tool, IPropertiesTool)
+        if types is not None:
+            site.portal_types = DummyTypesTool(types)
+            site.portal_url = DummyURLTool(site)
+            site.portal_membership = DummyMembershipTool()
+        if actions is not None:
+            site.portal_actions = DummyActionsTool(actions)
+        site.absolute_url = lambda: 'http://example.com'
+        return site
+
+    def test_show_icons_not_set(self):
+        """Show action icons not set"""
+        view = self._makeOne()
+        self.failIf(view._show_icons)
+        
+    def test_show_icons_enabled(self):
+        """Show actions set to True"""
+        site = self._makeSite()
+        site.portal_properties.enable_actionicons = True
+        view = self._makeOne(site)
+        self.failUnless(view._show_icons)
+
+    def test_show_icons_disabled(self):
+        """Show actions set to False"""
+        site = self._makeSite()
+        site.portal_properties.enable_actionicons = False
+        view = self._makeOne(site)
+        self.failIf(view._show_icons)
+    
+    def test_type_icons_with_action_icons_disabled(self):
+        """Type actions should always be visible"""
+        types = [DummyType("Document"), DummyType("Image")]
+        site = self._makeSite(types=types)
+        view = self._makeOne(site)
+        self.failIf(view.show_icons)
+        
+        css = view.types()
+        self.assertEqual(css,""".Document {background: url(http://example.com/Document.png) no-repeat 0.1em}
+
+.Image {background: url(http://example.com/Image.png) no-repeat 0.1em}""")
+        
+    def test_type_icons_with_action_icons_enabled(self):
+        """Type actions should always be visible"""
+        types = [DummyType("Document"), DummyType("Image")]
+        site = self._makeSite(types=types)
+        site.portal_properties.enable_actionicons = True
+        view = self._makeOne(site)
+        self.failUnless(view.show_icons)
+        
+        css = view.types()
+        self.assertEqual(css,""".Document {background: url(http://example.com/Document.png) no-repeat 0.1em}
+
+.Image {background: url(http://example.com/Image.png) no-repeat 0.1em}""")
+        
+    def test_action_icons_with_action_icons_disabled(self):
+        """Action icons disabled. Image less styles should be returned."""
+        site = self._makeSite(actions=ACTIONS)
+        view = self._makeOne(site)
+        self.failIf(view.show_icons)
+        
+        css = view.actions()
+        self.assertEqual(css, """/* user actions */
+
+.Login {/* Login.png */}
+
+.Logout {/* Logout.png */}
+
+/* object actions */
+
+.Edit {/* Edit.png */}
+
+/* folder actions */
+
+.folderContents {/* folderContents.png */}
+
+/* workflow actions */
+
+.Publish {/* Publish.png */}
+
+/* global actions */
+
+.Undo {/* Undo.png */}""")
+        
+    def test_action_icons_with_action_icons_enabled(self):
+        """Action icons enabled. Styles with images should be returned."""
+        site = self._makeSite(actions=ACTIONS)
+        site.portal_properties.enable_actionicons = True
+        view = self._makeOne(site)
+        self.failUnless(view.show_icons)
+        
+        css = view.actions()
+        self.assertEqual(css, """/* user actions */
+
+.Login {background: url(Login.png) no-repeat 0.1em}
+
+.Logout {background: url(Logout.png) no-repeat 0.1em}
+
+/* object actions */
+
+.Edit {background: url(Edit.png) no-repeat 0.1em}
+
+/* folder actions */
+
+.folderContents {background: url(folderContents.png) no-repeat 0.1em}
+
+/* workflow actions */
+
+.Publish {background: url(Publish.png) no-repeat 0.1em}
+
+/* global actions */
+
+.Undo {background: url(Undo.png) no-repeat 0.1em}""")
+    
+
+class DummyType:
+    
+    def __init__(self, id):
+        from Products.CMFCore.Expression import Expression
+        self.id = id
+        self.icon_expr_object = Expression('string:${portal_url}/%s.png' % id)
+    
+    def getIconExprObject(self):
+        return getattr(self, 'icon_expr_object', None)
+        
+
+class DummyTypesTool:
+    
+    def __init__(self, types=None):
+        if types is None:
+            self.typeInfos = []
+        else:
+            self.typeInfos = types[:]
+            
+    def listTypeInfo(self):
+        return self.typeInfos
+
+
+def DummyAction(name):
+    
+    return {'id':name, 'icon':'%s.png' % name}
+
+
+ACTIONS = {'global': [DummyAction('Undo')],
+           'user': [DummyAction('Login'), DummyAction('Logout')],
+           'object': [DummyAction('Edit')],
+           'folder': [DummyAction('folderContents')],
+           'workflow': [DummyAction('Publish')],
+          }
+
+class DummyMembershipTool:
+    
+    def isAnonymousUser(self):
+        return True
+
+        
\ No newline at end of file


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/skins/tests/test_icons.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list