[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 class GP_Test_Translations extends GP_UnitTestCase { 4 5 function test_add_entry() { 6 $entry = new Translation_Entry(array('singular' => 'baba',)); 7 $entry2 = new Translation_Entry(array('singular' => 'dyado',)); 8 $empty = new Translation_Entry(); 9 $po = new Translations(); 10 $po->add_entry($entry); 11 $this->assertEquals(array($entry->key() => $entry), $po->entries); 12 // add the same entry more than once 13 // we do not need to test proper key generation here, see test_key() 14 $po->add_entry($entry); 15 $po->add_entry($entry); 16 $this->assertEquals(array($entry->key() => $entry), $po->entries); 17 $po->add_entry($entry2); 18 $this->assertEquals(array($entry->key() => $entry, $entry2->key() => $entry2), $po->entries); 19 // add empty entry 20 $this->assertEquals(false, $po->add_entry($empty)); 21 $this->assertEquals(array($entry->key() => $entry, $entry2->key() => $entry2), $po->entries); 22 23 // give add_entry() the arguments and let it create the entry itself 24 $po = new Translations(); 25 $po->add_entry(array('singular' => 'baba',)); 26 $entries= array_values($po->entries); 27 $this->assertEquals($entry->key(), $entries[0]->key()); 28 } 29 30 function test_translate() { 31 $entry1 = new Translation_Entry(array('singular' => 'baba', 'translations' => array('babax'))); 32 $entry2 = new Translation_Entry(array('singular' => 'baba', 'translations' => array('babay'), 'context' => 'x')); 33 $domain = new Translations(); 34 $domain->add_entry($entry1); 35 $domain->add_entry($entry2); 36 $this->assertEquals('babax', $domain->translate('baba')); 37 $this->assertEquals('babay', $domain->translate('baba', 'x')); 38 $this->assertEquals('baba', $domain->translate('baba', 'y')); 39 $this->assertEquals('babaz', $domain->translate('babaz')); 40 } 41 42 function test_translate_plural() { 43 $entry_incomplete = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('babax'))); 44 $entry_toomany = new Translation_Entry(array('singular' => 'wink', 'plural' => 'winks', 'translations' => array('winki', 'winka', 'winko'))); 45 $entry_2 = new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados', 'translations' => array('dyadox', 'dyadoy'))); 46 $domain = new Translations(); 47 $domain->add_entry($entry_incomplete); 48 $domain->add_entry($entry_toomany); 49 $domain->add_entry($entry_2); 50 $this->assertEquals('other', $domain->translate_plural('other', 'others', 1)); 51 $this->assertEquals('others', $domain->translate_plural('other', 'others', 111)); 52 // too few translations + cont logic 53 $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 2)); 54 $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 0)); 55 $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', -1)); 56 $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 999)); 57 // proper 58 $this->assertEquals('dyadox', $domain->translate_plural('dyado', 'dyados', 1)); 59 $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 0)); 60 $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 18881)); 61 $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', -18881)); 62 } 63 64 function test_digit_and_merge() { 65 $entry_digit_1 = new Translation_Entry(array('singular' => 1, 'translations' => array('1'))); 66 $entry_digit_2 = new Translation_Entry(array('singular' => 2, 'translations' => array('2'))); 67 $domain = new Translations(); 68 $domain->add_entry($entry_digit_1); 69 $domain->add_entry($entry_digit_2); 70 $dummy_translation = new Translations; 71 $this->assertEquals( '1', $domain->translate( '1' ) ); 72 $domain->merge_with( $dummy_translation ); 73 $this->assertEquals( '1', $domain->translate( '1' ) ); 74 } 75 76 function test_if_translation_has_been_updated_since_timestamp() { 77 $set = $this->factory->translation_set->create_with_project_and_locale(); 78 $original = $this->factory->original->create( array( 'project_id' => $set->project_id ) ); 79 $this->factory->translation->create( array( 80 'original_id' => $original->id, 81 'translation_set_id' => $set->id, 82 'status' => 'current', 83 ) ); 84 85 $this->assertTrue( gp_has_translation_been_updated( $set ) ); 86 87 $timestamp_yesterday = strtotime( '-1 day' ); 88 $timestamp_tomorrow = strtotime( '+1 day' ); 89 90 $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate( 'D, d M Y H:i:s', $timestamp_yesterday ) . 'GMT'; 91 $this->assertTrue( gp_has_translation_been_updated( $set ) ); 92 93 $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate( 'D, d M Y H:i:s', $timestamp_tomorrow ) . 'GMT'; 94 $this->assertFalse( gp_has_translation_been_updated( $set ) ); 95 96 unset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 97 $this->assertTrue( gp_has_translation_been_updated( $set, $timestamp_yesterday ) ); 98 $this->assertFalse( gp_has_translation_been_updated( $set, $timestamp_tomorrow ) ); 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 26 01:01:15 2024 | Cross-referenced by PHPXref 0.7.1 |