summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php
diff options
context:
space:
mode:
authorwei <>2006-01-06 05:32:33 +0000
committerwei <>2006-01-06 05:32:33 +0000
commit16660934cc48f357b1322bce7869158db2f7cb58 (patch)
treecd142f641e14c0338eb8847f00b572cb4f4603be /tests/UnitTests/framework/I18N/testMessageFormat_gettext.php
parented3e43d30524a76969fb7d42cb5e613c2e1a1d9a (diff)
Adding I18N unit test cases.
Diffstat (limited to 'tests/UnitTests/framework/I18N/testMessageFormat_gettext.php')
-rw-r--r--tests/UnitTests/framework/I18N/testMessageFormat_gettext.php176
1 files changed, 176 insertions, 0 deletions
diff --git a/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php b/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php
new file mode 100644
index 00000000..6fa00e80
--- /dev/null
+++ b/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php
@@ -0,0 +1,176 @@
+<?php
+
+Prado::using('System.I18N.core.MessageFormat');
+
+class testMessageFormat_gettext extends UnitTestCase
+{
+ protected $type = 'gettext';
+ protected $source;
+ protected $tmp;
+ protected $dir;
+
+ function testMessageFormat_gettext()
+ {
+ $this->UnitTestCase();
+ $this->dir = dirname(__FILE__);
+ $this->tmp = $this->dir.'/tmp/';
+ $this->source = $this->dir.'/messages';
+ }
+
+ function test1()
+ {
+ $source = MessageSource::factory($this->type, $this->source);
+ $source->setCulture('en_AU');
+ $source->setCache(new MessageCache($this->tmp));
+
+ $formatter = new MessageFormat($source);
+ $this->assertEqual($formatter->format('Hello'),'G\'day Mate!');
+
+ $this->assertEqual($formatter->format('Goodbye'), 'Goodbye');
+
+ $formatter->setUntranslatedPS(array('[T]','[/T]'));
+ $this->assertEqual($formatter->format('Hi'), '[T]Hi[/T]');
+
+ $source->getCache()->clear();
+ }
+
+ function testSaveUpdateDelete()
+ {
+ $MObackup = $this->dir.'/messages/messages.en_AU.mo.bak';
+ $MOfile = $this->dir.'/messages/messages.en_AU.mo';
+ $PObackup = $this->dir.'/messages/messages.en_AU.po.bak';
+ $POfile = $this->dir.'/messages/messages.en_AU.po';
+
+ //restore using the back file
+ copy($MObackup,$MOfile);
+ copy($PObackup,$POfile);
+
+ //test that the back file doesn't contain the 'Testing123' string.
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile));
+
+ $source = MessageSource::factory($this->type, $this->source);
+ $source->setCulture('en_AU');
+ $source->setCache(new MessageCache($this->tmp));
+
+ $formatter = new MessageFormat($source);
+
+ //add a untranslated string
+ $this->assertEqual($formatter->format('Testing123'), 'Testing123');
+
+ //save it
+ $this->assertTrue($formatter->getSource()->save());
+
+ //check the contents
+ //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertWantedPattern('/Testing123/',file_get_contents($POfile));
+
+ //testing for update.
+ $this->assertTrue($formatter->getSource()->update(
+ 'Testing123', '123Test', 'update comments'));
+
+ $this->assertWantedPattern('/123Test/',file_get_contents($MOfile));
+
+
+ //var_dump(htmlspecialchars($contents));
+
+ //now doing some delete
+ $this->assertFalse($formatter->getSource()->delete('Test123'));
+ $this->assertTrue($formatter->getSource()->delete('Testing123'));
+
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile));
+
+ //restore using the backup file.
+ copy($MObackup,$MOfile);
+ copy($PObackup,$POfile);
+
+ $source->getCache()->clear();
+ }
+
+ function testCatalogueList()
+ {
+ $source = MessageSource::factory($this->type, $this->source);
+ $result[] = array('messages',NULL);
+ $result[] = array('messages', 'en');
+ $result[] = array('messages','en_AU');
+ $result[] = array('tests',NULL);
+ $result[] = array('tests','en');
+ $result[] = array('tests','en_AU');
+
+ $this->assertEqual($result, $source->catalogues());
+ }
+
+ function testAltCatalogue()
+ {
+ $source = MessageSource::factory($this->type, $this->source);
+ $source->setCulture('en_AU');
+ $source->setCache(new MessageCache($this->tmp));
+
+ $formatter = new MessageFormat($source);
+ $formatter->Catalogue = 'tests';
+
+ //from a different catalogue
+ $this->assertEqual($formatter->format('Hello'), 'Howdy!');
+ $this->assertEqual($formatter->format('Welcome'), 'Ho Ho!');
+ $this->assertEqual($formatter->format('Goodbye'), 'Sayonara');
+
+ //switch to 'messages' catalogue
+ $this->assertEqual($formatter->format('Hello',null,'messages'),'G\'day Mate!');
+
+ $source->getCache()->clear();
+ }
+
+ function testDirectoryTypeSaveUpdateDelete()
+ {
+ $MObackup = $this->dir.'/messages/en_AU/tests.mo.bak';
+ $MOfile = $this->dir.'/messages/en_AU/tests.mo';
+ $PObackup = $this->dir.'/messages/en_AU/tests.po.bak';
+ $POfile = $this->dir.'/messages/en_AU/tests.po';
+
+ //restore using the back file
+ copy($MObackup,$MOfile);
+ copy($PObackup,$POfile);
+
+ //test that the back file doesn't contain the 'Testing123' string.
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile));
+
+ $source = MessageSource::factory($this->type, $this->source);
+ $source->setCulture('en_AU');
+ $source->setCache(new MessageCache($this->tmp));
+
+ $formatter = new MessageFormat($source);
+
+ //add a untranslated string, note, doesn't matter which catalogue
+ $this->assertEqual($formatter->format('Testing123'), 'Testing123');
+
+ //save it to the 'tests' catalgoue
+ $this->assertTrue($formatter->getSource()->save('tests'));
+
+ //check the contents
+ //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertWantedPattern('/Testing123/',file_get_contents($POfile));
+
+ //testing for update. Update it to the 'tests' catalogue
+ $this->assertTrue($formatter->getSource()->update(
+ 'Testing123', '123Test', 'update comments','tests'));
+
+ $this->assertWantedPattern('/123Test/',file_get_contents($MOfile));
+
+ //now doing some delete from the 'tests' catalogue
+ $this->assertFalse($formatter->getSource()->delete('Test123','tests'));
+ $this->assertTrue($formatter->getSource()->delete('Testing123','tests'));
+
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile));
+ $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile));
+
+ //restore using the backup file.
+ copy($MObackup,$MOfile);
+ copy($PObackup,$POfile);
+
+ $source->getCache()->clear();
+ }
+}
+
+?> \ No newline at end of file