Skip to content

Commit b8ddc37

Browse files
Add tests currently passing for the & issue
1 parent 2b7ae2b commit b8ddc37

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

tests/phpunit/testcases/test_template_helper_functions.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,56 @@
55

66
class GP_Test_Template_Helper_Functions extends GP_UnitTestCase {
77

8-
function test_map_glossary_entries_to_translation_originals_with_ampersand_in_glossary() {
9-
$test_string = 'This string, <code>&lt;/body&gt;</code>, should not have the code tags mangled.';
10-
$orig = '';
11-
$expected_result = 'This string, &lt;code&gt;&amp;lt;/body<span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;&amp;amp;&quot;,&quot;pos&quot;:&quot;interjection&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">&amp;</span>gt;&lt;/code&gt;, should not have the code tags mangled.';
8+
/**
9+
* Data provider.
10+
*
11+
* @var array
12+
*/
13+
function provide_test_map_glossary_entries_to_translation_originals_with_ampersand_in_glossary() {
14+
return array(
15+
// Shouldn't mangle the code tags.
16+
array(
17+
'test_string' => 'This string, <code>&lt;/body&gt;</code>, should not have the code tags mangled.',
18+
'expected_result' => 'This string, &lt;code&gt;&amp;lt;/body<span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;&amp;amp;&quot;,&quot;pos&quot;:&quot;interjection&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">&amp;</span>gt;&lt;/code&gt;, should not have the code tags mangled.',
19+
),
20+
array(
21+
'test_string' => 'Products & Services',
22+
'expected_result' => 'Products &amp; Services', // Wrong: Should match.
23+
),
24+
// Test word left bound.
25+
array(
26+
'test_string' => 'Products ,& Services',
27+
'expected_result' => 'Products ,&amp; Services', // Wrong: Should match.
28+
),
29+
// Test word right bound.
30+
array(
31+
'test_string' => 'Products ,& Services',
32+
'expected_result' => 'Products ,&amp; Services', // Wrong: Should match.
33+
),
34+
// Test word both bounds.
35+
array(
36+
'test_string' => 'Products ,&. Services',
37+
'expected_result' => 'Products ,&amp;. Services', // Wrong: Should match.
38+
),
39+
// Don't match examples.
40+
array(
41+
'test_string' => 'Shop &gt; Products &amp; Services',
42+
'expected_result' => 'Shop &amp;gt; Products &amp;amp; Services',
43+
),
44+
// Match the simple &.
45+
array(
46+
'test_string' => 'Shop &gt; Products & Services',
47+
'expected_result' => 'Shop &amp;gt; Products &amp; Services',
48+
),
49+
);
50+
}
1251

52+
/**
53+
* Expects matching glossary term '&'.
54+
*
55+
* @dataProvider provide_test_map_glossary_entries_to_translation_originals_with_ampersand_in_glossary
56+
*/
57+
function test_map_glossary_entries_to_translation_originals_with_ampersand_in_glossary( $test_string, $expected_result ) {
1358
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
1459

1560
$set = $this->factory->translation_set->create_with_project_and_locale();

0 commit comments

Comments
 (0)