Skip to content

Commit

Permalink
Merge pull request #215 from iham/master
Browse files Browse the repository at this point in the history
Creating language folder(s) on installation.
  • Loading branch information
iham committed Mar 8, 2016
2 parents 059ebac + d0f2465 commit db01b12
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 24 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ Changelog

Incompatibilities:

- *add item here*
- No more compatible with GenericSetup below 1.8.2.
[iham]

New:

- *add item here*
- Creating language folder(s) on installation.
(fixes https://github.com/plone/plone.app.multilingual/issues/214)
[iham]

Fixes:

Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from setuptools import setup, find_packages
"""Setup plone.app.multilingual."""

import os
from setuptools import setup, find_packages


version = '3.0.16.dev0'
VERSION = '3.0.16.dev0'

setup(
name='plone.app.multilingual',
version=version,
version=VERSION,
description="Multilingual Plone UI package, enables maintenance of "
"translations for both Dexterity types and Archetypes",
long_description="\n\n".join([
Expand All @@ -32,6 +35,7 @@
zip_safe=False,
install_requires=[
'Products.CMFPlone>=5.0b1',
'Products.GenericSetup>=1.8.2',
'archetypes.multilingual',
'plone.app.registry',
'plone.app.z3cform',
Expand Down
3 changes: 2 additions & 1 deletion src/plone/app/multilingual/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
description="Install to enable multilingual content support"
directory="profiles/default"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"/>
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
post_handler=".setuphandlers.init_pam"/>

<genericsetup:registerProfile
name="uninstall"
Expand Down
9 changes: 9 additions & 0 deletions src/plone/app/multilingual/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from plone.api import portal
from Products.CMFPlone.interfaces import INonInstallable
from plone.app.multilingual.browser.setup import SetupMultilingualSite
from zope.interface import implementer
import pkg_resources

Expand All @@ -11,6 +13,7 @@
HAS_PLONE_APP_CONTENTTYPES = True



@implementer(INonInstallable)
class HiddenProfiles(object):

Expand All @@ -24,6 +27,12 @@ def getNonInstallableProfiles(self):
]


def init_pam(tool):
"""After installation run setup to create LRF and LIF."""
setup_tool = SetupMultilingualSite()
setup_tool.setupSite(portal.get())


def step_default_various(context):
if context.readDataFile('plone.app.multilingual_default.txt') is None:
return
Expand Down
54 changes: 54 additions & 0 deletions src/plone/app/multilingual/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,59 @@ def setUpPloneSite(self, portal):
name="plone.app.multilingual:Integration")


class PloneAppMultiLingualPresetLayer(PloneSandboxLayer):
"""Test installation with preset languages."""

defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

def setUpZope(self, app, configurationContext):
# Configure ZCML
xmlconfig.file('testing.zcml', plone.app.multilingual,
context=configurationContext)

xmlconfig.file('overrides.zcml', plone.app.multilingual,
context=configurationContext)

# Enable languageindependent-field on IRelatedItems-behavior
from plone.app.relationfield.behavior import IRelatedItems
alsoProvides(IRelatedItems['relatedItems'], ILanguageIndependentField)

def setUpPloneSite(self, portal):
# Define available languages before installing PAM
# This simulates the behavior of having predefined languages
# in GenericSetup before installing PAM
language_tool = getToolByName(portal, 'portal_languages')
language_tool.addSupportedLanguage('ca')
language_tool.addSupportedLanguage('es')

# Enable request negotiator
language_tool.use_request_negotiation = True

# Activate product
applyProfile(portal, 'plone.app.multilingual:default')

# Empower test user
setRoles(portal, TEST_USER_ID, ['Manager'])

# Enable all errors
error_log = getToolByName(portal, 'error_log')
error_log._ignored_exceptions = ()

# Set default workflow
wftool = getToolByName(portal, 'portal_workflow')
wftool.setDefaultChain('simple_publication_workflow')

# Cleanup p.a.contenttypes stuff
if 'robot-test-folder' in portal.objectIds():
portal.manage_delObjects('robot-test-folder')

PLONE_APP_MULTILINGUAL_PRESET_FIXTURE = PloneAppMultiLingualPresetLayer()

PLONE_APP_MULTILINGUAL_PRESET_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_MULTILINGUAL_PRESET_FIXTURE,),
name="plone.app.multilingual:PresetIntegration")


class MultipleLanguagesLayer(z2.Layer):

defaultBases = (PLONE_APP_MULTILINGUAL_FIXTURE,)
Expand Down Expand Up @@ -203,5 +256,6 @@ def create_translation(self, *args, **kwargs):


PAM_INTEGRATION_TESTING = PLONE_APP_MULTILINGUAL_INTEGRATION_TESTING
PAM_INTEGRATION_PRESET_TESTING = PLONE_APP_MULTILINGUAL_PRESET_INTEGRATION_TESTING
PAM_FUNCTIONAL_TESTING = PLONE_APP_MULTILINGUAL_FUNCTIONAL_TESTING
PAM_ROBOT_TESTING = PLONE_APP_MULTILINGUAL_ROBOT_TESTING
104 changes: 86 additions & 18 deletions src/plone/app/multilingual/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,107 @@
# -*- coding: utf-8 -*-
import unittest2 as unittest
from zope.interface import alsoProvides

from Products.CMFCore.utils import getToolByName

from plone.app.multilingual.browser.setup import SetupMultilingualSite
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
from plone.app.multilingual.browser.vocabularies import\
AllContentLanguageVocabulary
from plone.app.multilingual.testing import PAM_INTEGRATION_TESTING
import unittest2 as unittest
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
from zope.interface import alsoProvides
from plone.app.multilingual.testing import (PAM_INTEGRATION_TESTING,
PAM_INTEGRATION_PRESET_TESTING)


class TestSetupMultilingualSite(unittest.TestCase):
"""Testing multilingual site without predefined languages."""

layer = PAM_INTEGRATION_TESTING

def setUp(self):
"""Setting up the test."""
self.portal = self.layer['portal']
self.request = self.layer['request']
self.language_tool = getToolByName(self.portal, 'portal_languages')
self.languages = self.language_tool.getSupportedLanguages()
alsoProvides(self.layer['request'], IPloneAppMultilingualInstalled)

def test_add_all_supported_languages(self):
"""There was a language which code is 'id' and it broke the root
language folder setup process
def test_single_language(self):
"""Only one language is set."""
self.assertEqual(len(self.languages), 1)

def test_no_languagefolder_created(self):
"""On a single language no folder creation is done."""
portal_objects = self.portal.objectIds()
for lang in self.languages:
self.assertNotIn(lang, portal_objects)

def test_all_supported_languages(self):
"""There was a language which code is 'id'.
This broke the root language folder setup process.
To get rid of that the folder is 'id-id'.
"""
language_tool = getToolByName(self.portal, 'portal_languages')
for lang in AllContentLanguageVocabulary()(self.portal):
language_tool.addSupportedLanguage(lang.value)
all_langs = AllContentLanguageVocabulary()(self.portal)
for lang in all_langs:
self.language_tool.addSupportedLanguage(lang.value)

workflow_tool = getToolByName(self.portal, "portal_workflow")
workflow_tool.setDefaultChain('simple_publication_workflow')

workflowTool = getToolByName(self.portal, "portal_workflow")
workflowTool.setDefaultChain('simple_publication_workflow')
setup_tool = SetupMultilingualSite()
setup_tool.setupSite(self.portal)

setupTool = SetupMultilingualSite()
setupTool.setupSite(self.portal)
portal_objects = self.portal.objectIds()

for lang in AllContentLanguageVocabulary()(self.portal):
if lang.value == 'id':
self.assertIn('id-id', self.portal.objectIds())
for lang in all_langs.by_value.keys():
if lang == 'id':
self.assertIn('id-id', portal_objects)
else:
self.assertIn(lang.value, self.portal.objectIds())
self.assertIn(lang, portal_objects)

def test_type_of_language_folders(self):
"""The created objects have to be 'Language Root Folder'."""
all_langs = AllContentLanguageVocabulary()(self.portal)
for lang in all_langs:
self.language_tool.addSupportedLanguage(lang.value)

workflow_tool = getToolByName(self.portal, "portal_workflow")
workflow_tool.setDefaultChain('simple_publication_workflow')

setup_tool = SetupMultilingualSite()
setup_tool.setupSite(self.portal)

for lang in all_langs.by_value.keys():
if lang == 'id':
self.assertEqual(self.portal.get('id-id').portal_type, 'LRF')
else:
self.assertEqual(self.portal.get(lang).portal_type, 'LRF')


class TestSetupMultilingualPresetSite(unittest.TestCase):
"""Testing multilingual site with predefined languages."""

layer = PAM_INTEGRATION_PRESET_TESTING

def setUp(self):
"""Setting up the test."""
self.portal = self.layer['portal']
self.request = self.layer['request']
self.language_tool = getToolByName(self.portal, 'portal_languages')
self.languages = self.language_tool.getSupportedLanguages()
alsoProvides(self.layer['request'], IPloneAppMultilingualInstalled)

def test_language_folders_created(self):
"""Available languages are: 'en', 'ca', 'es'.
After setup has run there should be
new objects in the portal named after the languages.
"""
portal_objects = self.portal.objectIds()
for lang in self.languages:
self.assertIn(lang, portal_objects)

def test_type_of_language_folders(self):
"""The created objects have to be 'Language Root Folder'."""
for lang in self.languages:
self.assertEqual(self.portal.get(lang).portal_type, 'LRF')

0 comments on commit db01b12

Please sign in to comment.