w = new GP_Builtin_Translation_Warnings(); $this->l = $this->factory->locale->create(); $this->longer_than_20 = 'The little boy hid behind the counter and then came the wizard of all green wizards!'; $this->shorter_than_5 = 'Boom'; } function _assertWarning( $assert, $warning, $original, $translation, $locale = null ) { if ( is_null( $locale ) ) { $locale = $this->l; } $method = "warning_$warning"; $this->$assert( true, $this->w->$method( $original, $translation, $locale ) ); } function assertHasWarnings( $warning, $original, $translation, $locale = null ) { $this->_assertWarning( 'assertNotSame', $warning, $original, $translation, $locale ); } function assertNoWarnings( $warning, $original, $translation, $locale = null ) { $this->_assertWarning( 'assertSame', $warning, $original, $translation, $locale ); } function assertHasWarningsAndContainsOutput( $warning, $original, $translation, $output_expected, $locale = null ) { $this->assertHasWarnings( $warning, $original, $translation, $locale ); if ( is_null( $locale ) ) { $locale = $this->l; } $method = "warning_$warning"; $this->assertStringContainsString( $output_expected, $this->w->$method( $original, $translation, $locale ) ); } function assertContainsOutput( $singular, $plural, $translations, $output_expected, $locale = null ) { if ( is_null( $locale ) ) { $locale = $this->l; } $this->assertEquals( $output_expected, $this->tw->check( $singular, $plural, $translations, $locale ) ); } function test_length() { $this->assertNoWarnings( 'length', $this->longer_than_20, $this->longer_than_20 ); $this->assertNoWarnings( 'length', 'number_format_', '' ); $this->assertHasWarningsAndContainsOutput( 'length', $this->longer_than_20, $this->shorter_than_5, 'Lengths of source and translation differ too much.' ); } function test_length_exclude() { $w_without_locale = new GP_Builtin_Translation_Warnings(); $w_without_locale->length_exclude_languages = array( $this->l->slug ); $this->assertSame( true, $w_without_locale->warning_length( $this->longer_than_20, $this->longer_than_20, $this->l ) ); $this->assertSame( true, $w_without_locale->warning_length( $this->longer_than_20, $this->shorter_than_5, $this->l ) ); } function test_tags() { $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); $this->assertNoWarnings( 'tags', '

WHO was founded in 1948.

', '

LaOMS se fundó en 1948.

' ); $this->assertNoWarnings( 'tags', '', '' ); $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); $this->assertNoWarnings( 'tags', 'Example URL', 'URL de jemplo' ); $this->l->slug = 'ja'; $this->assertNoWarnings( 'tags', 'Text 1, Italic text, Text 2, Emphasized text, Text 3', 'テキスト1、イタリック体、テキスト2、エンファシス体、テキスト3', $this->l ); $this->assertNoWarnings( 'tags', 'Incorrect link', 'Incorrect link' ); $this->assertNoWarnings( 'tags', ' Text 1 Example plugin Text 2Log in Text 3 Example alt text', ' Texto 1 Plugin de ejemplo Texto 2Acceder Texto 3 Texto alternativo de ejemplo' ); $this->assertNoWarnings( 'tags', 'WordPress in the Wikipedia', 'WordPress en la Wikipedia' ); $this->assertNoWarnings( 'tags', ' Text 1 Log in Text 2 Matt\'s Gravatar ', ' Texto 1 Acceder Texto 2 Gravatar de Matt ' ); $this->assertHasWarningsAndContainsOutput( 'tags', '

Paragraph

', '

Párrafo', 'Missing tags from translation. Expected:

' ); $this->assertHasWarningsAndContainsOutput( 'tags', 'Paragraph

', '

Párrafo

', 'Too many tags in translation. Found:

' ); $this->assertHasWarningsAndContainsOutput( 'tags', '

Title

Text 1


Text 2', '

Título

Texto 1
Texto 2', 'Missing tags from translation. Expected:

' ); $this->assertHasWarningsAndContainsOutput( 'tags', '

Title

Text 1


Text 2', '

Título

Texto 1


Texto 2', 'Too many tags in translation. Found:

' ); $this->assertHasWarningsAndContainsOutput( 'tags', 'Baba', 'Баба', 'The translation contains the following unexpected links: javascript:%s' ); $this->assertHasWarningsAndContainsOutput( 'tags', 'Baba', 'Баба', 'The translation appears to be missing the following links: javascript:%s' ); $this->assertHasWarningsAndContainsOutput( 'tags', 'Example URL', 'Ejemplo', "The translation appears to be missing the following URLs: https://www.example.org\nThe translation contains the following unexpected URLs: https://www.example.com" ); $this->assertHasWarningsAndContainsOutput( 'tags', 'Baba', 'Баба', 'Expected , got .' ); $this->assertHasWarningsAndContainsOutput( 'tags', '

Baba

', '

Баба

', 'The translation contains incorrect HTML tags: Unexpected end tag : p' ); $this->assertHasWarningsAndContainsOutput( 'tags', '

Hello

Peter

', '

Hola

Pedro

', 'The translation contains incorrect HTML tags: Unexpected end tag : h2' ); $this->assertHasWarningsAndContainsOutput( 'tags', 'WordPress en la Wikipedia', 'WordPress in the Wikipedia', "The translation appears to be missing the following URLs: https://es.wikipedia.org/wiki/WordPress#/media/File:WordPress_logo.svg\nThe translation contains the following unexpected URLs: https://en.wikipedia.org/wiki/WordPress#/media/File:WordPress_logo.svg" ); $this->l->slug = 'ja'; $this->assertHasWarningsAndContainsOutput( 'tags', 'Text 1, Italic text, Text 2, Emphasized text, Text 3', 'テキスト1、イタリック体、テキスト2、エンファシス体、テキスト3', 'The translation contains incorrect HTML tags: Unexpected end tag : b', $this->l ); } function test_add_all() { $warnings = $this->getMockBuilder( 'GP_Translation_Warnings' )->getMock(); // we check for the number of warnings, because PHPUnit doesn't allow // us to check if each argument is a callable $warnings->expects( $this->exactly( 10 ) )->method( 'add' )->will( $this->returnValue( true ) ); $this->w->add_all( $warnings ); } function test_placeholders() { $this->assertNoWarnings( 'placeholders', '%s baba', '%s баба' ); $this->assertNoWarnings( 'placeholders', '%s baba', 'баба %s' ); $this->assertNoWarnings( 'placeholders', '%s baba', 'баба %s' ); $this->assertNoWarnings( 'placeholders', '%1$s baba %2$s dyado', '%1$sбабадядо%2$s' ); $this->assertNoWarnings( 'placeholders', '% baba', 'баба' ); $this->assertNoWarnings( 'placeholders', '% baba', '% баба' ); $this->assertNoWarnings( 'placeholders', '%1$s baba', '%1$s баба' ); $this->assertNoWarnings( 'placeholders', '%sHome%s', '%sНачало%s' ); $this->assertNoWarnings( 'placeholders', 'This string has %stwo variables%s.', 'Deze string heeft %stwee variabelen%s.' ); $this->assertNoWarnings( 'placeholders', '%% baba', '%% баба' ); $this->assertNoWarnings( 'placeholders', '%s%% baba', '%s%% баба' ); $this->assertNoWarnings( 'placeholders', '%1$d baba %2$@', '%2$@ баба %1$d' ); $this->assertNoWarnings( 'placeholders', '%1$.4f baba', '%1$.4f баба' ); $this->assertNoWarnings( 'placeholders', '%2$.2fMB baba', '%2$.2fMB баба' ); $this->assertNoWarnings( 'placeholders', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$.2f baba', '%1$.f баба', 'Missing %1$.2f placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$.f baba', '%1$.4f баба', 'Extra %1$.4f placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%s baba', 'баба', 'Missing %s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%s baba', '% баба', 'Missing %s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$s baba', 'баба', 'Missing %1$s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%% baba', '% баба', 'Missing %% placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%s baba', '%%s баба', 'Missing %s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$s baba', '%%1$s баба', 'Missing %1$s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', 'баба', '%s baba', 'Extra %s placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$d baba %2$@', '%1$d baba', 'Missing %2$@ placeholder in translation.' ); $this->assertHasWarningsAndContainsOutput( 'placeholders', '%1$d baba', '%1$d baba %2$@', 'Extra %2$@ placeholder in translation.' ); } function test_should_begin_end_on_newline() { $this->assertHasWarningsAndContainsOutput( 'should_begin_on_newline', "\nbaba", 'baba', 'Original and translation should both begin on newline.' ); $this->assertHasWarningsAndContainsOutput( 'should_not_begin_on_newline', 'baba', "\nbaba", 'Translation should not begin on newline.' ); $this->assertHasWarningsAndContainsOutput( 'should_end_on_newline', "baba\n", 'baba', 'Original and translation should both end on newline.' ); $this->assertHasWarningsAndContainsOutput( 'should_not_end_on_newline', 'baba', "baba\n", 'Translation should not end on newline.' ); $this->assertNoWarnings( 'should_begin_on_newline', 'baba', 'baba' ); $this->assertNoWarnings( 'should_not_begin_on_newline', 'baba', 'baba' ); $this->assertNoWarnings( 'should_end_on_newline', 'baba', 'baba' ); $this->assertNoWarnings( 'should_not_end_on_newline', 'baba', 'baba' ); $this->assertNoWarnings( 'should_begin_on_newline', "baba\n", "baba\n" ); $this->assertNoWarnings( 'should_not_begin_on_newline', "baba\n", "baba\n" ); $this->assertNoWarnings( 'should_end_on_newline', "baba\n", "baba\n" ); $this->assertNoWarnings( 'should_not_end_on_newline', "baba\n", "baba\n" ); $this->assertNoWarnings( 'should_begin_on_newline', "\nbaba", "\nbaba" ); $this->assertNoWarnings( 'should_not_begin_on_newline', "\nbaba", "\nbaba" ); $this->assertNoWarnings( 'should_end_on_newline', "\nbaba", "\nbaba" ); $this->assertNoWarnings( 'should_not_end_on_newline', "\nbaba", "\nbaba" ); } function test_placeholders_using_check() { $w = new GP_Translation_Warnings(); $builtin = new GP_Builtin_Translation_Warnings(); $w->add( 'placeholder', array( $builtin, 'warning_placeholders' ) ); $fr = new GP_Locale( array( 'nplurals' => 2, 'plural_expression' => 'n > 1', ) ); $this->assertEquals( null, $w->check( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation %2$s' ), $fr ) ); $this->assertEquals( null, $w->check( 'original %1$s', 'original %2$s', array( null ), $fr ) ); $this->assertEquals( null, $w->check( 'original', 'original %s', array( 'translation', 'translation %s' ), $fr ) ); $this->assertEquals( array( 1 => array( 'placeholder' => 'Missing %2$s placeholder in translation.' ) ), $w->check( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation' ), $fr ) ); $this->assertEquals( array( 0 => array( 'placeholder' => 'Missing %1$s placeholder in translation.' ) ), $w->check( 'original %1$s', 'original %2$s', array( 'translation', 'translation %2$s' ), $fr ) ); $de = new GP_Locale( array( 'nplurals' => 2, 'plural_expression' => 'n != 1', ) ); $this->assertEquals( null, $w->check( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation %2$s' ), $de ) ); $this->assertEquals( null, $w->check( 'original', 'original %s', array( 'translation', 'translation %s' ), $de ) ); $ja = new GP_Locale( array( 'nplurals' => 1, 'plural_expression' => '0', ) ); $this->assertEquals( null, $w->check( 'original %1$s', 'original %2$s', array( 'translation %2$s' ), $ja ) ); $this->assertEquals( null, $w->check( 'original', 'original %s', array( 'translation %s' ), $ja ) ); $this->assertEquals( array( 0 => array( 'placeholder' => 'Missing %2$s placeholder in translation.' ) ), $w->check( 'original %1$s', 'original %2$s', array( 'translation' ), $ja ) ); $ru = new GP_Locale( array( 'nplurals' => 3, 'plural_expression' => '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)', ) ); $this->assertEquals( null, $w->check( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation %2$s', 'translation 2 %2$s' ), $ru ) ); $this->assertEquals( null, $w->check( 'original', 'original %s', array( 'translation', 'translation 2 %s', 'translation 3 %s' ), $ru ) ); $this->assertEquals( array( 1 => array( 'placeholder' => 'Missing %2$s placeholder in translation.' ) ), $w->check( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation 2', 'translation 3 %2$s' ), $ru ) ); $this->assertEquals( array( 2 => array( 'placeholder' => 'Missing %s placeholder in translation.' ) ), $w->check( 'original', 'original %s', array( 'translation', 'translation 2 %s', 'translation 3' ), $ru ) ); $this->assertEquals( array( 1 => array( 'placeholder' => 'Missing %s placeholder in translation.' ), 2 => array( 'placeholder' => 'Missing %s placeholder in translation.' ), ), $w->check( 'original', 'original %s', array( 'translation', 'translation 2', 'translation 3' ), $ru ) ); } function test_mismatching_urls() { $this->assertNoWarnings( 'mismatching_urls', 'https://www.example', 'https://www.example' ); $this->assertNoWarnings( 'mismatching_urls', 'http://www.example', 'http://www.example' ); $this->assertNoWarnings( 'mismatching_urls', '//www.example', '//www.example' ); $this->assertNoWarnings( 'mismatching_urls', '"//www.example"', '"//www.example.com"' ); $this->assertNoWarnings( 'mismatching_urls', "'//www.example'", "'//www.example.com'" ); $this->assertNoWarnings( 'mismatching_urls', '// www.example', '// www.example.comte ' ); $this->assertNoWarnings( 'mismatching_urls', 'http://127.0.0.1', 'https://127.0.0.1' ); $this->assertNoWarnings( 'mismatching_urls', 'https://127.0.0.1', 'http://127.0.0.1' ); $this->assertNoWarnings( 'mismatching_urls', 'https://www.example.com', 'https://www.example.com/' ); $this->assertNoWarnings( 'mismatching_urls', 'https://www.example.com/', 'https://www.example.com' ); $this->assertNoWarnings( 'mismatching_urls', 'http://www.example.com', 'https://www.example.com/' ); $this->assertNoWarnings( 'mismatching_urls', 'http://www.example.com/', 'https://www.example.com' ); $this->assertNoWarnings( 'mismatching_urls', 'http://wordpress.org/plugins/example-plugin/', 'https://wordpress.org/plugins/example-plugin' ); $this->assertNoWarnings( 'mismatching_urls', 'https://wordpress.org/plugins/example-plugin', 'http://wordpress.org/plugins/example-plugin/' ); $this->assertNoWarnings( 'mismatching_urls', 'http://www.example.com/wp-content/uploads/2020/12/logo.png', 'https://www.example.com/wp-content/uploads/2020/12/logo.png' ); $this->assertNoWarnings( 'mismatching_urls', 'Text1 https://www.example.com Text2 https://www.example.org Text3', 'Texto1 https://www.example.com Texto2 https://www.example.org Texto3' ); $this->assertNoWarnings( 'mismatching_urls', 'Text1 https://www.example.com Text2 https://www.example.org Text3', ' Texto3 https://www.example.org Texto2 https://www.example.com Texto1 ' ); $this->assertNoWarnings( 'mismatching_urls', 'Text1 https://www.example.com Text2 https://www.example.org Text3', ' https://www.example.org Texto1 Texto3 https://www.example.com Texto2 ' ); $this->assertNoWarnings( 'mismatching_urls', 'Text1 https://www.example.com Text2 https://www.example.org Text3', ' https://www.example.org https://www.example.com ' ); $this->assertNoWarnings( 'mismatching_urls', 'https://wordpress.org/plugins/example-plugin/', 'https://es.wordpress.org/plugins/example-plugin/' ); $this->assertNoWarnings( 'mismatching_urls', 'https://wordpress.com/log-in/', 'https://es.wordpress.com/log-in/' ); $this->assertNoWarnings( 'mismatching_urls', 'https://en.gravatar.com/matt', 'https://es.gravatar.com/matt' ); $this->assertNoWarnings( 'mismatching_urls', 'https://en.wikipedia.org/wiki/WordPress', 'https://es.wikipedia.org/wiki/WordPress' ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'HTTPS://WWW.EXAMPLE', 'https://www.example', "The translation appears to be missing the following URLs: HTTPS://WWW.EXAMPLE\nThe translation contains the following unexpected URLs: https://www.example" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.example', 'HTTPS://WWW.EXAMPLE', "The translation appears to be missing the following URLs: https://www.example\nThe translation contains the following unexpected URLs: HTTPS://WWW.EXAMPLE" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'HtTpS://WwW.eXaMpLe', 'https://www.example', "The translation appears to be missing the following URLs: HtTpS://WwW.eXaMpLe\nThe translation contains the following unexpected URLs: https://www.example" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.example.com', 'https://www.example.org', "The translation appears to be missing the following URLs: https://www.example.com\nThe translation contains the following unexpected URLs: https://www.example.org" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', '//www.example.com', 'http://www.example.org', "The translation appears to be missing the following URLs: //www.example.com\nThe translation contains the following unexpected URLs: http://www.example.org" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', '//www.example.com', 'https://www.example.org', "The translation appears to be missing the following URLs: //www.example.com\nThe translation contains the following unexpected URLs: https://www.example.org" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'http://www.example.com', '//www.example.org', "The translation appears to be missing the following URLs: http://www.example.com\nThe translation contains the following unexpected URLs: //www.example.org" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.example.com', '//www.example.org', "The translation appears to be missing the following URLs: https://www.example.com\nThe translation contains the following unexpected URLs: //www.example.org" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.exañple.com', 'https://www.example.com', "The translation appears to be missing the following URLs: https://www.exañple.com\nThe translation contains the following unexpected URLs: https://www.example.com" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.example.com', 'https://www.exañple.com', "The translation appears to be missing the following URLs: https://www.example.com\nThe translation contains the following unexpected URLs: https://www.exañple.com" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.wordpress.org/plugins/example-plugin/', 'https://es.wordpress.org/plugins/example-plugin/', "The translation appears to be missing the following URLs: https://www.wordpress.org/plugins/example-plugin/\nThe translation contains the following unexpected URLs: https://es.wordpress.org/plugins/example-plugin/" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://www.wordpress.com/log-in/', 'https://es.wordpress.com/log-in/', "The translation appears to be missing the following URLs: https://www.wordpress.com/log-in/\nThe translation contains the following unexpected URLs: https://es.wordpress.com/log-in/" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://es.gravatar.com/matt', 'https://en.gravatar.com/matt', "The translation appears to be missing the following URLs: https://es.gravatar.com/matt\nThe translation contains the following unexpected URLs: https://en.gravatar.com/matt" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'https://es.wikipedia.org/wiki/WordPress', 'https://en.wikipedia.org/wiki/WordPress', "The translation appears to be missing the following URLs: https://es.wikipedia.org/wiki/WordPress\nThe translation contains the following unexpected URLs: https://en.wikipedia.org/wiki/WordPress" ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'Text1 https://www.example.com Text2', 'Texto1 Texto2', 'The translation appears to be missing the following URLs: https://www.example.com' ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'Text1 Text2', 'Texto1 https://www.example.com Texto2', 'The translation contains the following unexpected URLs: https://www.example.com' ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'Text1 https://www.example.com Text2 https://www.example.org', 'Texto1 https://www.example.com Texto2', 'The translation appears to be missing the following URLs: https://www.example.org' ); $this->assertHasWarningsAndContainsOutput( 'mismatching_urls', 'Text1 https://www.example.com Text2', 'Texto1 https://www.example.com Texto2 https://www.example.org', 'The translation contains the following unexpected URLs: https://www.example.org' ); } function test_unexpected_sprintf_token() { $this->assertNoWarnings( 'unexpected_sprintf_token', '100 percent', '100%' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '100 percent', '100%' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '100 percent', '100%%' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '100 percent', '100%%' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '%1$.2f baba', '%1$.2f баба' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '%1$.2f baba', '%1$.3f баба' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '%2$.2fMB baba', '%2$.2fMB баба' ); $this->assertNoWarnings( 'unexpected_sprintf_token', '%2$.3fMB baba', '%2$.2fMB баба' ); $this->assertNoWarnings( 'unexpected_sprintf_token', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s' ); $this->assertNoWarnings( 'unexpected_sprintf_token', 'The %s contains %d items', 'El %s contiene %d elementos' ); $this->assertNoWarnings( 'unexpected_sprintf_token', 'The %2$s contains %1$d items. That\'s a nice %2$s full of %1$d items.', 'El %2$s contiene %1$d elementos. Es un bonito %2$s lleno de %1$d elementos.' ); $this->assertNoWarnings( 'unexpected_sprintf_token', 'The application password %friendly_name%.', 'La contraseña de aplicación %friendly_name%.' ); $this->assertHasWarningsAndContainsOutput( 'unexpected_sprintf_token', '100 percent', '100%', 'The translation contains the following unexpected placeholders: ">100%<' ); $this->assertHasWarningsAndContainsOutput( 'unexpected_sprintf_token', '100 percent', ' 95% of 100%%', 'The translation contains the following unexpected placeholders: 95% ' ); $this->assertHasWarningsAndContainsOutput( 'unexpected_sprintf_token', '100 percent', '100%% of 95% ', 'The translation contains the following unexpected placeholders: 95% ' ); $this->assertHasWarningsAndContainsOutput( 'unexpected_sprintf_token', '100 percent', '100% of 95% ', 'The translation contains the following unexpected placeholders: ">100%<, 95% ' ); } function test_named_placeholders() { $this->assertNoWarnings( 'named_placeholders', '###NEW_EMAIL###', '###NEW_EMAIL###' ); $this->assertNoWarnings( 'named_placeholders', '###new-email###', '###new-email###' ); $this->assertNoWarnings( 'named_placeholders', 'Hi ###USERNAME###, we sent to ###EMAIL### your new password from "###SITENAME###" (###SITEURL###)', 'Hola ###USERNAME###, te enviamos desde «###SITENAME###» (###SITEURL###) tu nueva contraseña a ###EMAIL###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', '###NEW_EMAIL###', '##NEW_EMAIL##', 'The translation appears to be missing the following placeholders: ###NEW_EMAIL###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', '##NEW_EMAIL###', '###NEW_EMAIL###', 'The translation contains the following unexpected placeholders: ###NEW_EMAIL###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', '###NEW_EMAIL###', '###NUEVO_CORREO###', "The translation appears to be missing the following placeholders: ###NEW_EMAIL###\nThe translation contains the following unexpected placeholders: ###NUEVO_CORREO###" ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', 'Hi ###USERNAME###, we sent to ###EMAIL### your new password from "###SITENAME###" (###SITEURL###)', 'Hola ##USERNAME##, te enviamos desde «###SITENAME###» (###SITEURL###) tu nueva contraseña a ###EMAIL###', 'The translation appears to be missing the following placeholders: ###USERNAME###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', 'Hi ###USERNAME###, we sent to ###EMAIL### your new password from "###SITENAME###" (###SITEURL###)', 'Hola ###USERNAME###, te enviamos desde «SITENAME» (###SITEURL###) tu nueva contraseña a ###EMAIL###', 'The translation appears to be missing the following placeholders: ###SITENAME###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', 'Hi ###USERNAME###, we sent to ###EMAIL### your new password from "###SITENAME###" (###SITEURL###)', 'Hola ###USERNAME###, te enviamos desde «###SITENAME###» (###SITEURL###) tu nueva contraseña a EMAIL#', 'The translation appears to be missing the following placeholders: ###EMAIL###' ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', '###NEW_EMAIL###', '###new_email###', "The translation appears to be missing the following placeholders: ###NEW_EMAIL###\nThe translation contains the following unexpected placeholders: ###new_email###" ); $this->assertHasWarningsAndContainsOutput( 'named_placeholders', '###new_email###', '###NEW_EMAIL###', "The translation appears to be missing the following placeholders: ###new_email###\nThe translation contains the following unexpected placeholders: ###NEW_EMAIL###" ); } public function test_chained_warnings() { $this->tw = new GP_Translation_Warnings(); $this->w = new GP_Builtin_Translation_Warnings(); $this->w->add_all( $this->tw ); $this->assertContainsOutput( 'original %1$s', 'original %2$s', array( 'translation %1$s', 'translation %2$s' ), null ); $this->assertContainsOutput( 'original %1$s', null, array( 'translation %1$s' ), array( array( 'tags' => 'Too many tags in translation. Found: ' ), ) ); $this->assertContainsOutput( 'original %1$s', null, array( 'translation s' ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'placeholders' => 'Missing %1$s placeholder in translation.', ), ) ); $this->assertContainsOutput( 'original', null, array( 'translation %1$s' ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'placeholders' => 'Extra %1$s placeholder in translation.', ), ) ); $this->assertContainsOutput( 'original s', null, array( "\ntranslation s" ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', ), ) ); $this->assertContainsOutput( 'original s', null, array( "translation s\n" ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'should_not_end_on_newline' => 'Translation should not end on newline.', ), ) ); $this->assertContainsOutput( "\noriginal s", null, array( 'translation s' ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'should_begin_on_newline' => 'Original and translation should both begin on newline.', ), ) ); $this->assertContainsOutput( "original s\n", null, array( 'translation s' ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'should_end_on_newline' => 'Original and translation should both end on newline.', ), ) ); $this->assertContainsOutput( 'original', null, array( "translation very very very very long \n" ), array( array( 'tags' => 'Too many tags in translation. Found: ', 'length' => 'Lengths of source and translation differ too much.', 'should_not_end_on_newline' => 'Translation should not end on newline.', ), ) ); $this->assertContainsOutput( '

original

', null, array( "
translation \n" ), array( array( 'tags' => 'Missing tags from translation. Expected:

', 'should_not_end_on_newline' => 'Translation should not end on newline.', ), ) ); $this->assertContainsOutput( '

original

', null, array( "

translation

\n" ), array( array( 'tags' => 'The translation contains incorrect HTML tags: Unexpected end tag : p', 'should_not_end_on_newline' => 'Translation should not end on newline.', ), ) ); $this->assertContainsOutput( '

original

', null, array( "\ntranslation \n" ), array( array( 'tags' => "Expected

, got .\nExpected

, got .", 'should_not_end_on_newline' => 'Translation should not end on newline.', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', ), ) ); $this->assertContainsOutput( '

https://example.com

', null, array( "\nhttps://example.org \n" ), array( array( 'tags' => "Expected

, got .\nExpected

, got .", 'should_not_end_on_newline' => 'Translation should not end on newline.', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', 'mismatching_urls' => "The translation appears to be missing the following URLs: https://example.com\nThe translation contains the following unexpected URLs: https://example.org", ), ) ); $this->assertContainsOutput( 'https://example.com', null, array( "\nhttps://example.org \n" ), array( array( 'tags' => "The translation appears to be missing the following URLs: https://example.com\nThe translation contains the following unexpected URLs: https://example.org", 'should_not_end_on_newline' => 'Translation should not end on newline.', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', 'mismatching_urls' => "The translation appears to be missing the following URLs: https://example.com\nThe translation contains the following unexpected URLs: https://example.org", ), ) ); $this->assertContainsOutput( 'https://example.com', null, array( "\nhttps://example.org \n" ), array( array( 'tags' => 'The translation contains the following unexpected links: javascript%s', 'should_not_end_on_newline' => 'Translation should not end on newline.', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', 'mismatching_urls' => "The translation appears to be missing the following URLs: https://example.com\nThe translation contains the following unexpected URLs: https://example.org", ), ) ); $this->assertContainsOutput( '

100 percent

', null, array( "\n100%%\n" ), array( array( 'tags' => 'Missing tags from translation. Expected:

', 'should_not_end_on_newline' => 'Translation should not end on newline.', 'should_not_begin_on_newline' => 'Translation should not begin on newline.', 'placeholders' => 'Extra %% placeholder in translation.', ), ) ); } }