[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/testcases/ -> test_template_helper_functions.php (source)

   1  <?php
   2  
   3  // As the test cases don't load the GP front end, we need to include the helper-functions here to make them available.
   4  require_once GP_TMPL_PATH . 'helper-functions.php';
   5  
   6  class GP_Test_Template_Helper_Functions extends GP_UnitTestCase {
   7  
   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.';
  12  
  13          $entry = new Translation_Entry( array( 'singular' => $test_string, ) );
  14  
  15          $set = $this->factory->translation_set->create_with_project_and_locale();
  16          $glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
  17  
  18          $glossary_entry = array(
  19              'term' => '&',
  20              'part_of_speech' => 'interjection',
  21              'translation' => '&amp;',
  22              'glossary_id' => $glossary->id,
  23          );
  24  
  25          GP::$glossary_entry->create_and_select( $glossary_entry );
  26  
  27          $orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
  28  
  29          $this->assertEquals( $orig->singular_glossary_markup, $expected_result );
  30      }
  31  
  32      /**
  33       * Expects matching a term with a space between words [color scheme].
  34       */
  35      function test_map_glossary_entries_to_translation_originals_with_spaces_in_glossary() {
  36          $test_string = 'Please set your favorite color scheme.';
  37          $orig = '';
  38          $expected_result = 'Please set your favorite <span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;paleta de cores&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">color scheme</span>.';
  39  
  40          $entry = new Translation_Entry( array( 'singular' => $test_string, ) );
  41  
  42          $set = $this->factory->translation_set->create_with_project_and_locale();
  43          $glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
  44  
  45          $glossary_entry = array(
  46              'term' => 'color scheme',
  47              'part_of_speech' => 'noun',
  48              'translation' => 'paleta de cores',
  49              'glossary_id' => $glossary->id,
  50          );
  51  
  52          GP::$glossary_entry->create_and_select( $glossary_entry );
  53  
  54          $orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
  55  
  56          $this->assertEquals( $orig->singular_glossary_markup, $expected_result );
  57      }
  58  
  59      /**
  60       * Expects matching a term with an hyphen [color-scheme].
  61       */
  62      function test_map_glossary_entries_to_translation_originals_with_hyphens_in_glossary() {
  63          $test_string = 'Please set your favorite color-scheme.';
  64          $orig = '';
  65          $expected_result = 'Please set your favorite <span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;paleta de cores&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">color-scheme</span>.';
  66  
  67          $entry = new Translation_Entry( array( 'singular' => $test_string, ) );
  68  
  69          $set = $this->factory->translation_set->create_with_project_and_locale();
  70          $glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
  71  
  72          $glossary_entry = array(
  73              'term' => 'color-scheme',
  74              'part_of_speech' => 'noun',
  75              'translation' => 'paleta de cores',
  76              'glossary_id' => $glossary->id,
  77          );
  78  
  79          GP::$glossary_entry->create_and_select( $glossary_entry );
  80  
  81          $orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
  82  
  83          $this->assertEquals( $orig->singular_glossary_markup, $expected_result );
  84      }
  85  
  86      /**
  87       * Expects matching a term with space and hyphen mixed [GlotPress WP-Team].
  88       */
  89      function test_map_glossary_entries_to_translation_originals_with_spaces_and_hyphens_in_glossary() {
  90          $test_string = 'Prowdly built by your GlotPress WP-Team.';
  91          $orig = '';
  92          $expected_result = 'Prowdly built by your <span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;Equipa-WP do GlotPress&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">GlotPress WP-Team</span>.';
  93  
  94          $entry = new Translation_Entry( array( 'singular' => $test_string, ) );
  95  
  96          $set = $this->factory->translation_set->create_with_project_and_locale();
  97          $glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
  98  
  99          $glossary_entry = array(
 100              'term' => 'GlotPress WP-Team',
 101              'part_of_speech' => 'noun',
 102              'translation' => 'Equipa-WP do GlotPress',
 103              'glossary_id' => $glossary->id,
 104          );
 105  
 106          GP::$glossary_entry->create_and_select( $glossary_entry );
 107  
 108          $orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
 109  
 110          $this->assertEquals( $orig->singular_glossary_markup, $expected_result );
 111      }
 112  
 113      /**
 114       * Expects matching the 3 words term [admin color scheme] instead of the 2 words term [color scheme] or single word term [admin].
 115       */
 116      function test_map_glossary_entries_to_translation_originals_with_word_count_priority() {
 117          $test_string = 'Please set your admin color scheme.';
 118          $orig = '';
 119          $expected_result = 'Please set your <span class="glossary-word" data-translations="[{&quot;translation&quot;:&quot;paleta de cores do administrador&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;comment&quot;:null,&quot;locale_entry&quot;:&quot;&quot;}]">admin color scheme</span>.';
 120  
 121          $entry = new Translation_Entry( array( 'singular' => $test_string, ) );
 122  
 123          $set = $this->factory->translation_set->create_with_project_and_locale();
 124          $glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
 125  
 126          $glossary_entries = array(
 127              array(
 128                  'term' => 'admin',
 129                  'part_of_speech' => 'noun',
 130                  'translation' => 'administrador',
 131                  'glossary_id' => $glossary->id,
 132              ),
 133              array(
 134                  'term' => 'color scheme',
 135                  'part_of_speech' => 'noun',
 136                  'translation' => 'paleta de cores',
 137                  'glossary_id' => $glossary->id,
 138              ),
 139              array(
 140                  'term' => 'admin color scheme',
 141                  'part_of_speech' => 'noun',
 142                  'translation' => 'paleta de cores do administrador',
 143                  'glossary_id' => $glossary->id,
 144              ),
 145          );
 146  
 147          foreach ( $glossary_entries as $glossary_entry ) {
 148              GP::$glossary_entry->create_and_select( $glossary_entry );
 149          }
 150  
 151          $orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
 152  
 153          $this->assertEquals( $orig->singular_glossary_markup, $expected_result );
 154      }
 155  
 156  }


Generated: Wed Jun 29 01:01:13 2022 Cross-referenced by PHPXref 0.7.1