| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 require_once ('init.php'); 3 4 class GP_Test_Builtin_Translation_Warnings extends GP_UnitTestCase { 5 6 function setUp() { 7 parent::setUp(); 8 $this->w = new GP_Builtin_Translation_Warnings; 9 $this->l = $this->factory->locale->create(); 10 $this->longer_than_20 = 'The little boy hid behind the counter and then came the wizard of all green wizards!'; 11 $this->shorter_than_5 = 'Boom'; 12 } 13 14 function _assertWarning( $assert, $warning, $original, $translation, $locale = null ) { 15 if ( is_null( $locale ) ) $locale = $this->l; 16 $method = "warning_$warning"; 17 $this->$assert( true, $this->w->$method( $original, $translation, $locale ) ); 18 } 19 20 function assertHasWarnings( $warning, $original, $translation, $locale = null ) { 21 $this->_assertWarning( 'assertNotSame', $warning, $original, $translation, $locale ); 22 } 23 24 function assertNoWarnings( $warning, $original, $translation, $locale = null ) { 25 $this->_assertWarning( 'assertSame', $warning, $original, $translation, $locale ); 26 } 27 28 29 function test_length() { 30 $this->assertNoWarnings( 'length', $this->longer_than_20, $this->longer_than_20 ); 31 $this->assertHasWarnings( 'length', $this->longer_than_20, $this->shorter_than_5 ); 32 } 33 34 function test_length_exclude() { 35 $w_without_locale = new GP_Builtin_Translation_Warnings; 36 $w_without_locale->length_exclude_languages = array( $this->l->slug ); 37 $this->assertSame( true, $w_without_locale->warning_length( $this->longer_than_20, $this->longer_than_20, $this->l ) ); 38 $this->assertSame( true, $w_without_locale->warning_length( $this->longer_than_20, $this->shorter_than_5, $this->l ) ); 39 } 40 41 function test_tags() { 42 $this->assertNoWarnings( 'tags', 'Baba', 'Баба' ); 43 $this->assertNoWarnings( 'tags', '<a href="%s">Baba</a>', '<a href="%s">Баба</a>' ); 44 $this->assertNoWarnings( 'tags', '<a href="%s" title="Blimp!">Baba</a>', '<a href="%s" title="Блимп!">Баба</a>' ); 45 $this->assertHasWarnings( 'tags', '<a href="%s" title="Blimp!">Baba</a>', '<a href="javascript:%s" title="Блимп!">Баба</a>' ); 46 $this->assertHasWarnings( 'tags', '<a href="%s" title="Blimp!">Baba</a>', '<a href="%s" x>Баба</a>' ); 47 $this->assertHasWarnings( 'tags', '<a href="%s" title="Blimp!">Baba</a>', '<a href="javascript:%s" title="Блимп!" target="_blank">Баба</a>' ); 48 $this->assertHasWarnings( 'tags', '<a>Baba</a>', '</a>Баба<a>' ); 49 } 50 51 function test_add_all() { 52 $warnings = $this->getMock( 'GP_Translation_Warnings' ); 53 // we check for the number of warnings, because PHPUnit doesn't allow 54 // us to check if each argument is a callable 55 $warnings->expects( $this->exactly( 4 ) )->method( 'add' )->will( $this->returnValue( true ) ); 56 $this->w->add_all( $warnings ); 57 } 58 59 function test_placeholders() { 60 $this->assertHasWarnings( 'placeholders', '%s baba', 'баба' ); 61 $this->assertHasWarnings( 'placeholders', '%s baba', '% баба' ); 62 $this->assertNoWarnings( 'placeholders', '%s baba', '%s баба' ); 63 $this->assertNoWarnings( 'placeholders', '%s baba', 'баба %s' ); 64 $this->assertNoWarnings( 'placeholders', '%s baba', 'баба %s' ); 65 $this->assertNoWarnings( 'placeholders', '%1$s baba %2$s dyado', '%1$sбабадядо%2$s' ); 66 $this->assertHasWarnings( 'placeholders', '% baba', 'баба' ); 67 $this->assertNoWarnings( 'placeholders', '% baba', '% баба' ); 68 $this->assertHasWarnings( 'placeholders', '%ququ baba', 'баба' ); 69 $this->assertNoWarnings( 'placeholders', '%ququ baba', '%ququ баба' ); 70 $this->assertHasWarnings( 'placeholders', '%1$s baba', 'баба' ); 71 $this->assertNoWarnings( 'placeholders', '%1$s baba', '%1$s баба' ); 72 $this->assertNoWarnings( 'placeholders', '%sHome%s', '%sНачало%s' ); 73 } 74 75 function test_both_begin_end_on_newlines() { 76 $this->assertHasWarnings( 'both_begin_end_on_newlines', "baba\n", "baba" ); 77 $this->assertHasWarnings( 'both_begin_end_on_newlines', "baba", "baba\n" ); 78 $this->assertNoWarnings( 'both_begin_end_on_newlines', "baba", "baba" ); 79 $this->assertNoWarnings( 'both_begin_end_on_newlines', "baba\n", "baba\n" ); 80 $this->assertHasWarnings( 'both_begin_end_on_newlines', "\nbaba", "baba" ); 81 $this->assertHasWarnings( 'both_begin_end_on_newlines', "baba", "\nbaba" ); 82 $this->assertNoWarnings( 'both_begin_end_on_newlines', "\nbaba", "\nbaba" ); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |