Commit 3e1a5415 authored by Georgios Dagkakis's avatar Georgios Dagkakis

add new test class TestTalesPrefix. Two tests, for no_translate and structure prefix

parent fd0cae1f
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Georgios Dagkakis <georgios.dagkakis@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.Form import ERP5Form
from Products.Formulator.TALESField import TALESMethod
class TestTalesPrefix(ERP5TypeTestCase):
def getBusinessTemplateList(self):
return ('erp5_full_text_mroonga_catalog',
'erp5_core_proxy_field_legacy',
'erp5_base',
'erp5_jquery',
'erp5_jquery_ui',
'erp5_knowledge_pad',
'erp5_web',
)
def beforeTearDown(self):
if hasattr(self.portal.portal_skins.custom, 'test_form_id'):
self.portal.portal_skins.custom.manage_delObjects('test_form_id')
self.tic()
def test_tales_no_translate_prefix(self):
'''
create a Web Section that renders a form with two StringFields
and publish the path.
Check that expected messages are added in message catalog and
ones with no_translate prefix in tales are not
'''
message_catalog = self.portal.Localizer.erp5_ui
message_catalog._messages.clear()
if 'fr' not in message_catalog.get_available_languages():
message_catalog.add_language('fr')
web_site = self.portal.web_site_module.newContent(portal_type='Web Site')
web_section = web_site.newContent(portal_type='Web Section')
portal_skins = self.getSkinsTool()
skin_folder = portal_skins._getOb('custom')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'test_form_id',
'Test Form Title'
)
form = skin_folder._getOb('test_form_id')
form.manage_addField('string_field_translate',
'Test String Field Translate', 'StringField')
string_field_translate = getattr(form, 'string_field_translate')
string_field_translate.tales['title'] = TALESMethod(
"python: 'Title I expect to get translated'"
)
string_field_translate.tales['description'] = TALESMethod(
"python: 'Description I expect to get translated'"
)
form.manage_addField('string_field_no_translate',
'Test String Field No Translate', 'StringField')
string_field_no_translate = getattr(form, 'string_field_no_translate')
string_field_no_translate.tales['title'] = TALESMethod(
"no_translate; python: 'Title I DO NOT expect to get translated'"
)
string_field_no_translate.tales['description'] = TALESMethod(
"no_translate; python: 'Description I DO NOT expect to get translated'"
)
web_section.setCustomRenderMethodId(form.getId())
web_section.publish()
self.tic()
publish_path = '%s/%s' % (self.portal.getUrl(), web_section.getRelativeUrl())
response = self.publish(publish_path)
self.assertEquals(response.getStatus(), 200)
self.assertIn('Title I expect to get translated', message_catalog._messages)
self.assertIn('Title I expect to get translated', message_catalog._messages)
self.assertNotIn('Title I DO NOT expect to get translated', message_catalog._messages)
self.assertNotIn('Description I DO NOT expect to get translated', message_catalog._messages)
def test_tales_structure_prefix(self):
'''
create a for and two list fields and check that label is escaped
or not according to the existence of 'struct' prefix in tales
'''
form = ERP5Form('test_form_id', 'Test Form Title')
form.manage_addField('list_field_escape',
'Test List Field Escape', 'ListField')
list_field_escape = getattr(form, 'list_field_escape')
list_field_escape.tales['items'] = TALESMethod("python:['<i>label</i>', 'value']")
form.manage_addField('list_field_no_escape',
'Test List Field No Escape', 'ListField')
list_field_no_escape = getattr(form, 'list_field_no_escape')
list_field_no_escape.tales['items'] = TALESMethod("structure; python:['<i>label</i>', 'value']")
self.assertIn('\n&lt;i&gt;label&lt;/i&gt;', list_field_escape.render())
self.assertIn('<i>label</i>', list_field_no_escape.render())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment