</body>, should not have the code tags mangled.';
$orig = '';
$expected_result = 'This string, <code></body></code>, should not have the code tags mangled.';
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
$set = $this->factory->translation_set->create_with_project_and_locale();
$glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
$glossary_entry = array(
'term' => '&',
'part_of_speech' => 'interjection',
'translation' => '&',
'glossary_id' => $glossary->id,
);
GP::$glossary_entry->create_and_select( $glossary_entry );
$orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
$this->assertEquals( $orig->singular_glossary_markup, $expected_result );
}
/**
* Expects matching a term with a space between words [color scheme].
*/
function test_map_glossary_entries_to_translation_originals_with_spaces_in_glossary() {
$test_string = 'Please set your favorite color scheme.';
$orig = '';
$expected_result = 'Please set your favorite color scheme.';
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
$set = $this->factory->translation_set->create_with_project_and_locale();
$glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
$glossary_entry = array(
'term' => 'color scheme',
'part_of_speech' => 'noun',
'translation' => 'paleta de cores',
'glossary_id' => $glossary->id,
);
GP::$glossary_entry->create_and_select( $glossary_entry );
$orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
$this->assertEquals( $orig->singular_glossary_markup, $expected_result );
}
/**
* Expects matching a term with an hyphen [color-scheme].
*/
function test_map_glossary_entries_to_translation_originals_with_hyphens_in_glossary() {
$test_string = 'Please set your favorite color-scheme.';
$orig = '';
$expected_result = 'Please set your favorite color-scheme.';
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
$set = $this->factory->translation_set->create_with_project_and_locale();
$glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
$glossary_entry = array(
'term' => 'color-scheme',
'part_of_speech' => 'noun',
'translation' => 'paleta de cores',
'glossary_id' => $glossary->id,
);
GP::$glossary_entry->create_and_select( $glossary_entry );
$orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
$this->assertEquals( $orig->singular_glossary_markup, $expected_result );
}
/**
* Expects matching a term with space and hyphen mixed [GlotPress WP-Team].
*/
function test_map_glossary_entries_to_translation_originals_with_spaces_and_hyphens_in_glossary() {
$test_string = 'Prowdly built by your GlotPress WP-Team.';
$orig = '';
$expected_result = 'Prowdly built by your GlotPress WP-Team.';
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
$set = $this->factory->translation_set->create_with_project_and_locale();
$glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
$glossary_entry = array(
'term' => 'GlotPress WP-Team',
'part_of_speech' => 'noun',
'translation' => 'Equipa-WP do GlotPress',
'glossary_id' => $glossary->id,
);
GP::$glossary_entry->create_and_select( $glossary_entry );
$orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
$this->assertEquals( $orig->singular_glossary_markup, $expected_result );
}
/**
* Expects matching the 3 words term [admin color scheme] instead of the 2 words term [color scheme] or single word term [admin].
*/
function test_map_glossary_entries_to_translation_originals_with_word_count_priority() {
$test_string = 'Please set your admin color scheme.';
$orig = '';
$expected_result = 'Please set your admin color scheme.';
$entry = new Translation_Entry( array( 'singular' => $test_string, ) );
$set = $this->factory->translation_set->create_with_project_and_locale();
$glossary = GP::$glossary->create_and_select( array( 'translation_set_id' => $set->id ) );
$glossary_entries = array(
array(
'term' => 'admin',
'part_of_speech' => 'noun',
'translation' => 'administrador',
'glossary_id' => $glossary->id,
),
array(
'term' => 'color scheme',
'part_of_speech' => 'noun',
'translation' => 'paleta de cores',
'glossary_id' => $glossary->id,
),
array(
'term' => 'admin color scheme',
'part_of_speech' => 'noun',
'translation' => 'paleta de cores do administrador',
'glossary_id' => $glossary->id,
),
);
foreach ( $glossary_entries as $glossary_entry ) {
GP::$glossary_entry->create_and_select( $glossary_entry );
}
$orig = map_glossary_entries_to_translation_originals( $entry, $glossary );
$this->assertEquals( $orig->singular_glossary_markup, $expected_result );
}
}