Browse files

added removePage() method (with tests)

git-svn-id: http://svn.php.net/repository/pear/packages/Translation2/trunk@245971 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 8d4664d commit 0d366f14f0bba67ede60ce7f30a22cdf23fb41b0 @quipo quipo committed Nov 10, 2007
View
19 Admin.php
@@ -311,6 +311,25 @@ function remove($stringID, $pageID = null)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null)
+ {
+ $result = $this->storage->removePage($pageID);
+ if ($this->options['autoCleanCache']) {
+ $this->cleanCache();
+ }
+ return $result;
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
29 Admin/Container/dataobjectsimple.php
@@ -196,7 +196,34 @@ function remove($stringID, $pageID)
$do = DB_DataObject::factory($this->options['table']);
$do->page = $pageID;
$do->translation = $stringID;
- // we dont have the base language translation..
+ // we don't have the base language translation..
+ if (!$do->find()) {
+ return '';
+ }
+
+ while ($do->fetch()) {
+ $do2 = DB_DataObject::factory($this->options['table']);
+ $do2->get($do->id);
+ $do2->delete();
+ }
+ return true;
+ }
+
+ // }}}
+ // {{{ removePage()
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null)
+ {
+ $do = DB_DataObject::factory($this->options['table']);
+ $do->page = $pageID;
+ // we don't have the base language translation..
if (!$do->find()) {
return '';
}
View
40 Admin/Container/db.php
@@ -497,6 +497,46 @@ function remove($stringID, $pageID)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null)
+ {
+ $tables = array_unique($this->_getLangTables());
+
+ // get the tables and skip the non existent ones
+ $dbTables = $this->db->getListOf('tables');
+ foreach ($tables as $table) {
+ if (!in_array($table, $dbTables)) {
+ continue;
+ }
+ $query = sprintf('DELETE FROM %s WHERE %s',
+ $this->db->quoteIdentifier($table, true),
+ $this->db->quoteIdentifier($this->options['string_page_id_col'])
+ );
+ if (is_null($pageID)) {
+ $query .= ' IS NULL';
+ } else {
+ $query .= ' = ' . $this->db->quote($pageID, 'text');
+ }
+
+ ++$this->_queries;
+ $res = $this->db->query($query);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+
+ return true;
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
105 Admin/Container/gettext.php
@@ -77,7 +77,7 @@ class Translation2_Admin_Container_gettext extends Translation2_Container_gettex
*/
function addLang($langData, $path = null)
{
- if (!isset($path)) {
+ if (!isset($path) || !is_string($path)) {
$path = $this->_domains[$this->options['default_domain']];
}
@@ -192,6 +192,48 @@ function remove($stringID, $pageID)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group (domain)
+ *
+ * @param string $pageID page/group ID
+ * @param string $path path to gettext data dir
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null, $path = null)
+ {
+ if (!isset($pageID)) {
+ $pageID = $this->options['default_domain'];
+ }
+
+ if (!isset($path)) {
+ if (!empty($this->_domains[$pageID])) {
+ $path = $this->_domains[$pageID];
+ } else {
+ $path = $this->_domains[$this->options['default_domain']];
+ }
+ }
+
+ if (PEAR::isError($e = $this->_removeDomain($pageID))) {
+ return $e;
+ }
+
+ $this->fetchLangs();
+ foreach ($this->langs as $langID => $lang) {
+ $domain_file = $path .'/'. $langID .'/LC_MESSAGES/'. $pageID .'.';
+ if (!@unlink($domain_file.'mo') || !@unlink($domain_file.'po')) {
+ return $this->raiseError('Cannot delete page ' . $pageID. ' (file '.$domain_file.'.*)',
+ TRANSLATION2_ERROR
+ );
+ }
+ }
+
+ return true;
+ }
+
+ // }}}
// {{{ update()
/**
@@ -454,17 +496,70 @@ function _addDomain($pageID)
$CRLF = $this->options['carriage_return'];
- @flock($f, LOCK_EX);
- fwrite($f, $CRLF . $pageID . ' = ' . $domain_path . $CRLF);
- @flock($f, LOCK_UN);
- fclose($f);
+ while (true) {
+ if (@flock($f, LOCK_EX)) {
+ fwrite($f, $CRLF . $pageID . ' = ' . $domain_path . $CRLF);
+ @flock($f, LOCK_UN);
+ fclose($f);
+ break;
+ }
+ }
$this->_domains[$pageID] = $domain_path;
return true;
}
// }}}
+ // {{{ _removeDomain()
+
+ /**
+ * Remove the path-to-the-domain from the domains-path-INI-file
+ *
+ * @param string $pageID domain name
+ *
+ * @return true|PEAR_Error on failure
+ * @access private
+ */
+ function _removeDomain($pageID)
+ {
+ $domain_path = count($this->_domains) ? reset($this->_domains) : 'locale/';
+
+ if (!is_resource($f = fopen($this->options['domains_path_file'], 'r+'))) {
+ return $this->raiseError(sprintf(
+ 'Cannot write to domains path INI file "%s"',
+ $this->options['domains_path_file']
+ ),
+ TRANSLATION2_ERROR_CANNOT_WRITE_FILE
+ );
+ }
+
+ $CRLF = $this->options['carriage_return'];
+
+ while (true) {
+ if (@flock($f, LOCK_EX)) {
+ $pages = file($this->options['domains_path_file']);
+ foreach ($pages as $page) {
+ if (preg_match('/^'.$pageID.'\s*=/', $page)) {
+ //skip
+ continue;
+ }
+ fwrite($f, $page . $CRLF);
+ }
+ fflush($f);
+ ftruncate($f, ftell($f));
+ @flock($f, LOCK_UN);
+ fclose($f);
+ break;
+ }
+ }
+
+ unset($this->_domains[$pageID]);
+
+ return true;
+ }
+
+ // }}}
// {{{ _writeLangsAvailFile()
/**
View
40 Admin/Container/mdb.php
@@ -490,6 +490,46 @@ function remove($stringID, $pageID)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null)
+ {
+ $tables = array_unique($this->_getLangTables());
+
+ // get the tables and skip the non existent ones
+ $dbTables = $this->db->listTables();
+ foreach ($tables as $table) {
+ if (!in_array($table, $dbTables)) {
+ continue;
+ }
+ $query = sprintf('DELETE FROM %s WHERE %s',
+ $this->db->quoteIdentifier($table, true),
+ $this->db->quoteIdentifier($this->options['string_page_id_col'], true)
+ );
+ if (is_null($pageID)) {
+ $query .= ' IS NULL';
+ } else {
+ $query .= ' = ' . $this->db->getTextValue($pageID);
+ }
+
+ ++$this->_queries;
+ $res = $this->db->query($query);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+
+ return true;
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
40 Admin/Container/mdb2.php
@@ -531,6 +531,46 @@ function remove($stringID, $pageID)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function removePage($pageID = null)
+ {
+ $tables = array_unique($this->_getLangTables());
+
+ // get the tables and skip the non existent ones
+ $dbTables = $this->_fetchTableNames();
+ foreach ($tables as $table) {
+ if (!in_array($table, $dbTables)) {
+ continue;
+ }
+ $query = sprintf('DELETE FROM %s WHERE %s',
+ $this->db->quoteIdentifier($table, true),
+ $this->db->quoteIdentifier($this->options['string_page_id_col'], true)
+ );
+ if (is_null($pageID)) {
+ $query .= ' IS NULL';
+ } else {
+ $query .= ' = ' . $this->db->quote($pageID, 'text');
+ }
+
+ ++$this->_queries;
+ $res = $this->db->exec($query);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+
+ return true;
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
20 Admin/Container/xml.php
@@ -244,6 +244,26 @@ function removeLang($langID, $force = true)
}
// }}}
+ // {{{ removePage()
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return true|PEAR_Error
+ */
+ function removePage($pageID = null)
+ {
+ $pageID = is_null($pageID) ? '#NULL' : $pageID;
+ $pageID = empty($pageID) ? '#EMPTY' : $pageID;
+
+ unset ($this->_data['pages'][$pageID]);
+
+ return $this->_scheduleSaving();
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
16 Admin/Decorator.php
@@ -172,6 +172,22 @@ function remove($stringID, $pageID = null)
}
// }}}
+ // {{{ removePage
+
+ /**
+ * Remove all the strings in the given page/group
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ * @see Translation2_Admin::removePage()
+ */
+ function removePage($pageID = null)
+ {
+ return $this->translation2->removePager($pageID);
+ }
+
+ // }}}
// {{{ getPageNames()
/**
View
12 package.xml
@@ -45,8 +45,8 @@ Currently, the following decorators are provided:
<email>mike@php.net</email>
<active>yes</active>
</developer>
- <date>2007-10-22</date>
- <time>21:18:30</time>
+ <date>2007-11-10</date>
+ <time>01:02:30</time>
<version>
<release>2.0.0RC2</release>
<api>2.0.0RC2</api>
@@ -62,6 +62,8 @@ Currently, the following decorators are provided:
- bug #12183: language ID '0' considered invalid
- bug #12398: fixed return value of addLangToList() and updateLang() in the MDB2
admin container
+- request #12405: added removePage() method in the Admin module
+- fixed the test suite
- fixed Coding Standards
</notes>
<contents>
@@ -208,12 +210,16 @@ Currently, the following decorators are provided:
<release>beta</release>
<api>beta</api>
</stability>
- <date>2007-10-22</date>
+ <date>2007-11-10</date>
<license uri="http://www.debian.org/misc/bsd.license">BSD</license>
<notes>- request #11711: added setCharset() method in the DB container
- bug #11880: [XML driver] removing one language removes all strings for all languages
- request #11881: getLang(...,'array') now returns a 'lang_id' alias to 'id'
- bug #12183: language ID '0' considered invalid
+- bug #12398: fixed return value of addLangToList() and updateLang() in the MDB2
+ admin container
+- request #12405: added removePage() method in the Admin module
+- fixed the test suite
- fixed Coding Standards
</notes>
</release>
View
51 tests/admin_db_test_base.php
@@ -94,27 +94,29 @@ function testUpdateLang() {
$this->assertEqual($original, $this->tr->getLang('en', 'array'));
}
function testAddUpdateRemove() {
+ $stringID = 'sample';
+ $pageID = 'new page';
$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'));
+ $this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
+ $this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
+ $this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
+ $this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, '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'));
+ $this->assertTrue($this->tr->update($stringID, $pageID, $newStringArray));
+ $this->assertEqual($newStringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
+ $this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
+ $this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
//remove
- $this->assertTrue($this->tr->remove('sample', 'new page'));
- $this->assertEqual('', $this->tr->get('sample', 'new page', 'en'));
+ $this->assertTrue($this->tr->remove($stringID, $pageID));
+ $this->assertEqual('', $this->tr->get($stringID, $pageID, 'en'));
}
function testGetPageNames() {
$expected = array(
@@ -133,5 +135,34 @@ function testGetPageNames() {
sort($actual);
$this->assertEqual($expected, $actual);
}
+
+ function testRemovePage() {
+ $stringID = 'sample';
+ $pageID = 'new page';
+
+ $this->assertFalse(in_array($pageID, $this->tr->getPageNames()));
+
+ $stringArray = array(
+ 'en' => 'sample',
+ 'it' => 'esempio',
+ 'de' => 'Beispiel',
+ );
+ //add new page
+ $this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
+
+ $this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
+ $this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
+ $this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
+
+ $actual = $this->tr->getPageNames();
+ $this->assertTrue(in_array($pageID, $this->tr->getPageNames()));
+
+ //delete the page
+ $this->assertTrue($this->tr->removePage($pageID));
+
+ $this->assertEqual('', $this->tr->get($stringID, $pageID, 'en'));
+
+ $this->assertFalse(in_array($pageID, $this->tr->getPageNames()));
+ }
}
?>
View
29 tests/admin_gettext_mo_test.php
@@ -0,0 +1,29 @@
+<?php
+// $Id$
+
+require_once 'admin_gettext_test_base.php';
+
+class TestOfAdminContainerGettextMO extends TestOfAdminContainerGettextPO {
+ function TestOfAdminContainerGettextMO($name='Test of Admin Container Gettext MO') {
+ $this->UnitTestCase($name);
+ }
+ function setUp() {
+ $this->init();
+ $driver = 'gettext';
+ $options = array(
+ 'prefetch' => false,
+ 'langs_avail_file' => 'gettext_langs.ini',
+ 'domains_path_file' => 'gettext_domains.ini',
+ 'default_domain' => 'messages',
+ 'file_type' => 'mo',
+ );
+ $this->tr = Translation2_Admin::factory($driver, $options);
+ }
+}
+
+if (!defined('TEST_RUNNING')) {
+ define('TEST_RUNNING', true);
+ $test = &new TestOfAdminContainerGettextMO();
+ $test->run(new HtmlReporter());
+}
+?>
View
128 tests/admin_gettext_po_test.php
@@ -1,129 +1,11 @@
<?php
// $Id$
-require_once 'admin_db_test.php';
+require_once 'admin_gettext_test_base.php';
-class TestOfAdminContainerGettextPO extends TestOfAdminContainerDB {
- var $options = array(
- 'prefetch' => false,
- 'langs_avail_file' => 'gettext_langs.ini',
- 'domains_path_file' => 'gettext_domains.ini',
- 'default_domain' => 'messages',
- 'file_type' => 'po',
- 'carriage_return' => "\n",
- );
- function TestOfAdminContainerGettextPO($name='Test of Admin Container Gettext PO') {
- $this->UnitTestCase($name);
- }
- function setUp() {
- $langs = array(
- 'it' => array(
- 'name' => 'italiano',
- 'meta' => 'charset: iso-8859-1',
- 'error_text' => 'non disponibile in Italiano',
- 'encoding' => 'iso-8859-1',
- ),
- 'en' => array(
- 'name' => 'english',
- 'meta' => 'my meta info',
- 'error_text' => 'not available in English',
- 'encoding' => 'iso-8859-1',
- ),
- 'de' => array(
- 'name' => 'deutsch',
- 'meta' => 'charset: iso-8859-1',
- 'error_text' => 'kein Text auf Deutsch verfügbar',
- 'encoding' => 'iso-8859-1',
- ),
- );
- $this->write_ini_file($langs, $this->options['langs_avail_file'], true);
-
- $domains = array(
- 'calendar' => 'locale/',
- 'alone' => 'locale/',
- 'admin' => 'locale/',
- 'small page' => 'locale/',
- 'messages' => 'locale/',
- 'in_page' => 'locale/',
- );
- $this->write_ini_file($domains, $this->options['domains_path_file'], false);
-
- $driver = 'gettext';
- $this->tr = Translation2_Admin::factory($driver, $this->options);
- }
-
- /**
- * This function writes an array to a INI file,
- * pretty much like parse_ini_file(), only in reverse.
- *
- * @param array $array Data to write
- * @param string $filename Destination file name
- * @param boolean $process_sections The source array is bidimensional,
- * and the first keys are the section names
- */
- function write_ini_file($array, $filename, $process_sections = false)
- {
- if (!is_resource($f = fopen($filename, 'w'))) {
- die('Ops... cannot write "'.$filename.'" file');
- }
- $CRLF = $this->options['carriage_return'];
-
- @flock($f, LOCK_EX);
-
- if ($process_sections) {
- foreach ($array as $id => $data) {
- fwrite($f, '['. $id .']'. $CRLF);
- foreach ($data as $k => $v) {
- fwrite($f, $k . ' = ' . $v . $CRLF);
- }
- fwrite($f, $CRLF);
- }
- } else {
- foreach ($array as $id => $data) {
- fwrite($f, $id . ' = ' . $data . $CRLF);
- }
- }
-
- @flock($f, LOCK_UN);
- fclose($f);
- }
- 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'));
- //with gettext, empty strings are replaced by the stringID
- $this->assertEqual('sample', $this->tr->get('sample', 'new page', 'en'));
- }
- function testGetPageNames() {
- $expected = array(
- 'admin',
- 'alone',
- 'calendar',
- 'in_page',
- 'messages',
- 'small page',
- );
- sort($expected);
- $actual = $this->tr->getPageNames();
- sort($actual);
- $this->assertEqual($expected, $actual);
- }
+if (!defined('TEST_RUNNING')) {
+ define('TEST_RUNNING', true);
+ $test = &new TestOfAdminContainerGettextPO();
+ $test->run(new HtmlReporter());
}
?>
View
158 tests/admin_gettext_test_base.php
@@ -0,0 +1,158 @@
+<?php
+// $Id$
+
+require_once 'admin_db_test_base.php';
+
+class TestOfAdminContainerGettextPO extends TestOfAdminContainerDB {
+ var $options = array(
+ 'prefetch' => false,
+ 'langs_avail_file' => 'gettext_langs.ini',
+ 'domains_path_file' => 'gettext_domains.ini',
+ 'default_domain' => 'messages',
+ 'file_type' => 'po',
+ 'carriage_return' => "\n",
+ );
+ var $domains = array(
+ 'calendar' => 'locale/',
+ 'alone' => 'locale/',
+ 'admin' => 'locale/',
+ 'small page' => 'locale/',
+ 'messages' => 'locale/',
+ 'in_page' => 'locale/',
+ );
+ function TestOfAdminContainerGettextPO($name='Test of Admin Container Gettext PO') {
+ $this->UnitTestCase($name);
+ }
+
+ function init() {
+ $langs = array(
+ 'it' => array(
+ 'name' => 'italiano',
+ 'meta' => 'charset: iso-8859-1',
+ 'error_text' => 'non disponibile in Italiano',
+ 'encoding' => 'iso-8859-1',
+ ),
+ 'en' => array(
+ 'name' => 'english',
+ 'meta' => 'my meta info',
+ 'error_text' => 'not available in English',
+ 'encoding' => 'iso-8859-1',
+ ),
+ 'de' => array(
+ 'name' => 'deutsch',
+ 'meta' => 'charset: iso-8859-1',
+ 'error_text' => 'kein Text auf Deutsch verfügbar',
+ 'encoding' => 'iso-8859-1',
+ ),
+ );
+ $this->write_ini_file($langs, $this->options['langs_avail_file'], true);
+ $this->write_ini_file($this->domains, $this->options['domains_path_file'], false);
+ }
+
+ function setUp() {
+ $this->init();
+ $driver = 'gettext';
+ $this->tr = Translation2_Admin::factory($driver, $this->options);
+ }
+
+ /**
+ * This function writes an array to a INI file,
+ * pretty much like parse_ini_file(), only in reverse.
+ *
+ * @param array $array Data to write
+ * @param string $filename Destination file name
+ * @param boolean $process_sections The source array is bidimensional,
+ * and the first keys are the section names
+ */
+ function write_ini_file($array, $filename, $process_sections = false)
+ {
+ if (!is_resource($f = fopen($filename, 'w'))) {
+ die('Ops... cannot write "'.$filename.'" file');
+ }
+ $CRLF = $this->options['carriage_return'];
+
+ @flock($f, LOCK_EX);
+
+ if ($process_sections) {
+ foreach ($array as $id => $data) {
+ fwrite($f, '['. $id .']'. $CRLF);
+ foreach ($data as $k => $v) {
+ fwrite($f, $k . ' = ' . $v . $CRLF);
+ }
+ fwrite($f, $CRLF);
+ }
+ } else {
+ foreach ($array as $id => $data) {
+ fwrite($f, $id . ' = ' . $data . $CRLF);
+ }
+ }
+
+ @flock($f, LOCK_UN);
+ fclose($f);
+ }
+ function testAddUpdateRemove() {
+ $stringID = 'sample';
+ $pageID = 'new page';
+ $stringArray = array(
+ 'en' => 'sample',
+ 'it' => 'esempio',
+ 'de' => 'Beispiel',
+ );
+ //add
+ $this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
+ $this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
+ $this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
+ $this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
+
+ //update
+ $newStringArray = array('en' => 'example');
+ $this->assertTrue($this->tr->update($stringID, $pageID, $newStringArray));
+ $this->assertEqual($newStringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
+ $this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
+ $this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
+
+ //remove
+ $this->assertTrue($this->tr->remove($stringID, $pageID));
+ //with gettext, empty strings are replaced by the stringID
+ $this->assertEqual('sample', $this->tr->get($stringID, $pageID, 'en'));
+ }
+ function testGetPageNames() {
+ $expected = array_keys($this->domains);
+ sort($expected);
+ $actual = $this->tr->getPageNames();
+ sort($actual);
+ $this->assertEqual($expected, $actual);
+ }
+ function testRemovePage() {
+ $this->testGetPageNames();
+ $stringArray = array(
+ 'en' => 'sample',
+ 'it' => 'esempio',
+ 'de' => 'Beispiel',
+ );
+
+ //add new page
+ $newpage = 'new page';
+ $this->assertTrue($this->tr->add('sample', $newpage, $stringArray));
+
+ $actual = $this->tr->getPageNames();
+ $this->assertTrue(in_array($newpage, $this->tr->getPageNames()));
+
+ //check if the page name was written in the .ini file
+ $this->assertTrue($this->inifileHasDomain($newpage));
+
+ //delete the page
+ $this->assertTrue($this->tr->removePage($newpage));
+
+ $this->testGetPageNames();
+
+ //check if the page name was written in the .ini file
+ $this->assertFalse($this->inifileHasDomain($newpage));
+ }
+
+ function inifileHasDomain($domain) {
+ $inifile = parse_ini_file($this->options['domains_path_file']);
+ return in_array($domain, array_keys($inifile));
+ }
+}
+?>

0 comments on commit 0d366f1

Please sign in to comment.