cvs: pear /Translation2/tests admin_db_test.php admin_db_test_base.php admin_mdb2_test.php admin_mdb_test.php db_test.php db_test_base.php
mdb2_test.php mdb_test.php

From: Date: Tue, 29 Aug 2006 09:54:36 +0000
Subject: cvs: pear /Translation2/tests admin_db_test.php admin_db_test_base.php admin_mdb2_test.php admin_mdb_test.php db_test.php db_test_base.php
mdb2_test.php mdb_test.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-41903@lists.php.net to get a copy of this message
quipo Tue Aug 29 09:54:36 2006 UTC Added files: /pear/Translation2/tests admin_db_test_base.php db_test_base.php Modified files: /pear/Translation2/tests admin_db_test.php admin_mdb2_test.php admin_mdb_test.php db_test.php mdb2_test.php mdb_test.php Log: fixed MDB/MDB2 test runner

http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/admin_db_test.php?r1=1.6&r2=1.7&diff_format=u Index: pear/Translation2/tests/admin_db_test.php diff -u pear/Translation2/tests/admin_db_test.php:1.6 pear/Translation2/tests/admin_db_test.php:1.7 --- pear/Translation2/tests/admin_db_test.php:1.6 Tue Dec 7 15:34:23 2004 +++ pear/Translation2/tests/admin_db_test.php Tue Aug 29 09:54:36 2006 @@ -1,6 +1,8 @@ <?php -// $Id: admin_db_test.php,v 1.6 2004/12/07 15:34:23 quipo Exp $ +// $Id: admin_db_test.php,v 1.7 2006/08/29 09:54:36 quipo Exp $ +require_once 'simple_include.php'; +require_once 'translation2_admin_include.php'; require_once 'dbms.php'; class TestOfAdminContainerDB extends UnitTestCase { http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/admin_mdb2_test.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Translation2/tests/admin_mdb2_test.php diff -u pear/Translation2/tests/admin_mdb2_test.php:1.2 pear/Translation2/tests/admin_mdb2_test.php:1.3 --- pear/Translation2/tests/admin_mdb2_test.php:1.2 Thu Nov 18 20:34:07 2004 +++ pear/Translation2/tests/admin_mdb2_test.php Tue Aug 29 09:54:36 2006 @@ -1,7 +1,7 @@ <?php -// $Id: admin_mdb2_test.php,v 1.2 2004/11/18 20:34:07 quipo Exp $ +// $Id: admin_mdb2_test.php,v 1.3 2006/08/29 09:54:36 quipo Exp $ -require_once 'admin_db_test.php'; +require_once 'admin_db_test_base.php'; class TestOfAdminContainerMDB2 extends TestOfAdminContainerDB { function TestOfAdminContainerMDB2($name='Test of Admin Container MDB2') { @@ -12,4 +12,10 @@ $this->tr = Translation2_Admin::factory($driver, dbms::getDbInfo(), dbms::getParams()); } } + +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = &new TestOfAdminContainerMDB2(); + $test->run(new HtmlReporter()); +} ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/admin_mdb_test.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Translation2/tests/admin_mdb_test.php diff -u pear/Translation2/tests/admin_mdb_test.php:1.2 pear/Translation2/tests/admin_mdb_test.php:1.3 --- pear/Translation2/tests/admin_mdb_test.php:1.2 Thu Nov 18 20:34:07 2004 +++ pear/Translation2/tests/admin_mdb_test.php Tue Aug 29 09:54:36 2006 @@ -1,7 +1,7 @@ <?php -// $Id: admin_mdb_test.php,v 1.2 2004/11/18 20:34:07 quipo Exp $ +// $Id: admin_mdb_test.php,v 1.3 2006/08/29 09:54:36 quipo Exp $ -require_once 'admin_db_test.php'; +require_once 'admin_db_test_base.php'; class TestOfAdminContainerMDB extends TestOfAdminContainerDB { function TestOfAdminContainerMDB($name='Test of Admin Container MDB') { @@ -12,4 +12,10 @@ $this->tr = Translation2_Admin::factory($driver, dbms::getDbInfo(), dbms::getParams()); } } + +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = &new TestOfAdminContainerMDB(); + $test->run(new HtmlReporter()); +} ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/db_test.php?r1=1.8&r2=1.9&diff_format=u Index: pear/Translation2/tests/db_test.php diff -u pear/Translation2/tests/db_test.php:1.8 pear/Translation2/tests/db_test.php:1.9 --- pear/Translation2/tests/db_test.php:1.8 Tue Oct 4 21:23:19 2005 +++ pear/Translation2/tests/db_test.php Tue Aug 29 09:54:36 2006 @@ -1,295 +1,7 @@ <?php -// $Id: db_test.php,v 1.8 2005/10/04 21:23:19 quipo Exp $ +// $Id: db_test.php,v 1.9 2006/08/29 09:54:36 quipo Exp $ - -require_once 'simple_include.php'; -require_once 'translation2_include.php'; -require_once 'dbms.php'; -//require_once 'common_tests.php'; - -class TestOfContainerDB extends UnitTestCase { //TestOfTranslation2 { - var $tr; - function TestOfContainerDB($name='Test of Container DB') { - $this->UnitTestCase($name); - } - function setUp() { - $driver = 'DB'; - $this->tr = Translation2::factory($driver, dbms::getDbInfo(), dbms::getParams()); - } - function tearDown() { - unset($this->tr); - } - function testFactory() { - if (PEAR::isError($this->tr)) { - var_dump($this->tr->getUserInfo()); - var_dump($this->tr->getMessage()); - } - $this->assertTrue(!PEAR::isError($this->tr)); - } - function testGet() { - $this->assertEqual('gennaio', $this->tr->get('month_01', 'calendar', 'it')); - $this->assertEqual('january', $this->tr->get('month_01', 'calendar', 'en')); - $this->assertFalse(PEAR::isError($this->tr->setLang('en'))); //set default lang - $this->assertEqual('sunday', $this->tr->get('day_0', 'calendar')); - $this->assertEqual('monday', $this->tr->get('day_1', 'calendar')); - $this->tr->setPageID('calendar'); //set default lang AND default pageID - $this->assertEqual('sunday', $this->tr->get('day_0')); - $this->assertEqual('monday', $this->tr->get('day_1')); - } - function testGetRaw() { - $this->tr->setLang('it'); - $this->tr->setParams(array( - 'user' => 'Joe', - 'day' => '15', - 'month' => $this->tr->get('month_01', 'calendar'), - 'year' => '2004', - 'weekday' => $this->tr->get('day_5', 'calendar') - )); - $expected = 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)'; - $this->assertEqual($expected, $this->tr->getRaw('hello_user')); - - $this->tr =& $this->tr->getDecorator('SpecialChars'); - $this->assertEqual('venerdì', $this->tr->getRaw('day_5', 'calendar', 'it')); - } - function testGetPage() { - $this->tr->setLang('en'); - $expected = array( - 'first string' => 'first string', - 'second string' => 'second string', - ); - $this->assertEqual($expected, $this->tr->getPage('small page')); - $this->tr->setLang('it'); - $expected = array( - 'first string' => 'prima stringa', - 'second string' => 'seconda stringa', - ); - $this->assertEqual($expected, $this->tr->getPage('small page')); - } - function testGetRawPage() { - $expected = array( - 'first string' => 'first string', - 'second string' => 'second string', - ); - $this->assertEqual($expected, $this->tr->getRawPage('small page', 'en')); - $expected = array( - 'first string' => 'prima stringa', - 'second string' => 'seconda stringa', - ); - $this->assertEqual($expected, $this->tr->getRawPage('small page', 'it')); - } - function testConficts() { - $this->tr->setLang('en'); - $this->tr->setPageID('in_page'); - //pageID=TRANSLATION2_DEFAULT_PAGEID => get current pageID - $this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto')); - //pageID=null => get strings with pageID = NULL - $this->assertEqual('conflicting text - Global', $this->tr->get('prova_conflitto', null)); - //force pageID - $this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto', 'in_page')); - } - function testParameterSubstitution() { - $this->tr->setLang('en'); - $this->tr->setParams(array( - 'user' => 'Joe', - 'day' => '15', - 'month' => $this->tr->get('month_01', 'calendar'), - 'year' => '2004', - 'weekday' => $this->tr->get('day_5', 'calendar') - )); - $expected = 'hello Joe, today is friday, 15th january 2004'; - $this->assertEqual($expected, $this->tr->get('hello_user')); - $this->tr->setLang('it'); - $this->tr->setParams(array( - 'user' => 'Joe', - 'day' => '15', - 'month' => $this->tr->get('month_01', 'calendar'), - 'year' => '2004', - 'weekday' => $this->tr->get('day_5', 'calendar') - )); - $expected = 'ciao, Joe, oggi è il 15 gennaio 2004 (venerdì)'; - $this->assertEqual($expected, $this->tr->get('hello_user')); - } - function testGetStringID() { - $this->tr->setLang('en'); - $this->tr->setPageID('calendar'); - $this->assertEqual('month_01', $this->tr->getStringID('january')); - $this->tr->setLang('it'); - $this->assertEqual('month_01', $this->tr->getStringID('gennaio')); - } - function testGetLang() { - $this->tr->setLang('en'); - $this->assertEqual('english', $this->tr->getLang()); - $this->assertEqual('iso-8859-1', $this->tr->getLang('en', 'encoding')); - $this->assertEqual('my meta info', $this->tr->getLang('en', 'meta')); - $expected = array( - 'id' => 'it', - 'name' => 'italiano', - 'meta' => 'charset: iso-8859-1', - 'error_text' => 'non disponibile in Italiano', - 'encoding' => 'iso-8859-1', - ); - $this->assertEqual($expected, $this->tr->getLang('it', 'array')); - } - function testGetLangs() { - $expected = array( - 'it', - 'en', - 'de', - ); - $this->assertEqual($expected, $this->tr->getLangs('ids')); - $expected = array( - 'it' => 'italiano', - 'en' => 'english', - 'de' => 'deutsch', - ); - $this->assertEqual($expected, $this->tr->getLangs('names')); - $expected = array( - 'it' => array( - 'id' => 'it', - 'name' => 'italiano', - 'meta' => 'charset: iso-8859-1', - 'error_text' => 'non disponibile in Italiano', - 'encoding' => 'iso-8859-1', - ), - 'en' => array( - 'id' => 'en', - 'name' => 'english', - 'meta' => 'my meta info', - 'error_text' => 'not available in English', - 'encoding' => 'iso-8859-1', - ), - 'de' => array( - 'id' => 'de', - 'name' => 'deutsch', - 'meta' => 'charset: iso-8859-1', - 'error_text' => 'kein Text auf Deutsch verfügbar', - 'encoding' => 'iso-8859-1', - ), - ); - $this->assertEqual($expected, $this->tr->getLangs('array')); - } - function testDefaultTextDecorator() { - $this->tr->setLang('it'); - //without decorator - $this->assertEqual('', $this->tr->get('isempty')); - $expected = array( - 'only_english' => null, - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => null, - 'prova_conflitto' => 'testo con conflitto - globale', - 'test' => 'stringa di prova', - 'Entirely new string' => null, - ); - //with decorator - $this->tr =& $this->tr->getDecorator('DefaultText'); - $this->assertEqual('isempty', $this->tr->get('isempty')); - $this->assertEqual($expected, $this->tr->getRawPage()); - $expected = array( - 'only_english' => 'only_english', - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => 'isempty', - 'prova_conflitto' => 'testo con conflitto - globale', - 'test' => 'stringa di prova', - 'Entirely new string' => 'Entirely new string', - ); - $this->assertEqual($expected, $this->tr->getPage()); - } - function testErrorTextDecorator() { - $lang = 'it'; - $this->tr->setLang($lang); - //without decorator - $this->assertEqual('', $this->tr->get('isempty')); - $expected = array( - 'only_english' => null, - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => null, - 'prova_conflitto' => 'testo con conflitto - globale', - 'test' => 'stringa di prova', - 'Entirely new string' => null, - ); - $error_text = $this->tr->getLang($lang, 'error_text'); - //with decorator - $this->tr =& $this->tr->getDecorator('ErrorText'); - $this->assertEqual($error_text, $this->tr->get('isempty')); - $this->assertEqual($expected, $this->tr->getRawPage()); - $expected = array( - 'only_english' => $error_text, - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => $error_text, - 'prova_conflitto' => 'testo con conflitto - globale', - 'test' => 'stringa di prova', - 'Entirely new string' => $error_text, - ); - $this->assertEqual($expected, $this->tr->getPage()); - } - function testLangDecorator() { - $this->tr->setLang('it'); - $this->tr =& $this->tr->getDecorator('Lang'); - $this->tr->setOption('fallbackLang', 'en'); - $this->assertEqual('only english text', $this->tr->get('only_english')); - $expected = array( - 'only_english' => null, - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => null, - 'prova_conflitto' => 'testo con conflitto - globale', - 'test' => 'stringa di prova', - 'Entirely new string' => null, - ); - $this->assertEqual($expected, $this->tr->getRawPage()); - $this->tr =& $this->tr->getDecorator('Lang'); - $this->tr->setOption('fallbackLang', 'de'); - $expected = array( - 'only_english' => 'only english text', - 'only_italian' => 'testo solo in italiano', - 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', - 'isempty' => 'this string is empty in English and Italian, but not in German!', - 'test' => 'stringa di prova', - 'prova_conflitto' => 'testo con conflitto - globale', - 'Entirely new string' => 'Entirely new string', - ); - $this->assertEqual($expected, $this->tr->getPage()); - } - function testIconvDecorator() { - $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); - $this->tr =& $this->tr->getDecorator('Iconv'); - $this->tr->setOptions(array('encoding' => 'UTF-8')); - $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); - } - function testSpecialCharsDecorator() { - $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); - $this->tr =& $this->tr->getDecorator('SpecialChars'); - $this->assertEqual('venerd&igrave;', $this->tr->get('day_5', 'calendar', 'it')); - } - function testCacheMemoryDecorator() { - $this->tr->setLang('en'); - $original = 'hello &&user&&, today is &&weekday&&, &&day&&th &&month&& &&year&&'; - $this->assertEqual($original, $this->tr->get('hello_user')); - $this->tr =& $this->tr->getDecorator('CacheMemory'); - $replacements = array('Joe', 'Boe', 'Moe'); - foreach ($replacements as $v) { - $this->tr->setParams(array('user' => $v)); - $v = str_replace('&&user&&', $v, $original); - $this->assertEqual($v, $this->tr->get('hello_user')); - } - } - function testMultipleDecorators() { - $this->tr->setLang('en'); - $this->assertEqual(null, $this->tr->get('only_italian')); - $this->tr =& $this->tr->getDecorator('Lang'); - $this->tr->setOption('fallbackLang', 'de'); - $this->assertEqual(null, $this->tr->get('only_italian')); - //in-between decorator - $this->tr =& $this->tr->getDecorator('Iconv'); - //set option of the Lang decorator, passing through the Iconv decorator - $this->tr->setOption('fallbackLang', 'it'); - $this->assertEqual('testo solo in italiano', $this->tr->get('only_italian')); - } -} +require_once 'db_test_base.php'; if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/mdb2_test.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Translation2/tests/mdb2_test.php diff -u pear/Translation2/tests/mdb2_test.php:1.3 pear/Translation2/tests/mdb2_test.php:1.4 --- pear/Translation2/tests/mdb2_test.php:1.3 Thu Nov 18 20:34:07 2004 +++ pear/Translation2/tests/mdb2_test.php Tue Aug 29 09:54:36 2006 @@ -1,7 +1,7 @@ <?php -// $Id: mdb2_test.php,v 1.3 2004/11/18 20:34:07 quipo Exp $ +// $Id: mdb2_test.php,v 1.4 2006/08/29 09:54:36 quipo Exp $ -require_once 'db_test.php'; +require_once 'db_test_base.php'; class TestOfContainerMDB2 extends TestOfContainerDB { function TestOfContainerMDB2($name='Test of Container MDB2') { @@ -12,4 +12,10 @@ $this->tr = Translation2::factory($driver, dbms::getDbInfo(), dbms::getParams()); } } + +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = &new TestOfContainerMDB2(); + $test->run(new HtmlReporter()); +} ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/mdb_test.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Translation2/tests/mdb_test.php diff -u pear/Translation2/tests/mdb_test.php:1.3 pear/Translation2/tests/mdb_test.php:1.4 --- pear/Translation2/tests/mdb_test.php:1.3 Thu Nov 18 20:34:07 2004 +++ pear/Translation2/tests/mdb_test.php Tue Aug 29 09:54:36 2006 @@ -1,7 +1,7 @@ <?php -// $Id: mdb_test.php,v 1.3 2004/11/18 20:34:07 quipo Exp $ +// $Id: mdb_test.php,v 1.4 2006/08/29 09:54:36 quipo Exp $ -require_once 'db_test.php'; +require_once 'db_test_base.php'; class TestOfContainerMDB extends TestOfContainerDB { function TestOfContainerMDB($name='Test of Container MDB') { @@ -12,4 +12,10 @@ $this->tr = Translation2::factory($driver, dbms::getDbInfo(), dbms::getParams()); } } + +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = &new TestOfContainerMDB(); + $test->run(new HtmlReporter()); +} ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/admin_db_test_base.php?view=markup&rev=1.1 Index: pear/Translation2/tests/admin_db_test_base.php +++ pear/Translation2/tests/admin_db_test_base.php <?php // $Id: admin_db_test_base.php,v 1.1 2006/08/29 09:54:36 quipo Exp $ require_once 'simple_include.php'; require_once 'translation2_admin_include.php'; require_once 'dbms.php'; class TestOfAdminContainerDB extends UnitTestCase { var $tr; function TestOfAdminContainerDB($name='Test of Admin Container DB') { $this->UnitTestCase($name); } function setUp() { $driver = 'DB'; $this->tr = Translation2_Admin::factory($driver, dbms::getDbInfo(), dbms::getParams()); } function tearDown() { unset($this->tr); } function testFactory() { if (PEAR::isError($this->tr)) { var_dump($this->tr->getUserInfo()); var_dump($this->tr->getMessage()); //var_dump(debug_backtrace()); exit; } $this->assertTrue(!PEAR::isError($this->tr)); } function testAddLang() { $langData = array( 'lang_id' => 'fr', 'table_name' => 'i18n', 'name' => 'français', 'meta' => '123 abc', 'error_text' => 'non disponible', 'encoding' => 'iso-8859-1', ); $pre = $this->tr->getLangs('array'); // create a new language $this->tr->addLang($langData); $post = $this->tr->getLangs('array'); $expected = array( 'id' => 'fr', 'name' => 'français', 'meta' => '123 abc', 'error_text' => 'non disponible', 'encoding' => 'iso-8859-1', ); $this->assertEqual($expected, array_pop(array_diff_assoc($post, $pre))); // remove the new language $this->assertTrue($this->tr->removeLang('fr')); $this->assertEqual($pre, $this->tr->getLangs('array')); } function testUpdateLang() { $original = array( 'id' => 'en', 'name' => 'english', 'meta' => 'my meta info', 'error_text' => 'not available in English', 'encoding' => 'iso-8859-1', ); $restore = array( 'lang_id' => 'en', 'name' => 'english', 'meta' => 'my meta info', 'error_text' => 'not available in English', 'encoding' => 'iso-8859-1', ); $newLangData = array( 'lang_id' => 'en', 'name' => 'english2', 'meta' => 'my other meta info', 'error_text' => 'not available in English2', 'encoding' => 'iso-8859-15', ); $expected = array( 'id' => 'en', 'name' => 'english2', 'meta' => 'my other meta info', 'error_text' => 'not available in English2', 'encoding' => 'iso-8859-15', ); $this->assertTrue($this->tr->updateLang($newLangData)); $this->tr->setLang('en'); $this->assertEqual($expected, $this->tr->getLang('en', 'array')); $this->assertTrue($this->tr->updateLang($restore)); $this->assertEqual($original, $this->tr->getLang('en', 'array')); } function testAddUpdateRemove() { $stringArray = array( 'en' => 'sample', 'it' => 'esempio', 'de' => 'Beispiel', ); //add $this->assertTrue($this->tr->add('sample', 'new page', $stringArray)); $this->assertEqual($stringArray['en'], $this->tr->get('sample', 'new page', 'en')); $this->assertEqual($stringArray['it'], $this->tr->get('sample', 'new page', 'it')); $this->assertEqual($stringArray['de'], $this->tr->get('sample', 'new page', 'de')); //update $newStringArray = array('en' => 'example'); $this->assertTrue($this->tr->update('sample', 'new page', $newStringArray)); $this->assertEqual($newStringArray['en'], $this->tr->get('sample', 'new page', 'en')); $this->assertEqual($stringArray['it'], $this->tr->get('sample', 'new page', 'it')); $this->assertEqual($stringArray['de'], $this->tr->get('sample', 'new page', 'de')); //remove $this->assertTrue($this->tr->remove('sample', 'new page')); $this->assertEqual('', $this->tr->get('sample', 'new page', 'en')); } function testGetPageNames() { $expected = array( null, '', 'alone', 'bbcode', 'calendar', 'de', 'in_page', 'samplePage', 'small page', ); sort($expected); $actual = $this->tr->getPageNames(); sort($actual); $this->assertEqual($expected, $actual); } } ?> http://cvs.php.net/viewvc.cgi/pear/Translation2/tests/db_test_base.php?view=markup&rev=1.1 Index: pear/Translation2/tests/db_test_base.php +++ pear/Translation2/tests/db_test_base.php <?php // $Id: db_test_base.php,v 1.1 2006/08/29 09:54:36 quipo Exp $ require_once 'simple_include.php'; require_once 'translation2_include.php'; require_once 'dbms.php'; //require_once 'common_tests.php'; class TestOfContainerDB extends UnitTestCase { //TestOfTranslation2 { var $tr; function TestOfContainerDB($name='Test of Container DB') { $this->UnitTestCase($name); } function setUp() { $driver = 'DB'; $this->tr = Translation2::factory($driver, dbms::getDbInfo(), dbms::getParams()); } function tearDown() { unset($this->tr); } function testFactory() { if (PEAR::isError($this->tr)) { var_dump($this->tr->getUserInfo()); var_dump($this->tr->getMessage()); } $this->assertTrue(!PEAR::isError($this->tr)); } function testGet() { $this->assertEqual('gennaio', $this->tr->get('month_01', 'calendar', 'it')); $this->assertEqual('january', $this->tr->get('month_01', 'calendar', 'en')); $this->assertFalse(PEAR::isError($this->tr->setLang('en'))); //set default lang $this->assertEqual('sunday', $this->tr->get('day_0', 'calendar')); $this->assertEqual('monday', $this->tr->get('day_1', 'calendar')); $this->tr->setPageID('calendar'); //set default lang AND default pageID $this->assertEqual('sunday', $this->tr->get('day_0')); $this->assertEqual('monday', $this->tr->get('day_1')); } function testGetRaw() { $this->tr->setLang('it'); $this->tr->setParams(array( 'user' => 'Joe', 'day' => '15', 'month' => $this->tr->get('month_01', 'calendar'), 'year' => '2004', 'weekday' => $this->tr->get('day_5', 'calendar') )); $expected = 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)'; $this->assertEqual($expected, $this->tr->getRaw('hello_user')); $this->tr =& $this->tr->getDecorator('SpecialChars'); $this->assertEqual('venerdì', $this->tr->getRaw('day_5', 'calendar', 'it')); } function testGetPage() { $this->tr->setLang('en'); $expected = array( 'first string' => 'first string', 'second string' => 'second string', ); $this->assertEqual($expected, $this->tr->getPage('small page')); $this->tr->setLang('it'); $expected = array( 'first string' => 'prima stringa', 'second string' => 'seconda stringa', ); $this->assertEqual($expected, $this->tr->getPage('small page')); } function testGetRawPage() { $expected = array( 'first string' => 'first string', 'second string' => 'second string', ); $this->assertEqual($expected, $this->tr->getRawPage('small page', 'en')); $expected = array( 'first string' => 'prima stringa', 'second string' => 'seconda stringa', ); $this->assertEqual($expected, $this->tr->getRawPage('small page', 'it')); } function testConficts() { $this->tr->setLang('en'); $this->tr->setPageID('in_page'); //pageID=TRANSLATION2_DEFAULT_PAGEID => get current pageID $this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto')); //pageID=null => get strings with pageID = NULL $this->assertEqual('conflicting text - Global', $this->tr->get('prova_conflitto', null)); //force pageID $this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto', 'in_page')); } function testParameterSubstitution() { $this->tr->setLang('en'); $this->tr->setParams(array( 'user' => 'Joe', 'day' => '15', 'month' => $this->tr->get('month_01', 'calendar'), 'year' => '2004', 'weekday' => $this->tr->get('day_5', 'calendar') )); $expected = 'hello Joe, today is friday, 15th january 2004'; $this->assertEqual($expected, $this->tr->get('hello_user')); $this->tr->setLang('it'); $this->tr->setParams(array( 'user' => 'Joe', 'day' => '15', 'month' => $this->tr->get('month_01', 'calendar'), 'year' => '2004', 'weekday' => $this->tr->get('day_5', 'calendar') )); $expected = 'ciao, Joe, oggi è il 15 gennaio 2004 (venerdì)'; $this->assertEqual($expected, $this->tr->get('hello_user')); } function testGetStringID() { $this->tr->setLang('en'); $this->tr->setPageID('calendar'); $this->assertEqual('month_01', $this->tr->getStringID('january')); $this->tr->setLang('it'); $this->assertEqual('month_01', $this->tr->getStringID('gennaio')); } function testGetLang() { $this->tr->setLang('en'); $this->assertEqual('english', $this->tr->getLang()); $this->assertEqual('iso-8859-1', $this->tr->getLang('en', 'encoding')); $this->assertEqual('my meta info', $this->tr->getLang('en', 'meta')); $expected = array( 'id' => 'it', 'name' => 'italiano', 'meta' => 'charset: iso-8859-1', 'error_text' => 'non disponibile in Italiano', 'encoding' => 'iso-8859-1', ); $this->assertEqual($expected, $this->tr->getLang('it', 'array')); } function testGetLangs() { $expected = array( 'it', 'en', 'de', ); $this->assertEqual($expected, $this->tr->getLangs('ids')); $expected = array( 'it' => 'italiano', 'en' => 'english', 'de' => 'deutsch', ); $this->assertEqual($expected, $this->tr->getLangs('names')); $expected = array( 'it' => array( 'id' => 'it', 'name' => 'italiano', 'meta' => 'charset: iso-8859-1', 'error_text' => 'non disponibile in Italiano', 'encoding' => 'iso-8859-1', ), 'en' => array( 'id' => 'en', 'name' => 'english', 'meta' => 'my meta info', 'error_text' => 'not available in English', 'encoding' => 'iso-8859-1', ), 'de' => array( 'id' => 'de', 'name' => 'deutsch', 'meta' => 'charset: iso-8859-1', 'error_text' => 'kein Text auf Deutsch verfügbar', 'encoding' => 'iso-8859-1', ), ); $this->assertEqual($expected, $this->tr->getLangs('array')); } function testDefaultTextDecorator() { $this->tr->setLang('it'); //without decorator $this->assertEqual('', $this->tr->get('isempty')); $expected = array( 'only_english' => null, 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => null, 'prova_conflitto' => 'testo con conflitto - globale', 'test' => 'stringa di prova', 'Entirely new string' => null, ); //with decorator $this->tr =& $this->tr->getDecorator('DefaultText'); $this->assertEqual('isempty', $this->tr->get('isempty')); $this->assertEqual($expected, $this->tr->getRawPage()); $expected = array( 'only_english' => 'only_english', 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => 'isempty', 'prova_conflitto' => 'testo con conflitto - globale', 'test' => 'stringa di prova', 'Entirely new string' => 'Entirely new string', ); $this->assertEqual($expected, $this->tr->getPage()); } function testErrorTextDecorator() { $lang = 'it'; $this->tr->setLang($lang); //without decorator $this->assertEqual('', $this->tr->get('isempty')); $expected = array( 'only_english' => null, 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => null, 'prova_conflitto' => 'testo con conflitto - globale', 'test' => 'stringa di prova', 'Entirely new string' => null, ); $error_text = $this->tr->getLang($lang, 'error_text'); //with decorator $this->tr =& $this->tr->getDecorator('ErrorText'); $this->assertEqual($error_text, $this->tr->get('isempty')); $this->assertEqual($expected, $this->tr->getRawPage()); $expected = array( 'only_english' => $error_text, 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => $error_text, 'prova_conflitto' => 'testo con conflitto - globale', 'test' => 'stringa di prova', 'Entirely new string' => $error_text, ); $this->assertEqual($expected, $this->tr->getPage()); } function testLangDecorator() { $this->tr->setLang('it'); $this->tr =& $this->tr->getDecorator('Lang'); $this->tr->setOption('fallbackLang', 'en'); $this->assertEqual('only english text', $this->tr->get('only_english')); $expected = array( 'only_english' => null, 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => null, 'prova_conflitto' => 'testo con conflitto - globale', 'test' => 'stringa di prova', 'Entirely new string' => null, ); $this->assertEqual($expected, $this->tr->getRawPage()); $this->tr =& $this->tr->getDecorator('Lang'); $this->tr->setOption('fallbackLang', 'de'); $expected = array( 'only_english' => 'only english text', 'only_italian' => 'testo solo in italiano', 'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)', 'isempty' => 'this string is empty in English and Italian, but not in German!', 'test' => 'stringa di prova', 'prova_conflitto' => 'testo con conflitto - globale', 'Entirely new string' => 'Entirely new string', ); $this->assertEqual($expected, $this->tr->getPage()); } function testIconvDecorator() { $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); $this->tr =& $this->tr->getDecorator('Iconv'); $this->tr->setOptions(array('encoding' => 'UTF-8')); $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); } function testSpecialCharsDecorator() { $this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it')); $this->tr =& $this->tr->getDecorator('SpecialChars'); $this->assertEqual('venerd&igrave;', $this->tr->get('day_5', 'calendar', 'it')); } function testCacheMemoryDecorator() { $this->tr->setLang('en'); $original = 'hello &&user&&, today is &&weekday&&, &&day&&th &&month&& &&year&&'; $this->assertEqual($original, $this->tr->get('hello_user')); $this->tr =& $this->tr->getDecorator('CacheMemory'); $replacements = array('Joe', 'Boe', 'Moe'); foreach ($replacements as $v) { $this->tr->setParams(array('user' => $v)); $v = str_replace('&&user&&', $v, $original); $this->assertEqual($v, $this->tr->get('hello_user')); } } function testMultipleDecorators() { $this->tr->setLang('en'); $this->assertEqual(null, $this->tr->get('only_italian')); $this->tr =& $this->tr->getDecorator('Lang'); $this->tr->setOption('fallbackLang', 'de'); $this->assertEqual(null, $this->tr->get('only_italian')); //in-between decorator $this->tr =& $this->tr->getDecorator('Iconv'); //set option of the Lang decorator, passing through the Iconv decorator $this->tr->setOption('fallbackLang', 'it'); $this->assertEqual('testo solo in italiano', $this->tr->get('only_italian')); } } ?>
« previous php.pear.cvs (#41903) next »