Commit c948178a authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

test: canonicalize html during tests

parent e9e6dac5
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.AudioField import AudioField from Products.ERP5Form.AudioField import AudioField
from Products.ERP5Type.tests.utils import canonical_html
class TestAudioField(ERP5TypeTestCase): class TestAudioField(ERP5TypeTestCase):
...@@ -44,9 +45,10 @@ class TestAudioField(ERP5TypeTestCase): ...@@ -44,9 +45,10 @@ class TestAudioField(ERP5TypeTestCase):
def test_render_view(self): def test_render_view(self):
self.field.values['default'] = 'Audio content' self.field.values['default'] = 'Audio content'
self.assertEqual('<audio preload="preload" src="Audio content" ' + self.assertEqual(
'controls="controls" >Your browser does not ' + canonical_html(self.field.render_view(value='Audio content')),
'support audio tag.</audio>', self.field.render_view(value='Audio content')) '<audio controls="controls" preload="preload" src="Audio content"'
+ '>Your browser does not support audio tag.</audio>',)
self.field.values['audio_preload'] = False self.field.values['audio_preload'] = False
self.field.values['audio_loop'] = True self.field.values['audio_loop'] = True
...@@ -54,13 +56,7 @@ class TestAudioField(ERP5TypeTestCase): ...@@ -54,13 +56,7 @@ class TestAudioField(ERP5TypeTestCase):
self.field.values['audio_autoplay'] = True self.field.values['audio_autoplay'] = True
self.field.values['audio_error_message'] = 'Another error message' self.field.values['audio_error_message'] = 'Another error message'
self.assertEqual('<audio src="Another Audio content" ' + self.assertEqual(
'loop="loop" autoplay="autoplay" >Another error ' + canonical_html(self.field.render_view(value='Another Audio content')),
'message</audio>', self.field.render_view(value='Another Audio content')) '<audio autoplay="autoplay" loop="loop" src="Another Audio content"'
+ '>Another error message</audio>')
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAudioField))
return suite
...@@ -45,7 +45,7 @@ from Products.ERP5Form.CaptchaField import CaptchaField ...@@ -45,7 +45,7 @@ from Products.ERP5Form.CaptchaField import CaptchaField
from Products.ERP5Form.EditorField import EditorField from Products.ERP5Form.EditorField import EditorField
from Products.Formulator.MethodField import Method from Products.Formulator.MethodField import Method
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from Products.ERP5Type.tests.utils import canonical_html
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Form.Form import field_value_cache from Products.ERP5Form.Form import field_value_cache
from Products.ERP5Form.Form import getFieldValue from Products.ERP5Form.Form import getFieldValue
...@@ -1275,8 +1275,8 @@ class TestEditorField(ERP5TypeTestCase): ...@@ -1275,8 +1275,8 @@ class TestEditorField(ERP5TypeTestCase):
def test_render_editable_textarea(self): def test_render_editable_textarea(self):
self.field.values['default'] = 'value' self.field.values['default'] = 'value'
self.assertEqual( self.assertEqual(
self.field.render(REQUEST=self.portal.REQUEST), canonical_html(self.field.render(REQUEST=self.portal.REQUEST)),
'<textarea rows="5" cols="40" name="field_test_field" >\nvalue</textarea>') '<textarea cols="40" name="field_test_field" rows="5">\nvalue</textarea>')
def test_render_editable_textarea_REQUEST(self): def test_render_editable_textarea_REQUEST(self):
self.field.values['default'] = 'default value' self.field.values['default'] = 'default value'
...@@ -1285,8 +1285,8 @@ class TestEditorField(ERP5TypeTestCase): ...@@ -1285,8 +1285,8 @@ class TestEditorField(ERP5TypeTestCase):
self.field.generate_field_key(key=self.field.id) self.field.generate_field_key(key=self.field.id)
] = 'user <value>' ] = 'user <value>'
self.assertEqual( self.assertEqual(
self.field.render(REQUEST=self.portal.REQUEST), canonical_html(self.field.render(REQUEST=self.portal.REQUEST)),
'<textarea rows="5" cols="40" name="field_test_field" >\nuser &lt;value&gt;</textarea>') '<textarea cols="40" name="field_test_field" rows="5">\nuser &lt;value&gt;</textarea>')
def test_render_non_editable_textarea(self): def test_render_non_editable_textarea(self):
self.field.values['default'] = '<not &scaped' self.field.values['default'] = '<not &scaped'
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.VideoField import VideoField from Products.ERP5Form.VideoField import VideoField
from Products.ERP5Type.tests.utils import canonical_html
class TestVideoField(ERP5TypeTestCase): class TestVideoField(ERP5TypeTestCase):
"""Tests Video field """Tests Video field
...@@ -43,8 +45,11 @@ class TestVideoField(ERP5TypeTestCase): ...@@ -43,8 +45,11 @@ class TestVideoField(ERP5TypeTestCase):
def test_render_view(self): def test_render_view(self):
self.field.values['default'] = 'Video content' self.field.values['default'] = 'Video content'
self.assertEqual('<video preload="auto" src="Video content" controls="controls" height="85" width="160" >Your browser does not support video tag.</video>', \ self.assertEqual(
self.field.render_view(value='Video content')) canonical_html(self.field.render_view(value='Video content')),
'<video controls="controls" height="85" preload="auto" src="Video content"'
+ ' width="160">Your browser does not support video tag.</video>',
)
self.field.values['video_preload'] = False self.field.values['video_preload'] = False
self.field.values['video_loop'] = True self.field.values['video_loop'] = True
...@@ -54,14 +59,9 @@ class TestVideoField(ERP5TypeTestCase): ...@@ -54,14 +59,9 @@ class TestVideoField(ERP5TypeTestCase):
self.field.values['video_height'] = 800 self.field.values['video_height'] = 800
self.field.values['video_width'] = 1280 self.field.values['video_width'] = 1280
self.assertEqual('<video src="Another Video content" ' +
'height="800" width="1280" loop="loop" autoplay="autoplay" ' +
'>Another error message</video>', \
self.field.render_view(value='Another Video content'))
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestVideoField))
return suite
self.assertEqual(
canonical_html(self.field.render_view(value='Another Video content')),
'<video autoplay="autoplay" height="800" loop="loop"'
+ ' src="Another Video content" width="1280">Another error message</video>'
)
...@@ -55,6 +55,18 @@ from Products.ERP5Type.Utils import simple_decorator ...@@ -55,6 +55,18 @@ from Products.ERP5Type.Utils import simple_decorator
from Products.ZSQLCatalog.SQLCatalog import Catalog from Products.ZSQLCatalog.SQLCatalog import Catalog
import pytz import pytz
import six import six
import lxml.html
def canonical_html(html):
# type: (str) -> str
"""returns canonical form of html text.
"""
return lxml.html.tostring(
lxml.html.fromstring(html),
method="c14n",
).decode('utf-8')
class FileUpload(file): class FileUpload(file):
"""Act as an uploaded file. """Act as an uploaded file.
......
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