Skip to content

Commit

Permalink
Merge pull request #83 from plone/thet-sitelogo-subsite
Browse files Browse the repository at this point in the history
Allow subsites have a different logo
  • Loading branch information
jensens committed Mar 7, 2016
2 parents 205b7d5 + 243f304 commit b760498
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 27 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Changelog

New:

- *add item here*
- Construct the site logo URL to be rooted at ISite instances returned by ``zope.component.hooks.getSite`` and not only rootet at portal root.
This makes it possible to have sub sites with local registries which return a different logo.
[thet]

Fixes:

Expand Down
2 changes: 1 addition & 1 deletion plone/app/layout/viewlets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def update(self):
prefix="plone",
check=False)
self.logo_title = settings.site_title
self.img_src = getSiteLogo(self.portal_state.portal())
self.img_src = getSiteLogo()


class GlobalSectionsViewlet(ViewletBase):
Expand Down
109 changes: 84 additions & 25 deletions plone/app/layout/viewlets/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.interfaces import INonStructuralFolder
from Products.CMFPlone.interfaces import ISiteSchema
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.viewlets.common import ContentViewsViewlet
from plone.app.layout.viewlets.common import GlobalSectionsViewlet
Expand All @@ -10,7 +8,10 @@
from plone.app.layout.viewlets.tests.base import ViewletsTestCase
from plone.protect import authenticator as auth
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import INonStructuralFolder
from Products.CMFPlone.interfaces import ISiteSchema
from zope.component import getUtility
from zope.component.hooks import setSite
from zope.interface import alsoProvides
from zope.interface import directlyProvides
from zope.interface import noLongerProvides
Expand Down Expand Up @@ -54,15 +55,15 @@ def _invalidateRequestMemoizations(self):
except AttributeError:
pass

def testSet1OnPortalRoot(self):
def test_set1_on_portal_root(self):
self._invalidateRequestMemoizations()
self.loginAsPortalOwner()
self.app.REQUEST['ACTUAL_URL'] = self.portal.absolute_url()
view = ContentViewsViewlet(self.portal, self.app.REQUEST, None)
view.update()
self.assertEqual(view.tabSet1[0]['id'], 'folderContents')

def testSet1NonStructuralFolder(self):
def test_set1_NonStructuralFolder(self):
self._invalidateRequestMemoizations()
self.loginAsPortalOwner()
self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url()
Expand All @@ -73,7 +74,7 @@ def testSet1NonStructuralFolder(self):
self.assertEqual(1, len([t for t in view.tabSet1 if t[
'id'] == 'folderContents']))

def testSet1(self):
def test_set1(self):
self._invalidateRequestMemoizations()
self.loginAsPortalOwner()
self.app.REQUEST['ACTUAL_URL'] = '%s/edit?_authenticator=%s' % (
Expand All @@ -82,11 +83,29 @@ def testSet1(self):
)
view = ContentViewsViewlet(self.folder.test, self.app.REQUEST, None)
view.update()
self.assertEqual(1, len([t for t in view.tabSet1 if t[
'id'] == 'folderContents']))
self.assertEqual(['edit'], [t['id'] for t in view.tabSet1 if t['selected']])
self.assertEqual(
1, len([t for t in view.tabSet1 if t['id'] == 'folderContents']))
self.assertEqual(
['edit'], [t['id'] for t in view.tabSet1 if t['selected']])


class TestTitleViewsViewlet(ViewletsTestCase):
"""Test the title viewlet.
"""

def afterSetUp(self):
self.folder.invokeFactory('Document', 'test',
title='Test default page')
self.folder.test.unmarkCreationFlag()
self.folder.setTitle(u"Folder")

def _invalidateRequestMemoizations(self):
try:
del self.app.REQUEST.__annotations__
except AttributeError:
pass

def testTitleViewlet(self):
def test_title_viewlet(self):
"""Title viewlet renders navigation root title
"""
self._invalidateRequestMemoizations()
Expand All @@ -98,7 +117,7 @@ def testTitleViewlet(self):
self.assertEqual(viewlet.site_title,
"Test default page — Folder")

def testTitleViewletInPortalfactory(self):
def test_title_viewlet_in_portal_factory(self):
"""Title viewlet renders navigation root title in portal factory
"""
self._invalidateRequestMemoizations()
Expand All @@ -115,31 +134,71 @@ def testTitleViewletInPortalfactory(self):
self.assertEqual(viewlet.site_title,
u'Add Page — Folder')

def testLogoViewletDefault(self):
"""Logo links towards navigation root

class TestLogoViewlet(ViewletsTestCase):
"""Test the site logo viewlet.
"""

def _set_site(self, context):
"""Set context as a site.
"""
self._invalidateRequestMemoizations()
self.loginAsPortalOwner()
self.app.REQUEST['ACTUAL_URL'] = self.folder.test.absolute_url()
directlyProvides(self.folder, INavigationRoot)
viewlet = LogoViewlet(self.folder.test, self.app.REQUEST, None)
# Set the portal's getSiteManager method on context.
# This is a hackish way to make setSite work without creating a site
# with five.localsitemanager.
# ATTENTION: this works only for the purpose of this test.
context.getSiteManager = self.portal.getSiteManager
setSite(context)

def test_logo_viewlet_portal_root_default(self):
"""When no logo is set, and viewlet is opened on a non-navigation root,
obtain the default one from the portal.
"""
viewlet = LogoViewlet(self.folder, self.app.REQUEST, None)
viewlet.update()
self.assertEqual(viewlet.navigation_root_title, "Folder")
# there is no theme yet in Plone 5, so we see the old png logo
self.assertTrue("logo.png" in viewlet.img_src)
self.assertEqual(
viewlet.img_src, '{0}/logo.png'.format(self.portal.absolute_url()))

def testLogoViewletRegistry(self):
"""If logo is defined in plone.app.registry, use that one.
def test_logo_viewlet_portal_root_registry(self):
"""When a logo is set, and viewlet is opened on a non-navigation root,
obtain the registry logo from the portal.
"""
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone')
settings.site_logo = SITE_LOGO_BASE64

viewlet = LogoViewlet(self.folder.test, self.app.REQUEST, None)
viewlet = LogoViewlet(self.folder, self.app.REQUEST, None)
viewlet.update()
self.assertTrue(
'http://nohost/plone/@@site-logo/pixel.png'
in viewlet.img_src)
viewlet.img_src,
'{0}/@@site-logo/pixel.png'.format(self.portal.absolute_url())
)

def test_logo_viewlet_navigation_root_default(self):
"""When no logo is set, and viewlet is opened on a navigation root,
obtain the default one from the navigation root.
"""
self._set_site(self.folder)
viewlet = LogoViewlet(self.folder, self.app.REQUEST, None)
viewlet.update()
self.assertEqual(
viewlet.img_src, '{0}/logo.png'.format(self.folder.absolute_url()))

def test_viewlet_navigation_root_registry(self):
"""When a logo is set, and viewlet is opened on a navigation root,
obtain the registry logo from the navigation root.
"""
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone')
settings.site_logo = SITE_LOGO_BASE64

# Set fake site after registry setup...
self._set_site(self.folder)
viewlet = LogoViewlet(self.folder, self.app.REQUEST, None)
viewlet.update()
self.assertTrue(
viewlet.img_src,
'{0}/@@site-logo/pixel.png'.format(self.folder.absolute_url())
)


class TestGlobalSectionsViewlet(ViewletsTestCase):
Expand Down

0 comments on commit b760498

Please sign in to comment.