From 9fb9697e3b583bdc563f2c5e4ac016276e2080fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 14 Mar 2022 20:50:52 +0100
Subject: [PATCH] tests: add markup to string field value to check it's escaped
 properly (#61391)

---
 tests/test_wcs.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index f21d6d52..2e7bdb90 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -137,7 +137,7 @@ WCS_CARDS_DATA = {
             'text': 'aa',
             'url': '/backoffice/data/card_model_1/11/',
             'fields': {
-                'fielda': 'a',
+                'fielda': '<i>a</i>',
                 'fieldb': True,
                 'fieldc': '2020-09-28',
                 'fieldd': {'filename': 'file.pdf', 'url': 'http://127.0.0.1:8999/download?f=42'},
@@ -2449,7 +2449,7 @@ def test_card_cell_render(mock_send, context, app):
     mock_send.reset_mock()
     result = cell.render(context)
     assert '<h2>Card Model 1 - aa</h2>' in result
-    assert PyQuery(result).find('.label:contains("Field A") + .value').text() == 'a'
+    assert PyQuery(result).find('.label:contains("Field A") + .value').text() == '<i>a</i>'
     assert PyQuery(result).find('.label:contains("Field B") + .value').text() == 'yes'
     assert PyQuery(result).find('.label:contains("Field C") + .value').text() == 'Sept. 28, 2020'
     assert PyQuery(result).find('.label:contains("Related") + .value').text() == 'Foo Bar'
@@ -2463,7 +2463,7 @@ def test_card_cell_render(mock_send, context, app):
     cell.save()
     assert cell.get_additional_label() == '&lt;b&gt;Foo bar {{ card.fields.fielda }}&lt;/b&gt;'
     result = cell.render(context)
-    assert '<h2>&lt;b&gt;Foo bar a&lt;/b&gt;</h2>' in result
+    assert '<h2>&lt;b&gt;Foo bar &lt;i&gt;a&lt;/i&gt;&lt;/b&gt;</h2>' in result
 
     context.pop('title')
     cell.custom_title = '{{ foobar }}'
@@ -2627,7 +2627,7 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     context['synchronous'] = True  # to get fresh content
 
     result = cell.render(context)
-    assert PyQuery(result).find('h3').text() == 'a'
+    assert PyQuery(result).find('h3').text() == '<i>a</i>'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fielda',
@@ -2636,7 +2636,7 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('h4').text() == 'a'
+    assert PyQuery(result).find('h4').text() == '<i>a</i>'
 
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'title'}
     cell.save()
@@ -2660,7 +2660,7 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'value', 'display_mode': 'text'}
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('.value').text() == 'a'
+    assert PyQuery(result).find('.value').text() == '<i>a</i>'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fielda',
@@ -2670,7 +2670,7 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     cell.save()
     result = cell.render(context)
     assert PyQuery(result).find('.label').text() == 'Field A'
-    assert PyQuery(result).find('.value').text() == 'a'
+    assert PyQuery(result).find('.value').text() == '<i>a</i>'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldb',
@@ -2887,7 +2887,7 @@ def test_card_cell_render_custom_schema_custom_entry(mock_send, context, app):
     cell.custom_schema['cells'][0]['display_mode'] = 'subtitle'
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('h4').text() == 'a - Foo Bar (42)'
+    assert PyQuery(result).find('h4').text() == '<i>a</i> - Foo Bar (42)'
 
     # test display_mode & filters in template
     cell.custom_schema = {
@@ -2975,14 +2975,14 @@ def test_card_cell_render_custom_schema_link_entry(mock_send, context, app):
     context['synchronous'] = True  # to get fresh content
 
     result = cell.render(context)
-    assert PyQuery(result).find('.value a').text() == 'a - Foo Bar'
+    assert PyQuery(result).find('.value a').text() == '<i>a</i> - Foo Bar'
     assert PyQuery(result).find('.value a').attr['href'] == '/foo/bar/42/'
     assert PyQuery(result).find('.value a').attr['class'] is None
 
     cell.custom_schema['cells'][0]['display_mode'] = 'button'
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('.value a').text() == 'a - Foo Bar'
+    assert PyQuery(result).find('.value a').text() == '<i>a</i> - Foo Bar'
     assert PyQuery(result).find('.value a').attr['href'] == '/foo/bar/42/'
     assert PyQuery(result).find('.value a').attr['class'] == 'pk-button'
 
@@ -3001,7 +3001,7 @@ def test_card_cell_render_custom_schema_link_entry(mock_send, context, app):
     )
     cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[0])
     assert (
-        '<div class="value"><a href="http://testserver/foo/bar/42/" class="pk-button">&lt;b&gt;a&lt;/b&gt; - Foo Bar</a></div>'
+        '<div class="value"><a href="http://testserver/foo/bar/42/" class="pk-button">&lt;b&gt;&lt;i&gt;a&lt;/i&gt;&lt;/b&gt; - Foo Bar</a></div>'
         in cell_resp
     )
 
-- 
2.35.1

