Commit ad4e44c3 authored by Romain Courteaud's avatar Romain Courteaud

testEditorField: test the new gadget field used to display/edit the content

parent d230cfe3
master arnau arnau-RD-Components-CacheTool arnau-RD-Components-ERP5Form-ERP5Report arnau-RD-Components-ERP5Form-SelectionTool-MemcachedTool arnau-RD-Components-ERP5OOo arnau-RD-Components-PreferenceTool-Preference arnau-RD-Components-Products-import-compat arnau-RD-Components-astroid_cache_per_component_reset arnau-RD-Components-erp5_crm arnau-RD-Components-erp5_trade-TODO-Interactor arnau-TM-Components-Migrate-PortalTransforms arnau-TM-Components-ModuleSecurityInfo arnau-TM-Components-PortalTransforms arnau-TM-FEC-output arnau-TM-WIP arnau-TM-isBuildable-with-multiple-BusinessLinks arnau-TM-jabber-client-desktop-notifications arnau-TM-newContent-temp_object arnau-TM-runUnitTest-clear-previous-execution-catalog arnau-TM-wkhtmltopdf arnau-WIP arnau-real-time-inventory-accounting catalog_filter cloud_reliability_test cmf_upgrade_versions cribjs-bootloader enhance_scalability_testing erp5-component erp5-imt erp5-messenger erp5-vifib erp5_catalog_final erp5_corporate_identity erp5_hal_json_style_fix_restricted_access_with_traverse erp5_payslip_migration feat/coding_style_form_naming feat/dms_implicit_predecessor_successor_fields feat/erp5_ide feat/inventory_api_group_by_time_interval_list feat/python_language_support feat/stock-report-valuation feat/support_request_crm_translation feat/translated_related_keys fix/ZMI_editor_preference fix/advance_ecommerce_coding_crimes fix/business-template-update-tool fix/support-request-app-empty fix/test_result_after_mep fix/workflow_method_security for_testrunner_1 for_testrunner_2 for_testrunner_3 hotfix/rjs-formfields-padding js-ui listbox_url lle-bout/metadata-modules macros_fix my2to3 override_cache_control_header_by_caching_policy_manager publish_recursiveReindexObject revert-38554dbe scalability-master scalability-run-command scalability_crash_mariadb shop-box-rebase streaming_fix streaming_fix-0 support_request trustable-x-forwarded-for ttrm valentin_translation_fix wsgi wsgi-gevent wsgi_backport_setbody_lock wsgi_medusa_stream_fix 0.4.59.1 0.4.59 test-rjsacc test-rjs erp5.util-0.4.68 erp5.util-0.4.67 erp5.util-0.4.66 erp5.util-0.4.65 erp5.util-0.4.64 erp5.util-0.4.63 erp5.util-0.4.62 erp5.util-0.4.61 erp5.util-0.4.60 erp5.util-0.4.59.1 erp5.util-0.4.59 erp5.util-0.4.58 erp5.util-0.4.57 erp5.util-0.4.56 erp5.util-0.4.55 erp5.util-0.4.54 erp5.util-0.4.53 erp5.util-0.4.52
No related merge requests found
......@@ -34,6 +34,7 @@ import unittest
from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DocumentTemplate.DT_Util import html_quote
class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
"""
......@@ -113,7 +114,7 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure editor field preference is also set
form = getattr(event, form_id)
field = getattr(form, field_id)
self.assertEqual(field.get_value('text_editor'), editor)
self.assertEqual(dict(field.get_value('renderjs_extra'))['editor'], editor)
def _isFCKEditor(self, html_text, field_id, text_content):
"""
......@@ -128,8 +129,8 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
text_content -- the embedded text content
"""
html_text = html_text.encode('utf-8')
match_string1 = "var oFCKeditor = new FCKeditor('field_%s');" % field_id
match_string2 = "oFCKeditor.Value = '%s';" % ('\\n'.join(text_content.splitlines()))
match_string1 = 'data-gadget-editable="field_%s"' % field_id
match_string2 = 'data-gadget-value="%s"' % html_quote(text_content)
if html_text.find(match_string1) == -1:
print html_text
print match_string1
......@@ -153,14 +154,21 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
text_content -- the embedded text content
"""
html_text = html_text.encode('utf-8')
match_string = """name="field_%s" >\n%s</textarea>""" % (field_id, text_content)
if html_text.find(match_string) == -1:
match_string1 = 'data-gadget-editable="field_%s"' % field_id
match_string2 = 'data-gadget-value="%s"' % html_quote(text_content)
if html_text.find(match_string1) == -1:
print html_text
print match_string
print match_string1
import pdb; pdb.set_trace()
return False
if html_text.find(match_string2) == -1:
print html_text
print match_string2
import pdb; pdb.set_trace()
return False
return True
def _isReadOnlyEditor(self, html_text, document):
def _isReadOnlyEditor(self, html_text, document, text_content):
"""
Tries to find in the HTML page string portions
which show that text content is displayed in read
......@@ -172,10 +180,9 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
read only mode
"""
html_text = html_text.encode('utf-8')
text_content = document.asStrippedHTML()
match_string1 = """<div class="input"><div class="page" >\n%s</div></div>""" % text_content
match_string2 = """<div class="field page"""
if html_text.find(match_string1) == -1:
match_string1 = "data-gadget-editable="
match_string2 = 'data-gadget-value="%s"' % html_quote(text_content)
if html_text.find(match_string1) != -1:
print html_text
print match_string1
return False
......@@ -203,8 +210,6 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
self._testPreferredDocumentEditor(event, 'fck_editor', 'fck_editor', 'Event_view', 'my_text_content')
# Make sure generated HTML is based on FCKEditor
request=self.app.REQUEST
request.set('URLPATH2', '/arbitrary/path') # A hack to make sure FCKEditor page template renders
html_text = event.view()
self.assertTrue(self._isFCKEditor(html_text, 'my_text_content', text_content))
......@@ -213,7 +218,7 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
event.setData('fake')
self.assertFalse(event.Event_view.my_text_content.get_value('editable'))
html_text = event.view()
self.assertTrue(self._isReadOnlyEditor(html_text, event))
self.assertTrue(self._isReadOnlyEditor(html_text, event, 'fake'))
def test_EditSimpleEmailEventFCKEditorText(self):
"""
......@@ -234,8 +239,6 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
self._testPreferredDocumentEditor(event, 'fck_editor', 'text_area', 'Event_view', 'my_text_content')
# Make sure generated HTML is based on TextArea since this is not HTML
request=self.app.REQUEST
request.set('URLPATH2', '/arbitrary/path') # A hack to make sure FCKEditor page template renders
html_text = event.view()
self.assertTrue(self._isTextAreaEditor(html_text, 'my_text_content', text_content))
......@@ -244,7 +247,7 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
event.setData('fake')
self.assertFalse(event.Event_view.my_text_content.get_value('editable'))
html_text = event.view()
self.assertTrue(self._isReadOnlyEditor(html_text, event))
self.assertTrue(self._isReadOnlyEditor(html_text, event, 'fake'))
def test_EditSimpleEmailEventTextAreaHTML(self):
"""
......@@ -265,9 +268,6 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure generated HTML is based on TextArea
html_text = event.view()
# text_content is processed to simulate the way TextArea does
text_content = text_content.replace('<', '&lt;')
text_content = text_content.replace('>', '&gt;')
self.assertTrue(self._isTextAreaEditor(html_text, 'my_text_content', text_content))
# Set a fake file on Event and make sure no more editor is displayed
......@@ -275,7 +275,7 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
event.setData('fake')
self.assertFalse(event.Event_view.my_text_content.get_value('editable'))
html_text = event.view()
self.assertTrue(self._isReadOnlyEditor(html_text, event))
self.assertTrue(self._isReadOnlyEditor(html_text, event, 'fake'))
def test_EditSimpleEmailEventTextAreaText(self):
"""
......@@ -303,7 +303,7 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
event.setData('fake')
self.assertFalse(event.Event_view.my_text_content.get_value('editable'))
html_text = event.view()
self.assertTrue(self._isReadOnlyEditor(html_text, event))
self.assertTrue(self._isReadOnlyEditor(html_text, event, 'fake'))
def test_EditWebPageFCKEditorHTML(self):
"""
......@@ -324,8 +324,8 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure default view is read only
html_text = page.WebPage_view()
self.assertFalse(page.WebPage_view.text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page))
self.assertFalse(page.WebPage_view.my_text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page, page.asStrippedHTML()))
def test_EditWebPageFCKEditorText(self):
"""
......@@ -346,8 +346,8 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure default view is read only
html_text = page.WebPage_view()
self.assertFalse(page.WebPage_view.text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page))
self.assertFalse(page.WebPage_view.my_text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page, page.asStrippedHTML()))
def test_EditWebPageTextAreaHTML(self):
"""
......@@ -368,8 +368,8 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure default view is read only
html_text = page.WebPage_view()
self.assertFalse(page.WebPage_view.text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page))
self.assertFalse(page.WebPage_view.my_text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page, page.asStrippedHTML()))
def test_EditWebPageTextAreaText(self):
"""
......@@ -390,8 +390,8 @@ class TestEditorField(ERP5TypeTestCase, ZopeTestCase.Functional):
# Make sure default view is read only
html_text = page.WebPage_view()
self.assertFalse(page.WebPage_view.text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page))
self.assertFalse(page.WebPage_view.my_text_content.get_value('editable'))
self.assertTrue(self._isReadOnlyEditor(html_text, page, page.asStrippedHTML()))
def test_suite():
suite = unittest.TestSuite()
......
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