tests: Add a test suite for verifying the mobile push notifs content.

This test suite works by using the expected_output and new text_output
fields in the bugdown test cases to verify that each syntax is
correctly translated by this new function.

Some of these translations, like strikethrough, are kinda poor; but
this framework should make it easy to iterate on the formatting.

Fixes: #6720.
This commit is contained in:
Harshit Bansal 2017-10-06 21:16:29 +00:00 committed by Tim Abbott
parent 5a6584890d
commit 7b88e3eea7
2 changed files with 163 additions and 62 deletions

View File

@ -4,151 +4,176 @@
"name": "codeblock_hilite",
"input": "Hamlet said:\n~~~~.python \ndef speak(self):\n x = 1\n~~~~",
"expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">speak</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n <span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>",
"marked_expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\"><pre><span></span>def speak(self):\n x = 1\n</pre></div>"
"marked_expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\"><pre><span></span>def speak(self):\n x = 1\n</pre></div>",
"text_content": "Hamlet said:\ndef speak(self):\n x = 1\n"
},
{
"name": "basic_paragraph",
"input": "test_input",
"expected_output": "<p>test_input</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "test_input"
},
{
"name": "codeblock_multiline",
"input": "Hamlet once said\n~~~~\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n~~~~\nAnd all was good.",
"expected_output": "<p>Hamlet once said</p>\n<div class=\"codehilite\"><pre><span></span>def func():\n x = 1\n\n y = 2\n\n z = 3\n</pre></div>\n\n\n<p>And all was good.</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Hamlet once said\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n\n\n\nAnd all was good."
},
{
"name": "codeblock_trailing_whitespace",
"input": "Hamlet once said\n~~~~\ndef func():\n x = 1\n\n y = 2\t\t\n\n z = 3 \n~~~~\nAnd all was good.",
"expected_output": "<p>Hamlet once said</p>\n<div class=\"codehilite\"><pre><span></span>def func():\n x = 1\n\n y = 2\n\n z = 3\n</pre></div>\n\n\n<p>And all was good.</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Hamlet once said\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n\n\n\nAnd all was good."
},
{
"name": "codeblock_backticks",
"input": "\n```\nfenced code\n```\n\n```inline code```\n",
"expected_output": "<div class=\"codehilite\"><pre><span></span>fenced code\n</pre></div>\n\n\n<p><code>inline code</code></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"test_content": "fenced code\n\n\n\ninline code"
},
{
"name": "hanging_multi_codeblock",
"input": "Hamlet said:\n~~~~\ndef speak(self):\n x = 1\n# Comment to make this code block longer to test Trac #1162\n~~~~\n\nThen he mentioned ````y = 4 + x**2```` and\n~~~~\ndef foobar(self):\n return self.baz()",
"expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\"><pre><span></span>def speak(self):\n x = 1\n# Comment to make this code block longer to test Trac #1162\n</pre></div>\n\n\n<p>Then he mentioned <code>y = 4 + x**2</code> and</p>\n<div class=\"codehilite\"><pre><span></span>def foobar(self):\n return self.baz()\n</pre></div>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"test_content": "Hamlet said:\ndef speak(self):\n x = 1\n# Comment to make this code block longer to test Trac #1162\n\n\n\nThen he mentioned y = 4 + x**2 and\ndef foobar(self):\n return self.baz()\n"
},
{
"name": "fenced_quote",
"input": "Hamlet said:\n~~~ quote\nTo be or **not** to be.\n\nThat is the question\n~~~",
"expected_output": "<p>Hamlet said:</p>\n<blockquote>\n<p>To be or <strong>not</strong> to be.</p>\n<p>That is the question</p>\n</blockquote>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Hamlet said:\n\nTo be or not to be.\nThat is the question\n"
},
{
"name": "fenced_nested_quote",
"input": "Hamlet said:\n~~~ quote\nPolonius said:\n> This above all: to thine ownself be true,\nAnd it must follow, as the night the day,\nThou canst not then be false to any man.\n\nWhat good advice!\n~~~",
"expected_output": "<p>Hamlet said:</p>\n<blockquote>\n<p>Polonius said:</p>\n<blockquote>\n<p>This above all: to thine ownself be true,<br>\nAnd it must follow, as the night the day,<br>\nThou canst not then be false to any man.</p>\n</blockquote>\n<p>What good advice!</p>\n</blockquote>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Hamlet said:\n\nPolonius said:\n\nThis above all: to thine ownself be true,\nAnd it must follow, as the night the day,\nThou canst not then be false to any man.\n\nWhat good advice!\n"
},
{
"name": "complexly_nested_quote",
"input": "I heard about this second hand...\n~~~ quote\n\nHe said:\n~~~ quote\nThe customer is complaining.\n\nThey looked at this code:\n``` \ndef hello(): print 'hello\n```\nThey would prefer:\n~~~\ndef hello()\n puts 'hello'\nend\n~~~\n\nPlease advise.\n~~~\n\nShe said:\n~~~ quote\nJust send them this:\n```\necho \"hello\n\"\n```\n~~~",
"expected_output": "<p>I heard about this second hand...</p>\n<blockquote>\n<p>He said:</p>\n<blockquote>\n<p>The customer is complaining.</p>\n<p>They looked at this code:</p>\n<div class=\"codehilite\"><pre><span></span>def hello(): print &#39;hello\n</pre></div>\n\n\n<p>They would prefer:</p>\n</blockquote>\n<p>def hello()<br>\n puts 'hello'<br>\nend</p>\n</blockquote>\n<p>Please advise.</p>\n<div class=\"codehilite\"><pre><span></span>She said:\n~~~ quote\nJust send them this:\n```\necho &quot;hello\n&quot;\n```\n</pre></div>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "I heard about this second hand...\n\nHe said:\n\nThe customer is complaining.\nThey looked at this code:\ndef hello(): print 'hello\n\n\n\nThey would prefer:\n\ndef hello()\n puts 'hello'\nend\n\nPlease advise.\nShe said:\n~~~ quote\nJust send them this:\n```\necho \"hello\n\"\n```\n"
},
{
"name": "fenced_quote_with_hashtag",
"input": "```quote\n# line 1\n# line 2\n```",
"expected_output": "<blockquote>\n<p># line 1<br>\n# line 2</p>\n</blockquote>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\n# line 1\n# line 2\n"
},
{
"name": "dangerous_block",
"input": "xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\n```\"xxxx xxxx\\xxxxx\\xxxxxx\"```\n\nxxx xxxx xxxxx:```xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)```\n\nxxxxxxx'x xxxx xxxxxxxxxx ```'xxxx'```, xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?",
"expected_output": "<p>xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:</p>\n<p><code>\"xxxx xxxx\\xxxxx\\xxxxxx\"</code></p>\n<p>xxx xxxx xxxxx:<code>xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)</code></p>\n<p>xxxxxxx'x xxxx xxxxxxxxxx <code>'xxxx'</code>, xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?</p>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\"xxxx xxxx\\xxxxx\\xxxxxx\"\nxxx xxxx xxxxx:xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)\nxxxxxxx'x xxxx xxxxxxxxxx 'xxxx', xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?"
},
{
"name": "dangerous_block",
"input": "``` one ```\n\n``` two ```\n\n~~~~\nx = 1",
"expected_output": "<p><code>one</code></p>\n<p><code>two</code></p>\n<div class=\"codehilite\"><pre><span></span>x = 1\n</pre></div>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "one\ntwo\nx = 1\n"
},
{
"name": "four_space_code_block",
"input": " def foo(): pass",
"expected_output": "<div class=\"codehilite\"><pre><span></span>def foo(): pass\n</pre></div>",
"marked_expected_output": "<div class=\"codehilite\"><pre>def foo(): pass\n</pre></div>"
"marked_expected_output": "<div class=\"codehilite\"><pre>def foo(): pass\n</pre></div>",
"text_content": "def foo(): pass\n"
},
{
"name": "two_space_not_code_block",
"input": " notcode",
"expected_output": "<p>notcode</p>",
"marked_expected_output": "<p> notcode</p>"
"marked_expected_output": "<p> notcode</p>",
"text_content": "notcode"
},
{
"name": "ulist_standard",
"input": "Some text with a list:\n\n* One item\n* Two items\n* Three items",
"expected_output": "<p>Some text with a list:</p>\n<ul>\n<li>One item</li>\n<li>Two items</li>\n<li>Three items</li>\n</ul>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Some text with a list:\n\nOne item\nTwo items\nThree items\n"
},
{
"name": "ulist_hanging",
"input": "Some text with a hanging list:\n* One item\n* Two items\n* Three items",
"expected_output": "<p>Some text with a hanging list:</p>\n<ul>\n<li>One item</li>\n<li>Two items</li>\n<li>Three items</li>\n</ul>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Some text with a hanging list:\n\nOne item\nTwo items\nThree items\n"
},
{
"name": "ulist_hanging_mixed",
"input": "Plain list\n\n* Alpha\n\n* Beta\n\nThen hang it off:\n* Ypsilon\n* Zeta",
"expected_output": "<p>Plain list</p>\n<ul>\n<li>\n<p>Alpha</p>\n</li>\n<li>\n<p>Beta</p>\n</li>\n</ul>\n<p>Then hang it off:</p>\n<ul>\n<li>Ypsilon</li>\n<li>Zeta</li>\n</ul>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "Plain list\n\n\nAlpha\n\n\nBeta\n\n\nThen hang it off:\n\nYpsilon\nZeta\n"
},
{
"name": "ulist_hanging_multi",
"input": "Plain list\n* Alpha\n* Beta\n\nAnd Again:\n* A\n* B\n* C\n\nOnce more for feeling:\n* Q\n* E\n* D",
"expected_output": "<p>Plain list</p>\n<ul>\n<li>Alpha</li>\n<li>Beta</li>\n</ul>\n<p>And Again:</p>\n<ul>\n<li>A</li>\n<li>B</li>\n<li>C</li>\n</ul>\n<p>Once more for feeling:</p>\n<ul>\n<li>Q</li>\n<li>E</li>\n<li>D</li>\n</ul>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Plain list\n\nAlpha\nBeta\n\nAnd Again:\n\nA\nB\nC\n\nOnce more for feeling:\n\nQ\nE\nD\n"
},
{
"name": "ulist_nested_ulist_two_space_indent",
"input": "Nested list\n* I am outer list\n * I am inner nested list first item\n * I am inner nested list second item",
"expected_output": "<p>Nested list</p>\n<ul>\n<li>I am outer list<ul>\n<li>I am inner nested list first item</li>\n<li>I am inner nested list second item</li>\n</ul>\n</li>\n</ul>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Nested list\n\nI am outer list\nI am inner nested list first item\nI am inner nested list second item\n\n\n"
},
{
"name": "ulist_list_two_space_indent",
"input": "* I am outer list\n I am something inside",
"expected_output": "<ul>\n<li>I am outer list<br>\n I am something inside</li>\n</ul>",
"marked_expected_output": "<ul>\n<li>I am outer list<br>\nI am something inside</li>\n</ul>"
"marked_expected_output": "<ul>\n<li>I am outer list<br>\nI am something inside</li>\n</ul>",
"text_content": "\nI am outer list\n I am something inside\n"
},
{
"name": "ulist_codeblock",
"input": "~~~\nint x = 3\n* 4;\n~~~",
"expected_output": "<div class=\"codehilite\"><pre><span></span>int x = 3\n* 4;\n</pre></div>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "int x = 3\n* 4;\n"
},
{
"name": "malformed_fence",
"input": "~~~~~~~~xxxxxxxxx: xxxxxxxxxxxx xxxxx x xxxxxxxx~~~~~~",
"expected_output": "<p>~~~~~~~~xxxxxxxxx: xxxxxxxxxxxx xxxxx x xxxxxxxx~~~~~~</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "~~~~~~~~xxxxxxxxx: xxxxxxxxxxxx xxxxx x xxxxxxxx~~~~~~"
},
{
"name": "strikthrough_basic",
"input": "I like ~~software~~ hardware",
"expected_output": "<p>I like <del>software</del> hardware</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "I like software hardware"
},
{
"name": "strikthrough_multiword",
"input": "I ~~like software~~ love hardware",
"expected_output": "<p>I <del>like software</del> love hardware</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "I like software love hardware"
},
{
"name": "strikthrough_multiword",
"input": "I ~~ like software ~~ love hardware",
"expected_output": "<p>I <del> like software </del> love hardware</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "I like software love hardware"
},
{
"name": "underscore_disabled",
@ -160,7 +185,8 @@
"name": "emphasis_text",
"input": "*foo*",
"expected_output": "<p><em>foo</em></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "foo"
},
{
"name": "emphasis_code",
@ -172,7 +198,8 @@
"name": "emphasis_with_space",
"input": "A *foo bar* is a *baz quux*",
"expected_output": "<p>A <em>foo bar</em> is a <em>baz quux</em></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "A foo bar is a baz quux"
},
{
"name": "underscore_strong_disabled",
@ -184,31 +211,36 @@
"name": "star_strong",
"input": "**foo**",
"expected_output": "<p><strong>foo</strong></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "foo"
},
{
"name": "numbered_list",
"input": "1. A\n 2. B",
"expected_output": "<p>1. A<br>\n 2. B</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "1. A\n 2. B"
},
{
"name": "linkify_interference",
"input": "link: xx, x xxxxx xx xxxx xx\n\n[xxxxx #xx](http://xxxxxxxxx:xxxx/xxx/xxxxxx%xxxxxx/xx/):**xxxxxxx**\n\nxxxxxxx xxxxx xxxx xxxxx:\n`xxxxxx`: xxxxxxx\n`xxxxxx`: xxxxx\n`xxxxxx`: xxxxx xxxxx",
"expected_output": "<p>link: xx, x xxxxx xx xxxx xx</p>\n<p><a href=\"http://xxxxxxxxx:xxxx/xxx/xxxxxx%xxxxxx/xx/\" target=\"_blank\" title=\"http://xxxxxxxxx:xxxx/xxx/xxxxxx%xxxxxx/xx/\">xxxxx #xx</a>:<strong>xxxxxxx</strong></p>\n<p>xxxxxxx xxxxx xxxx xxxxx:<br>\n<code>xxxxxx</code>: xxxxxxx<br>\n<code>xxxxxx</code>: xxxxx<br>\n<code>xxxxxx</code>: xxxxx xxxxx</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "link: xx, x xxxxx xx xxxx xx\nxxxxx #xx:xxxxxxx\nxxxxxxx xxxxx xxxx xxxxx:\nxxxxxx: xxxxxxx\nxxxxxx: xxxxx\nxxxxxx: xxxxx xxxxx"
},
{
"name": "inline_image",
"input": "Google logo today: https://www.google.com/images/srpr/logo4w.png\nKinda boring",
"expected_output": "<p>Google logo today: <a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\">https://www.google.com/images/srpr/logo4w.png</a><br>\nKinda boring</p>\n<div class=\"message_inline_image\"><a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\"><img src=\"https://www.google.com/images/srpr/logo4w.png\"></a></div>",
"backend_only_rendering": true
"backend_only_rendering": true,
"text_content": "Google logo today: https:\/\/www.google.com\/images\/srpr\/logo4w.png\nKinda boring\n"
},
{
"name": "two_inline_images",
"input": "Google logo today: https://www.google.com/images/srpr/logo4w.png\nKinda boringGoogle logo today: https://www.google.com/images/srpr/logo4w.png\nKinda boring",
"expected_output": "<p>Google logo today: <a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\">https://www.google.com/images/srpr/logo4w.png</a><br>\nKinda boringGoogle logo today: <a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\">https://www.google.com/images/srpr/logo4w.png</a><br>\nKinda boring</p>\n<div class=\"message_inline_image\"><a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\"><img src=\"https://www.google.com/images/srpr/logo4w.png\"></a></div><div class=\"message_inline_image\"><a href=\"https://www.google.com/images/srpr/logo4w.png\" target=\"_blank\" title=\"https://www.google.com/images/srpr/logo4w.png\"><img src=\"https://www.google.com/images/srpr/logo4w.png\"></a></div>",
"backend_only_rendering": true
"backend_only_rendering": true,
"text_content": "Google logo today: https:\/\/www.google.com\/images\/srpr\/logo4w.png\nKinda boringGoogle logo today: https:\/\/www.google.com\/images\/srpr\/logo4w.png\nKinda boring\n"
},
{
"name": "camo",
@ -220,31 +252,36 @@
"name": "nl2br",
"input": "test\nbar",
"expected_output": "<p>test<br>\nbar</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "test\nbar"
},
{
"name": "nl2br_trailing_space",
"input": "test ",
"expected_output": "<p>test </p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "test "
},
{
"name": "tables",
"input": "This is a table:\n\nFirst Header | Second Header\n------------- | -------------\nContent Cell | Content Cell\nContent Cell | Content Cell\n",
"expected_output": "<p>This is a table:</p>\n<table>\n<thead>\n<tr>\n<th>First Header</th>\n<th>Second Header</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Content Cell</td>\n<td>Content Cell</td>\n</tr>\n<tr>\n<td>Content Cell</td>\n<td>Content Cell</td>\n</tr>\n</tbody>\n</table>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "This is a table:\n\n\n\nFirst Header\nSecond Header\n\n\n\n\nContent Cell\nContent Cell\n\n\nContent Cell\nContent Cell\n\n\n"
},
{
"name": "multiline_strong",
"input": "You can check out **any time you'd like\nBut you can never leave**",
"expected_output": "<p>You can check out **any time you'd like<br>\nBut you can never leave**</p>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "You can check out **any time you'd like\nBut you can never leave**"
},
{
"name": "many_emoji",
"input": "test :smile: again :poop:\n:) foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:",
"expected_output": "<p>test <span class=\"emoji emoji-1f604\" title=\"smile\">:smile:</span> again <span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span><br>\n:) foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "test \ud83d\ude04 again \ud83d\udca9\n:) foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:"
},
{
"name": "random_emoji_1",
@ -256,7 +293,8 @@
"name": "zulip_emoji",
"input": ":zulip:",
"expected_output": "<p><img alt=\":zulip:\" class=\"emoji\" src=\"/static/generated/emoji/images/emoji/unicode/zulip.png\" title=\"zulip\"></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": ":zulip:"
},
{
"name": "random_emoji_2",
@ -268,43 +306,50 @@
"name": "emojis_without_space",
"input": ":cat:hello:dog::rabbit:",
"expected_output": "<p><span class=\"emoji emoji-1f431\" title=\"cat\">:cat:</span>hello<span class=\"emoji emoji-1f436\" title=\"dog\">:dog:</span><span class=\"emoji emoji-1f430\" title=\"rabbit\">:rabbit:</span></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udc31hello\ud83d\udc36\ud83d\udc30"
},
{
"name": "emojis_newline",
"input": ":cat:\n:dog:",
"expected_output": "<p><span class=\"emoji emoji-1f431\" title=\"cat\">:cat:</span><br>\n<span class=\"emoji emoji-1f436\" title=\"dog\">:dog:</span></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udc31\n\ud83d\udc36"
},
{
"name": "not_emoji",
"input": ":not_an_emoji:",
"expected_output": "<p>:not_an_emoji:</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": ":not_an_emoji:"
},
{
"name": "unicode_emoji",
"input": "\ud83d\udca9",
"expected_output":"<p><span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udca9"
},
{
"name": "two_unicode_emoji",
"input": "\ud83d\udca9\ud83d\udca9",
"expected_output":"<p><span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span><span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span><\/p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udca9\ud83d\udca9"
},
{
"name": "two_unicode_emoji_separated_by_text",
"input": "\ud83d\udca9 word \ud83d\udca9",
"expected_output":"<p><span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span> word <span class=\"emoji emoji-1f4a9\" title=\"poop\">:poop:</span><\/p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udca9 word \ud83d\udca9"
},
{
"name": "miscellaneous_symbols_and_pictographs",
"input": "Merry Christmas!!\ud83c\udf84",
"expected_output":"<p>Merry Christmas!!<span class=\"emoji emoji-1f384\" title=\"christmas tree\">:christmas_tree:</span><\/p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Merry Christmas!!\ud83c\udf84"
},
{
"name": "miscellaneous_and_dingbats_emoji",
@ -334,7 +379,8 @@
"name": "unicode_emojis_new_line",
"input": "\ud83d\udc7d\n\ud83d\udc7d",
"expected_output":"<p><span class=\"emoji emoji-1f47d\" title=\"alien\">:alien:</span><br>\n<span class=\"emoji emoji-1f47d\" title=\"alien\">:alien:</span></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "\ud83d\udc7d\n\ud83d\udc7d"
},
{
"name": "emoji_alongside_punctuation",
@ -364,31 +410,36 @@
"name": "emojis_with_zwj_are_banned",
"input": "Emojis like :man-girl-girl: which have ZWJ are banned for now.",
"expected_output": "<p>Emojis like :man-girl-girl: which have ZWJ are banned for now.</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "Emojis like :man-girl-girl: which have ZWJ are banned for now."
},
{
"name": "safe_html",
"input": "<h1>stay normal</h1> thanks",
"expected_output": "<p>&lt;h1&gt;stay normal&lt;/h1&gt; thanks</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "<h1>stay normal<\/h1> thanks"
},
{
"name": "safe_html_with_simple_script_tag",
"input": "<script>alert(1)</script>",
"expected_output": "<p>&lt;script&gt;alert(1)&lt;/script&gt;</p>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "<script>alert(1)<\/script>"
},
{
"name": "safe_html_nested_script_tag",
"input": "<<script>script>evil()<</script>/script>",
"expected_output": "<p>&lt;&lt;script&gt;script&gt;evil()&lt;&lt;/script&gt;/script&gt;</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "<<script>script>evil()<<\/script>\/script>"
},
{
"name": "safe_html_nested_script_tag_with_parse_error",
"input": "<<x>script>evil()<</x>/script>",
"expected_output": "<p>&lt;&lt;x&gt;script&gt;evil()&lt;&lt;/x&gt;/script&gt;</p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "<<x>script>evil()<<\/x>\/script>"
},
{
"name": "safe_html_messed_up_complexly_nested_script_tags",
@ -412,61 +463,71 @@
"name": "safe_html_in_code",
"input": "~~~\n<h1>stay normal</h1>",
"expected_output": "<div class=\"codehilite\"><pre><span></span>&lt;h1&gt;stay normal&lt;/h1&gt;\n</pre></div>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "<h1>stay normal<\/h1>\n"
},
{
"name": "ulist_with_inline_code",
"input": "gonna take a break for a bit--all yours if you want to play around too. what I did:\n\n* install cmake\n* git clone zulip desktop\n* run `cmake-gui ..` in `c:\\zulip\\zulip-desktop\\msvcbuild`\n* hit configure/generate until it generated the msvc project (had to make a fix to some cmake files)\n* opened vs2013 \n* tried to build\n",
"expected_output": "<p>gonna take a break for a bit--all yours if you want to play around too. what I did:</p>\n<ul>\n<li>install cmake</li>\n<li>git clone zulip desktop</li>\n<li>run <code>cmake-gui ..</code> in <code>c:\\zulip\\zulip-desktop\\msvcbuild</code></li>\n<li>hit configure/generate until it generated the msvc project (had to make a fix to some cmake files)</li>\n<li>opened vs2013 </li>\n<li>tried to build</li>\n</ul>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "gonna take a break for a bit--all yours if you want to play around too. what I did:\n\ninstall cmake\ngit clone zulip desktop\nrun cmake-gui .. in c:\\zulip\\zulip-desktop\\msvcbuild\nhit configure\/generate until it generated the msvc project (had to make a fix to some cmake files)\nopened vs2013 \ntried to build\n"
},
{
"name": "modal_link",
"input": "!modal_link(#settings, Settings page)",
"expected_output": "<p><a href=\"#settings\" title=\"#settings\">Settings page</a></p>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "Settings page"
},
{
"name": "modal_link_escaped",
"input": "`!modal_link(#settings, Settings page)`",
"expected_output": "<p><code>!modal_link(#settings, Settings page)</code></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "!modal_link(#settings, Settings page)"
},
{
"name": "avatar",
"input": "!avatar(username@example.com)",
"expected_output": "<p><img alt=\"username@example.com\" class=\"message_body_gravatar\" src=\"/avatar/username@example.com?s=30\" title=\"username@example.com\"></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "username@example.com"
},
{
"name": "gravatar",
"input": "!gravatar(username@example.com)",
"expected_output": "<p><img alt=\"username@example.com\" class=\"message_body_gravatar\" src=\"/avatar/username@example.com?s=30\" title=\"username@example.com\"></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "username@example.com"
},
{
"name": "avatar_escaped",
"input": "`!avatar(username@example.com)`",
"expected_output": "<p><code>!avatar(username@example.com)</code></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "!avatar(username@example.com)"
},
{
"name": "gravatar_escaped",
"input": "`!gravatar(username@example.com)`",
"expected_output": "<p><code>!gravatar(username@example.com)</code></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "!gravatar(username@example.com)"
},
{
"name": "stream_subscribe_button",
"input": "!_stream_subscribe_button(streamname)",
"expected_output": "<p><span class=\"inline-subscribe\" data-stream-name=\"streamname\"><button class=\"inline-subscribe-button btn\">Subscribe to streamname</button><span class=\"inline-subscribe-error\"></span></span></p>",
"bugdown_matches_marked": false
"bugdown_matches_marked": false,
"text_content": "Subscribe to streamname"
},
{
"name": "stream_subscribe_button_escaped",
"input": "`!_stream_subscribe_button(streamname)`",
"expected_output": "<p><code>!_stream_subscribe_button(streamname)</code></p>",
"bugdown_matches_marked": true
"bugdown_matches_marked": true,
"text_content": "!_stream_subscribe_button(streamname)"
},
{
"name": "tex_inline",

View File

@ -7,6 +7,7 @@ import time
from typing import Any, Dict, List, Union, SupportsInt, Text
import gcm
import os
import ujson
from django.test import TestCase, override_settings
@ -27,7 +28,8 @@ from zerver.models import (
Stream,
)
from zerver.lib import push_notifications as apn
from zerver.lib.push_notifications import DeviceToken
from zerver.lib.push_notifications import get_mobile_push_content, \
DeviceToken
from zerver.lib.response import json_success
from zerver.lib.test_classes import (
ZulipTestCase,
@ -36,6 +38,9 @@ from zerver.lib.test_classes import (
from zilencer.models import RemoteZulipServer, RemotePushDeviceToken
from django.utils.timezone import now
ZERVER_DIR = os.path.dirname(os.path.dirname(__file__))
FIXTURES_FILE_PATH = os.path.join(ZERVER_DIR, "fixtures", "markdown_test_cases.json")
class BouncerTestCase(ZulipTestCase):
def setUp(self):
# type: () -> None
@ -1133,3 +1138,38 @@ class TestReceivesNotificationsFunctions(ZulipTestCase):
self.user.enable_stream_push_notifications = False
self.assertFalse(receives_stream_notifications(self.user))
class TestPushNotificationsContent(ZulipTestCase):
def test_fixtures(self):
# type: () -> None
with open(FIXTURES_FILE_PATH) as fp:
fixtures = ujson.load(fp)
tests = fixtures["regular_tests"]
for test in tests:
if "text_content" in test:
output = get_mobile_push_content(test["expected_output"])
self.assertEqual(output, test["text_content"])
def test_backend_only_fixtures(self):
# type: () -> None
fixtures = [
{
'name': 'realm_emoji',
'rendered_content': '<p>Testing <img alt=":green_tick:" class="emoji" src="/user_avatars/1/emoji/green_tick.png" title="green tick"> realm emoji.</p>',
'expected_output': 'Testing :green_tick: realm emoji.',
},
{
'name': 'mentions',
'rendered_content': '<p>Mentioning <span class="user-mention" data-user-email="cordelia@zulip.com" data-user-id="3">@Cordelia Lear</span>.</p>',
'expected_output': 'Mentioning @Cordelia Lear.',
},
{
'name': 'stream_names',
'rendered_content': '<p>Testing stream names <a class="stream" data-stream-id="5" href="/#narrow/stream/Verona">#Verona</a>.</p>',
'expected_output': 'Testing stream names #Verona.',
},
]
for test in fixtures:
actual_output = get_mobile_push_content(test["rendered_content"])
self.assertEqual(actual_output, test["expected_output"])