diff --git a/CHANGES.rst b/CHANGES.rst
index 0ea47fc9..cb9955db 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,7 +6,8 @@ There's a frood who really knows where his towel is.
2.4.2 (unreleased)
^^^^^^^^^^^^^^^^^^
-- Nothing changed yet.
+- Use Plone's registry instead of the ``portal_properties`` tool to store package configuration (closes `#1`_).
+ [hvelarde]
2.4.1 (2015-12-10)
@@ -276,6 +277,7 @@ There's a frood who really knows where his towel is.
* Initial release [cleberjsantos]
+.. _`#1`: https://github.com/collective/sc.social.like/issues/1
.. _`#15`: https://github.com/collective/sc.social.like/pull/15
.. _`#36`: https://github.com/collective/sc.social.like/issues/36
.. _`#38`: https://github.com/collective/sc.social.like/issues/38
diff --git a/sc/social/like/browser/configure.zcml b/sc/social/like/browser/configure.zcml
index 36bc5760..9e5d9d4b 100644
--- a/sc/social/like/browser/configure.zcml
+++ b/sc/social/like/browser/configure.zcml
@@ -61,4 +61,11 @@
permission="zope.Public"
/>
+
+
diff --git a/sc/social/like/browser/helper.py b/sc/social/like/browser/helper.py
index cc3feaf4..c66fb092 100644
--- a/sc/social/like/browser/helper.py
+++ b/sc/social/like/browser/helper.py
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
-
from Acquisition import aq_inner
-from Products.Five import BrowserView
from plone.app.layout.globals.interfaces import IViewView
from plone.memoize.view import memoize
from plone.memoize.view import memoize_contextless
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from Products.Five import BrowserView
+from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import IHelperView
from sc.social.like.plugins import IPlugin
from zope.component import getMultiAdapter
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import implements
@@ -30,8 +31,9 @@ def __init__(self, context, request, *args, **kwargs):
@memoize_contextless
def configs(self):
- adapter = LikeControlPanelAdapter(self.portal)
- return adapter
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(ISocialLikeSettings)
+ return settings
@memoize_contextless
def enabled_portal_types(self):
diff --git a/sc/social/like/config.py b/sc/social/like/config.py
index e22edcf4..2ae7319c 100644
--- a/sc/social/like/config.py
+++ b/sc/social/like/config.py
@@ -5,3 +5,6 @@
__docformat__ = 'plaintext'
PROJECTNAME = 'sc.social.like'
+
+DEFAULT_ENABLED_CONTENT_TYPES = ('Document', 'Event')
+DEFAULT_PLUGINS_ENABLED = ('Facebook', 'Twitter')
diff --git a/sc/social/like/configure.zcml b/sc/social/like/configure.zcml
index c7c8ee1c..9620fc5e 100644
--- a/sc/social/like/configure.zcml
+++ b/sc/social/like/configure.zcml
@@ -7,11 +7,10 @@
-
+
-
diff --git a/sc/social/like/controlpanel.py b/sc/social/like/controlpanel.py
new file mode 100644
index 00000000..92b9ae17
--- /dev/null
+++ b/sc/social/like/controlpanel.py
@@ -0,0 +1,85 @@
+# -*- coding:utf-8 -*-
+from plone.app.registry.browser import controlpanel
+from sc.social.like import LikeMessageFactory as _
+from sc.social.like.config import DEFAULT_ENABLED_CONTENT_TYPES
+from sc.social.like.config import DEFAULT_PLUGINS_ENABLED
+from zope import schema
+from zope.interface import Interface
+from zope.schema.vocabulary import SimpleTerm
+from zope.schema.vocabulary import SimpleVocabulary
+
+
+CONTENT_TYPES = 'plone.app.vocabularies.ReallyUserFriendlyTypes'
+
+styles = SimpleVocabulary([
+ SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
+ SimpleTerm(value=u'vertical', title=_(u'vertical')),
+])
+
+
+class ISocialLikeSettings(Interface):
+
+ """Schema for the control panel form."""
+
+ enabled_portal_types = schema.Tuple(
+ title=_(u'Content types'),
+ description=_(
+ u'help_portal_types',
+ default=u'Please select content types in which the '
+ u'viewlet will be applied.',
+ ),
+ required=True,
+ default=DEFAULT_ENABLED_CONTENT_TYPES,
+ value_type=schema.Choice(vocabulary=CONTENT_TYPES)
+ )
+
+ plugins_enabled = schema.Tuple(
+ title=_(u'Plugins'),
+ description=_(
+ u'help_enabled_plugins',
+ default=u'Please select which plugins will be used',
+ ),
+ required=False,
+ default=DEFAULT_PLUGINS_ENABLED,
+ value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
+ )
+
+ typebutton = schema.Choice(
+ title=_(u'Button style'),
+ description=_(
+ u'help_selected_buttons',
+ default=u'Choose your button style.',
+ ),
+ required=True,
+ default=_(u'horizontal'),
+ vocabulary=styles,
+ )
+
+ do_not_track = schema.Bool(
+ title=_(u'Do not track users'),
+ description=_(
+ u'help_do_not_track',
+ default=u'If enabled, the site will not provide advanced sharing '
+ u'widgets , instead simple links will be used.\n'
+ u'This will limits user experience and features '
+ u'(like the share count) but will enhance users privacy: '
+ u'no 3rd party cookies will be sent to users.'
+ ),
+ default=False,
+ )
+
+
+class SocialLikeSettingsEditForm(controlpanel.RegistryEditForm):
+
+ """Control panel edit form."""
+
+ schema = ISocialLikeSettings
+ label = _(u'Social Like')
+ description = _(u'Settings for the sc.social.like package')
+
+
+class SocialLikeSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
+
+ """Control panel form wrapper."""
+
+ form = SocialLikeSettingsEditForm
diff --git a/sc/social/like/controlpanel/__init__.py b/sc/social/like/controlpanel/__init__.py
deleted file mode 100644
index 40a96afc..00000000
--- a/sc/social/like/controlpanel/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-# -*- coding: utf-8 -*-
diff --git a/sc/social/like/controlpanel/configure.zcml b/sc/social/like/controlpanel/configure.zcml
deleted file mode 100644
index 2630d71f..00000000
--- a/sc/social/like/controlpanel/configure.zcml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
diff --git a/sc/social/like/controlpanel/likes.pt b/sc/social/like/controlpanel/likes.pt
deleted file mode 100644
index 426e7657..00000000
--- a/sc/social/like/controlpanel/likes.pt
+++ /dev/null
@@ -1,171 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
- Info
-
-
-
-
-
-
- Site Setup
-
-
-
- Do something
-
-
-
- Description
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sc/social/like/controlpanel/likes.py b/sc/social/like/controlpanel/likes.py
deleted file mode 100644
index 9581ee0c..00000000
--- a/sc/social/like/controlpanel/likes.py
+++ /dev/null
@@ -1,134 +0,0 @@
-# -*- coding:utf-8 -*-
-
-from Acquisition import aq_inner
-from Products.CMFDefault.formlib.schema import ProxyFieldProperty as PFP
-from Products.CMFDefault.formlib.schema import SchemaAdapterBase
-from Products.CMFPlone.interfaces import IPloneSiteRoot
-from Products.CMFPlone.utils import getToolByName
-from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
-from plone.app.controlpanel.form import ControlPanelForm
-from sc.social.like import LikeMessageFactory as _
-from sc.social.like.plugins import IPlugin
-from zope import schema
-from zope.app.form.browser import itemswidgets
-from zope.component import adapts
-from zope.component import getUtilitiesFor
-from zope.formlib.form import FormFields
-from zope.interface import Interface
-from zope.interface import implements
-from zope.schema.vocabulary import SimpleTerm
-from zope.schema.vocabulary import SimpleVocabulary
-
-CONTENT_TYPES = 'plone.app.vocabularies.ReallyUserFriendlyTypes'
-
-
-class MultiSelectWidget(itemswidgets.MultiSelectWidget):
- """ """
- def __init__(self, field, request):
- """Initialize the widget."""
- super(MultiSelectWidget, self).__init__(field,
- field.value_type.vocabulary,
- request)
-
-
-styles = SimpleVocabulary([
- SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
- SimpleTerm(value=u'vertical', title=_(u'vertical')),
-])
-
-
-class IProvidersSchema(Interface):
- """ General Configurations """
-
- enabled_portal_types = schema.Tuple(
- title=_(u'Content types'),
- description=_(
- u'help_portal_types',
- default=u'Please select content types in which the '
- u'viewlet will be applied.',
- ),
- required=True,
- value_type=schema.Choice(vocabulary=CONTENT_TYPES)
- )
-
- plugins_enabled = schema.Tuple(
- title=_(u'Plugins'),
- description=_(
- u'help_enabled_plugins',
- default=u'Please select which plugins will be used',
- ),
- required=False,
- value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
- )
-
- typebutton = schema.Choice(
- title=_(u'Button style'),
- description=_(
- u'help_selected_buttons',
- default=u'Choose your button style.',
- ),
- required=True,
- default=_(u'horizontal'),
- vocabulary=styles,
- )
-
- do_not_track = schema.Bool(
- title=_(u'Do not track users'),
- description=_(
- u'help_do_not_track',
- default=u'If enabled, the site will not provide advanced sharing '
- u'widgets , instead simple links will be used.\n'
- u'This will limits user experience and features '
- u'(like the share count) but will enhance users privacy: '
- u'no 3rd party cookies will be sent to users.'
- ),
- default=False,
- )
-
-
-class BaseControlPanelAdapter(SchemaAdapterBase):
- """ Base control panel adapter """
-
- def __init__(self, context):
- super(BaseControlPanelAdapter, self).__init__(context)
- portal_properties = getToolByName(context, 'portal_properties')
- self.context = portal_properties.get('sc_social_likes_properties', None)
-
-
-class LikeControlPanelAdapter(BaseControlPanelAdapter):
- """ Like control panel adapter """
- adapts(IPloneSiteRoot)
- implements(IProvidersSchema)
-
- enabled_portal_types = PFP(IProvidersSchema['enabled_portal_types'])
- typebutton = PFP(IProvidersSchema['typebutton'])
- plugins_enabled = PFP(IProvidersSchema['plugins_enabled'])
- do_not_track = PFP(IProvidersSchema['do_not_track'])
-
-
-class ProvidersControlPanel(ControlPanelForm):
- """ """
- template = ViewPageTemplateFile('likes.pt')
- form_fields = FormFields(IProvidersSchema)
-
- form_fields['enabled_portal_types'].custom_widget = MultiSelectWidget
- form_fields['plugins_enabled'].custom_widget = MultiSelectWidget
-
- label = _('Social: Like Actions settings')
- description = _('Configure settings for social like actions.')
- form_name = _('Social: Like Actions')
-
- def plugins_configs(self):
- """ Return Plugins and their configuration pages """
- context = aq_inner(self.context)
- portal_url = getToolByName(context, 'portal_url')()
- registered = dict(getUtilitiesFor(IPlugin))
- plugins = []
- for name in registered:
- plugin = registered[name]
- config_view = plugin.config_view()
- if config_view:
- url = '%s/%s' % (portal_url, config_view)
- plugins.append({'name': name,
- 'url': url})
- return plugins
diff --git a/sc/social/like/interfaces/socialikes.py b/sc/social/like/interfaces.py
similarity index 100%
rename from sc/social/like/interfaces/socialikes.py
rename to sc/social/like/interfaces.py
diff --git a/sc/social/like/interfaces/__init__.py b/sc/social/like/interfaces/__init__.py
deleted file mode 100644
index 02662a9a..00000000
--- a/sc/social/like/interfaces/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# flake8: noqa
-
-from socialikes import IHelperView
-from socialikes import ISocialLikeLayer
-from socialikes import ISocialLikes
diff --git a/sc/social/like/plugins/facebook/browser.py b/sc/social/like/plugins/facebook/browser.py
index 74ebefe1..b8cae2b3 100644
--- a/sc/social/like/plugins/facebook/browser.py
+++ b/sc/social/like/plugins/facebook/browser.py
@@ -1,9 +1,13 @@
# -*- coding:utf-8 -*-
from Acquisition import aq_parent, aq_inner
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.controlpanel import ISocialLikeSettings
+from sc.social.like.plugins.facebook.controlpanel import ISocialLikeFacebookSettings
from sc.social.like.plugins.facebook.utils import facebook_language
from sc.social.like.utils import get_content_image
from sc.social.like.utils import get_language
@@ -16,27 +20,21 @@
class PluginView(BrowserView):
- enabled_portal_types = []
- typebutton = ''
fb_enabled = False
- fbaction = ''
- fbadmins = ''
language = 'en_US'
- fbshow_like = True
- fbshow_share = False
metadata = ViewPageTemplateFile('templates/metadata.pt')
plugin = ViewPageTemplateFile('templates/plugin.pt')
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
+ self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.title = context.title
self.description = context.Description()
- self.request = request
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -44,15 +42,8 @@ def __init__(self, context, request):
self.portal_title = self.portal_state.portal_title()
self.url = context.absolute_url()
self.language = facebook_language(get_language(context), self.language)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
self.image = get_content_image(context, width=1200, height=630)
- if self.sheet:
- self.fbaction = self.sheet.getProperty('fbaction', '')
- self.fbapp_id = self.sheet.getProperty('fbapp_id', '')
- self.fbadmins = self.sheet.getProperty('fbadmins', '')
- self.fbshow_like = 'Like' in self.sheet.getProperty('fbbuttons', [])
- self.fbshow_share = 'Share' in self.sheet.getProperty('fbbuttons', [])
- self.button = self.typebutton
+ self.typebutton # XXX: needed to initialize self.width
def fbjs(self):
js_source = """
@@ -99,7 +90,12 @@ def image_url(self):
@property
def typebutton(self):
- typebutton = self.sheet.getProperty('typebutton', '')
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ typebutton = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ typebutton = ''
+
if typebutton == 'horizontal':
typebutton = 'button_count'
self.width = '90px'
@@ -108,6 +104,46 @@ def typebutton(self):
self.width = '55px'
return typebutton
+ @property
+ def fbaction(self):
+ record = ISocialLikeFacebookSettings.__identifier__ + '.fbaction'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def fbapp_id(self):
+ record = ISocialLikeFacebookSettings.__identifier__ + '.fbapp_id'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def fbadmins(self):
+ record = ISocialLikeFacebookSettings.__identifier__ + '.fbadmins'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def fbshow_like(self):
+ record = ISocialLikeFacebookSettings.__identifier__ + '.fbbuttons'
+ try:
+ return 'Like' in api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return False
+
+ @property
+ def fbshow_share(self):
+ record = ISocialLikeFacebookSettings.__identifier__ + '.fbbuttons'
+ try:
+ return 'Share' in api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return False
+
def _isPortalDefaultView(self):
context = self.context
if ISiteRoot.providedBy(aq_parent(aq_inner(context))):
diff --git a/sc/social/like/plugins/facebook/configure.zcml b/sc/social/like/plugins/facebook/configure.zcml
index 50e3923c..f2dca674 100644
--- a/sc/social/like/plugins/facebook/configure.zcml
+++ b/sc/social/like/plugins/facebook/configure.zcml
@@ -8,16 +8,12 @@
factory="sc.social.like.plugins.facebook.Facebook"
name="Facebook" />
-
-
-
+ name="facebook-config"
+ for="Products.CMFPlone.interfaces.IPloneSiteRoot"
+ class="sc.social.like.plugins.facebook.controlpanel.SocialLikeFacebookSettingsControlPanel"
+ permission="cmf.ManagePortal"
+ />
-
-
-
+ name="twitter-config"
+ for="Products.CMFPlone.interfaces.IPloneSiteRoot"
+ class="sc.social.like.plugins.twitter.controlpanel.SocialLikeTwitterSettingsControlPanel"
+ permission="cmf.ManagePortal"
+ />
+
+
+
+
+
diff --git a/sc/social/like/profiles/uninstall/registry.xml b/sc/social/like/profiles/uninstall/registry.xml
new file mode 100644
index 00000000..cfbba2d2
--- /dev/null
+++ b/sc/social/like/profiles/uninstall/registry.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/sc/social/like/tests/functional.txt b/sc/social/like/tests/functional.txt
deleted file mode 100644
index 9b87f00d..00000000
--- a/sc/social/like/tests/functional.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-Functional test:
-
- >>> app = layer['app']
- >>> portal = layer['portal']
- >>> request = layer['request']
-
- >>> from plone.testing.z2 import Browser
- >>> browser = Browser(app)
- >>> portalURL = portal.absolute_url()
-
- >>> from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD
- >>> browser.open(portalURL + '/login_form')
- >>> browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
- >>> browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
- >>> browser.getControl(name='submit').click()
-
- >>> 'You are now logged in' in browser.contents
- True
-
- >>> browser.open(portalURL + '/@@likes-providers')
- >>> 'Configure settings for social like actions' in browser.contents
- True
-
diff --git a/sc/social/like/tests/test_controlpanel.py b/sc/social/like/tests/test_controlpanel.py
index 05fc7132..a681e029 100644
--- a/sc/social/like/tests/test_controlpanel.py
+++ b/sc/social/like/tests/test_controlpanel.py
@@ -1,83 +1,99 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.app.testing import logout
+from plone.registry.interfaces import IRegistry
from sc.social.like.config import PROJECTNAME
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
-from sc.social.like.controlpanel.likes import ProvidersControlPanel
+from sc.social.like.controlpanel import ISocialLikeSettings
+from sc.social.like.interfaces import ISocialLikeLayer
from sc.social.like.testing import INTEGRATION_TESTING
-from zope.component import getMultiAdapter
+from zope.component import getUtility
+from zope.interface import alsoProvides
import unittest
-class ControlPanelTest(unittest.TestCase):
+class ControlPanelTestCase(unittest.TestCase):
layer = INTEGRATION_TESTING
def setUp(self):
self.portal = self.layer['portal']
+ self.request = self.layer['request']
+ alsoProvides(self.request, ISocialLikeLayer)
self.controlpanel = self.portal['portal_controlpanel']
- self.adapter = LikeControlPanelAdapter(self.portal)
- self.sheet = self.portal.portal_properties.sc_social_likes_properties
- def test_controlpanel_view(self):
- view = getMultiAdapter(
- (self.portal, self.portal.REQUEST), name='likes-providers')
+ def test_controlpanel_has_view(self):
+ view = api.content.get_view(u'sociallike-settings', self.portal, self.request)
view = view.__of__(self.portal)
self.assertTrue(view())
- self.assertTrue(isinstance(view, ProvidersControlPanel))
- def test_controlpanel_plugins_configs(self):
- view = getMultiAdapter(
- (self.portal, self.portal.REQUEST), name='likes-providers')
- configs = view.plugins_configs()
- self.assertEqual(len(configs), 2)
-
- def test_controlpanel_view_protected(self):
- # control panel view can not be accessed by anonymous users
+ def test_controlpanel_view_is_protected(self):
from AccessControl import Unauthorized
logout()
with self.assertRaises(Unauthorized):
- self.portal.restrictedTraverse('@@likes-providers')
+ self.portal.restrictedTraverse('@@sociallike-settings')
- def test_configlet_installed(self):
- actions = [a.getAction(self)['id']
- for a in self.controlpanel.listActions()]
+ def test_controlpanel_installed(self):
+ actions = [
+ a.getAction(self)['id'] for a in self.controlpanel.listActions()]
self.assertIn('sociallikes', actions)
- def test_configlet_removed_on_uninstall(self):
+ def test_controlpanel_removed_on_uninstall(self):
qi = self.portal['portal_quickinstaller']
with api.env.adopt_roles(['Manager']):
qi.uninstallProducts(products=[PROJECTNAME])
- actions = [a.getAction(self)['id']
- for a in self.controlpanel.listActions()]
+ actions = [
+ a.getAction(self)['id'] for a in self.controlpanel.listActions()]
self.assertNotIn('sociallikes', actions)
- def test_enabled_portal_types(self):
- adapter = self.adapter
- adapter.enabled_portal_types = ()
- self.assertEqual(len(adapter.enabled_portal_types), 0)
- adapter.enabled_portal_types = ('Document', 'Event')
+ # def test_controlpanel_plugins_configs(self):
+ # view = getMultiAdapter(
+ # (self.portal, self.portal.REQUEST), name='likes-providers')
+ # configs = view.plugins_configs()
+ # self.assertEqual(len(configs), 2)
+
+
+class RegistryTestCase(unittest.TestCase):
+
+ layer = INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
- self.assertEqual(len(adapter.enabled_portal_types), 2)
+ def test_enabled_portal_types_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'enabled_portal_types'))
self.assertEqual(
- adapter.enabled_portal_types, self.sheet.enabled_portal_types)
+ self.settings.enabled_portal_types, ('Document', 'Event'))
- def test_plugins_enabled(self):
- adapter = self.adapter
- adapter.plugins_enabled = ()
- self.assertEqual(len(adapter.plugins_enabled), 0)
- adapter.plugins_enabled = ('Facebook', 'Twitter')
+ def test_plugins_enabled_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'plugins_enabled'))
+ self.assertEqual(
+ self.settings.plugins_enabled, ('Facebook', 'Twitter'))
+
+ def test_typebutton_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'typebutton'))
+ self.assertEqual(self.settings.typebutton, 'horizontal')
- self.assertEqual(len(adapter.plugins_enabled), 2)
- self.assertEqual(adapter.plugins_enabled, self.sheet.plugins_enabled)
+ def test_do_not_track_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'do_not_track'))
+ self.assertFalse(self.settings.do_not_track)
+
+ def test_records_removed_on_uninstall(self):
+ qi = self.portal['portal_quickinstaller']
+
+ with api.env.adopt_roles(['Manager']):
+ qi.uninstallProducts(products=[PROJECTNAME])
- def test_typebutton(self):
- adapter = self.adapter
- adapter.typebutton = 'horizontal'
- self.assertEqual(adapter.typebutton, self.sheet.typebutton)
+ records = [
+ ISocialLikeSettings.__identifier__ + '.enabled_portal_types',
+ ISocialLikeSettings.__identifier__ + '.plugins_enabled',
+ ISocialLikeSettings.__identifier__ + '.typebutton',
+ ISocialLikeSettings.__identifier__ + '.do_not_track',
+ ]
- adapter.typebutton = 'vertical'
- self.assertEqual(adapter.typebutton, self.sheet.typebutton)
+ for r in records:
+ self.assertNotIn(r, self.registry)
diff --git a/sc/social/like/tests/test_doctest.py b/sc/social/like/tests/test_doctest.py
deleted file mode 100644
index a1418445..00000000
--- a/sc/social/like/tests/test_doctest.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import unittest
-import doctest
-
-from plone.testing import layered
-
-from sc.social.like.testing import FUNCTIONAL_TESTING
-
-optionflags = doctest.REPORT_ONLY_FIRST_FAILURE
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTests([
- layered(doctest.DocFileSuite('functional.txt',
- optionflags=optionflags),
- layer=FUNCTIONAL_TESTING),
- doctest.DocTestSuite(module='sc.social.like'),
- ])
- return suite
diff --git a/sc/social/like/tests/test_plugin_facebook.py b/sc/social/like/tests/test_plugin_facebook.py
index 09d0d213..d6cd01a4 100644
--- a/sc/social/like/tests/test_plugin_facebook.py
+++ b/sc/social/like/tests/test_plugin_facebook.py
@@ -1,19 +1,23 @@
# -*- coding: utf-8 -*-
+from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
-from sc.social.like.interfaces import ISocialLikeLayer
+from plone.registry.interfaces import IRegistry
from sc.social.like import utils
+from sc.social.like.controlpanel import ISocialLikeSettings
+from sc.social.like.interfaces import ISocialLikeLayer
from sc.social.like.plugins.facebook import browser
-from sc.social.like.plugins.facebook import controlpanel
+from sc.social.like.plugins.facebook.controlpanel import ISocialLikeFacebookSettings
from sc.social.like.plugins.facebook.utils import facebook_language
from sc.social.like.plugins.facebook.utils import fix_iso
from sc.social.like.plugins.interfaces import IPlugin
-from sc.social.like.testing import load_image
from sc.social.like.testing import INTEGRATION_TESTING
+from sc.social.like.testing import load_image
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import alsoProvides
+
import unittest
name = 'Facebook'
@@ -59,9 +63,14 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
- self.adapter = LikeControlPanelAdapter(self.portal)
+ self.request = self.layer['request']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
+
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
+ self.plugin_settings = self.registry.forInterface(ISocialLikeFacebookSettings)
+
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
self.plugin = self.plugins[name]
@@ -83,11 +92,9 @@ def setup_content(self, portal):
self.image_bmp.setImage(load_image(640, 480, format='BMP'))
def test_config_view(self):
- plugin = self.plugin
- portal = self.portal
- config_view = plugin.config_view()
- view = portal.restrictedTraverse(config_view)
- self.assertTrue(isinstance(view, controlpanel.ProviderControlPanel))
+ view = api.content.get_view('facebook-config', self.portal, self.request)
+ view = view.__of__(self.portal)
+ self.assertTrue(view())
def test_plugin_view(self):
plugin = self.plugin
@@ -99,8 +106,8 @@ def test_plugin_view(self):
def test_plugin_view_html_likeonly(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.fbbuttons = ('Like',)
+ self.plugin_settings.fbbuttons = ('Like',)
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.plugin()
@@ -110,8 +117,8 @@ def test_plugin_view_html_likeonly(self):
def test_plugin_view_html_shareonly(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.fbbuttons = ('Share',)
+ self.plugin_settings.fbbuttons = ('Share',)
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.plugin()
@@ -121,8 +128,8 @@ def test_plugin_view_html_shareonly(self):
def test_plugin_view_html_both(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.fbbuttons = ('Like', 'Share')
+ self.plugin_settings.fbbuttons = ('Like', 'Share')
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.plugin()
@@ -133,14 +140,14 @@ def test_plugin_view_html_both(self):
def test_privacy_plugin_view_html(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.do_not_track = True
+ self.settings.do_not_track = True
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.link()
# Check that an appid is required
self.assertEqual('', html.strip())
- properties.fbapp_id = '12345'
+ self.plugin_settings.fbapp_id = u'12345'
view = portal.restrictedTraverse(plugin_view)
html = view.link()
self.assertIn('Share on Facebook', html)
@@ -304,13 +311,11 @@ def test_plugin_view_typebutton(self):
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
- self.assertEqual(view.button, 'button_count')
self.assertEqual(view.typebutton, 'button_count')
self.assertEqual(view.width, '90px')
# Change to vertical
- adapter = self.adapter
- adapter.typebutton = 'vertical'
+ self.settings.typebutton = 'vertical'
view = portal.restrictedTraverse(plugin_view)
self.assertEqual(view.typebutton, 'box_count')
self.assertEqual(view.width, '55px')
diff --git a/sc/social/like/tests/test_plugin_gplus.py b/sc/social/like/tests/test_plugin_gplus.py
index 06ff1894..df7c6311 100644
--- a/sc/social/like/tests/test_plugin_gplus.py
+++ b/sc/social/like/tests/test_plugin_gplus.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeLayer
from sc.social.like.plugins.gplus import browser
from sc.social.like.plugins.interfaces import IPlugin
from sc.social.like.testing import INTEGRATION_TESTING
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import alsoProvides
import unittest
@@ -54,9 +56,12 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
- self.adapter = LikeControlPanelAdapter(self.portal)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
+
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
+
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
self.plugin = self.plugins[name]
@@ -83,8 +88,8 @@ def test_plugin_view_html(self):
def test_privacy_plugin_view_html(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.do_not_track = True
+ self.settings.do_not_track = True
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.link()
@@ -107,7 +112,6 @@ def test_plugin_view_typebutton(self):
self.assertEqual(view.typebutton, 'medium')
# Change to vertical
- adapter = self.adapter
- adapter.typebutton = 'vertical'
+ self.settings.typebutton = 'vertical'
view = portal.restrictedTraverse(plugin_view)
self.assertEqual(view.typebutton, 'tall')
diff --git a/sc/social/like/tests/test_plugin_linkedin.py b/sc/social/like/tests/test_plugin_linkedin.py
index 4cf0b176..649115d4 100644
--- a/sc/social/like/tests/test_plugin_linkedin.py
+++ b/sc/social/like/tests/test_plugin_linkedin.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeLayer
-from sc.social.like.plugins.linkedin import browser
from sc.social.like.plugins.interfaces import IPlugin
+from sc.social.like.plugins.linkedin import browser
from sc.social.like.testing import INTEGRATION_TESTING
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import alsoProvides
import unittest
@@ -54,9 +56,12 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
- self.adapter = LikeControlPanelAdapter(self.portal)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
+
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
+
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
self.plugin = self.plugins[name]
@@ -83,8 +88,8 @@ def test_plugin_view_html(self):
def test_privacy_plugin_view_html(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.do_not_track = True
+ self.settings.do_not_track = True
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.link()
@@ -107,7 +112,6 @@ def test_plugin_view_typebutton(self):
self.assertEqual(view.typebutton, 'right')
# Change to vertical
- adapter = self.adapter
- adapter.typebutton = 'vertical'
+ self.settings.typebutton = 'vertical'
view = portal.restrictedTraverse(plugin_view)
self.assertEqual(view.typebutton, 'top')
diff --git a/sc/social/like/tests/test_plugin_pinterest.py b/sc/social/like/tests/test_plugin_pinterest.py
index 9b53ed88..d317fd76 100644
--- a/sc/social/like/tests/test_plugin_pinterest.py
+++ b/sc/social/like/tests/test_plugin_pinterest.py
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeLayer
-from sc.social.like.plugins.pinterest import browser
from sc.social.like.plugins.interfaces import IPlugin
+from sc.social.like.plugins.pinterest import browser
from sc.social.like.testing import INTEGRATION_TESTING
from sc.social.like.testing import load_image
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import alsoProvides
import unittest
@@ -55,9 +57,12 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
- self.adapter = LikeControlPanelAdapter(self.portal)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
+
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
+
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
self.plugin = self.plugins[name]
@@ -95,8 +100,8 @@ def test_plugin_view_html(self):
def test_privacy_plugin_view_html(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.do_not_track = True
+ self.settings.do_not_track = True
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.link()
@@ -148,7 +153,6 @@ def test_plugin_view_typebutton(self):
self.assertEqual(view.typebutton, 'beside')
# Change to vertical
- adapter = self.adapter
- adapter.typebutton = 'vertical'
+ self.settings.typebutton = 'vertical'
view = portal.restrictedTraverse(plugin_view)
self.assertEqual(view.typebutton, 'above')
diff --git a/sc/social/like/tests/test_plugin_twitter.py b/sc/social/like/tests/test_plugin_twitter.py
index fb72fcbc..49ce3d22 100644
--- a/sc/social/like/tests/test_plugin_twitter.py
+++ b/sc/social/like/tests/test_plugin_twitter.py
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
+from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeLayer
-from sc.social.like.plugins.twitter import browser
-from sc.social.like.plugins.twitter import controlpanel
from sc.social.like.plugins.interfaces import IPlugin
+from sc.social.like.plugins.twitter.controlpanel import ISocialLikeTwitterSettings
from sc.social.like.testing import INTEGRATION_TESTING
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import alsoProvides
import unittest
@@ -21,6 +23,7 @@ class PluginTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
+ self.request = self.layer['request']
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
@@ -33,8 +36,9 @@ def test_plugin_config(self):
self.assertEqual(plugin.id, 'twitter')
def test_plugin_config_view(self):
- plugin = self.plugins[name]
- self.assertEqual(plugin.config_view(), '@@twitter-config')
+ view = api.content.get_view('twitter-config', self.portal, self.request)
+ view = view.__of__(self.portal)
+ self.assertTrue(view())
def test_plugin_view(self):
plugin = self.plugins[name]
@@ -55,9 +59,13 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
- self.adapter = LikeControlPanelAdapter(self.portal)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
+
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(ISocialLikeSettings)
+ self.plugin_settings = self.registry.forInterface(ISocialLikeTwitterSettings)
+
alsoProvides(self.portal.REQUEST, ISocialLikeLayer)
self.plugins = dict(getUtilitiesFor(IPlugin))
self.plugin = self.plugins[name]
@@ -66,20 +74,6 @@ def setup_content(self, portal):
portal.invokeFactory('Document', 'my-document')
self.document = portal['my-document']
- def test_config_view(self):
- plugin = self.plugin
- portal = self.portal
- config_view = plugin.config_view()
- view = portal.restrictedTraverse(config_view)
- self.assertTrue(isinstance(view, controlpanel.ProviderControlPanel))
-
- def test_plugin_view(self):
- plugin = self.plugin
- portal = self.portal
- plugin_view = plugin.view()
- view = portal.restrictedTraverse(plugin_view)
- self.assertTrue(isinstance(view, browser.PluginView))
-
def test_plugin_view_html(self):
plugin = self.plugin
document = self.document
@@ -91,8 +85,8 @@ def test_plugin_view_html(self):
def test_privacy_plugin_view_html(self):
plugin = self.plugin
portal = self.portal
- properties = portal.portal_properties.sc_social_likes_properties
- properties.do_not_track = True
+ self.settings.do_not_track = True
+
plugin_view = plugin.view()
view = portal.restrictedTraverse(plugin_view)
html = view.link()
@@ -101,8 +95,7 @@ def test_privacy_plugin_view_html(self):
def test_plugin_twittvia(self):
plugin = self.plugin
document = self.document
- adapter = controlpanel.ControlPanelAdapter(self.portal)
- adapter.twittvia = u'@simplesconsult'
+ self.plugin_settings.twittvia = u'@simplesconsult'
plugin_view = plugin.view()
view = document.restrictedTraverse(plugin_view)
@@ -113,8 +106,7 @@ def test_plugin_urlnoscript_encoding(self):
plugin = self.plugin
document = self.document
document.setTitle(u'NotÃcia')
- adapter = controlpanel.ControlPanelAdapter(self.portal)
- adapter.twittvia = u'@simplesconsult'
+ self.plugin_settings.twittvia = u'@simplesconsult'
plugin_view = plugin.view()
view = document.restrictedTraverse(plugin_view)
diff --git a/sc/social/like/tests/test_plugin_whatsapp.py b/sc/social/like/tests/test_plugin_whatsapp.py
index 70702fea..ee017356 100644
--- a/sc/social/like/tests/test_plugin_whatsapp.py
+++ b/sc/social/like/tests/test_plugin_whatsapp.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
from sc.social.like.interfaces import ISocialLikeLayer
from sc.social.like.plugins.interfaces import IPlugin
from sc.social.like.plugins.whatsapp import browser
@@ -55,7 +54,6 @@ class PluginViewsTest(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']
- self.adapter = LikeControlPanelAdapter(self.portal)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.setup_content(self.portal)
alsoProvides(self.request, ISocialLikeLayer)