- implemented php side of plural translation
- using it to generate labels dynamically for the expire options (deprecating the [expire_labels] configuration). - added translation of the human readable data sizes to support the french octet - fixed IEC label for kibibytes
This commit is contained in:
@@ -9,14 +9,31 @@ class filterTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterMakesTimesHumanlyReadable()
|
||||
{
|
||||
$this->assertEquals('5 minutes', filter::time_humanreadable('5min'));
|
||||
$this->assertEquals('90 seconds', filter::time_humanreadable('90sec'));
|
||||
$this->assertEquals('1 week', filter::time_humanreadable('1week'));
|
||||
$this->assertEquals('6 months', filter::time_humanreadable('6months'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 30
|
||||
*/
|
||||
public function testFilterFailTimesHumanlyReadable()
|
||||
{
|
||||
filter::time_humanreadable('five_minutes');
|
||||
}
|
||||
|
||||
public function testFilterMakesSizesHumanlyReadable()
|
||||
{
|
||||
$this->assertEquals('1 B', filter::size_humanreadable(1));
|
||||
$this->assertEquals('1 000 B', filter::size_humanreadable(1000));
|
||||
$this->assertEquals('1.00 kiB', filter::size_humanreadable(1024));
|
||||
$this->assertEquals('1.21 kiB', filter::size_humanreadable(1234));
|
||||
$this->assertEquals('1.00 KiB', filter::size_humanreadable(1024));
|
||||
$this->assertEquals('1.21 KiB', filter::size_humanreadable(1234));
|
||||
$exponent = 1024;
|
||||
$this->assertEquals('1 000.00 kiB', filter::size_humanreadable(1000 * $exponent));
|
||||
$this->assertEquals('1 000.00 KiB', filter::size_humanreadable(1000 * $exponent));
|
||||
$this->assertEquals('1.00 MiB', filter::size_humanreadable(1024 * $exponent));
|
||||
$this->assertEquals('1.21 MiB', filter::size_humanreadable(1234 * $exponent));
|
||||
$exponent *= 1024;
|
||||
|
||||
30
tst/i18n.php
30
tst/i18n.php
@@ -25,11 +25,39 @@ class i18nTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($messageId, i18n::_($messageId), 'fallback to en');
|
||||
}
|
||||
|
||||
public function testBrowserLanguageDetection()
|
||||
public function testBrowserLanguageDeDetection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals($this->_translations['en'], i18n::_('en'), 'browser language de');
|
||||
$this->assertEquals('0 Stunden', i18n::_('%d hours', 0), '0 hours in german');
|
||||
$this->assertEquals('1 Stunde', i18n::_('%d hours', 1), '1 hour in german');
|
||||
$this->assertEquals('2 Stunden', i18n::_('%d hours', 2), '2 hours in french');
|
||||
}
|
||||
|
||||
public function testBrowserLanguageFrDetection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-CH,fr;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals('fr', i18n::_('en'), 'browser language fr');
|
||||
$this->assertEquals('0 heure', i18n::_('%d hours', 0), '0 hours in french');
|
||||
$this->assertEquals('1 heure', i18n::_('%d hours', 1), '1 hour in french');
|
||||
$this->assertEquals('2 heures', i18n::_('%d hours', 2), '2 hours in french');
|
||||
}
|
||||
|
||||
public function testBrowserLanguagePlDetection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'pl;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals('pl', i18n::_('en'), 'browser language pl');
|
||||
$this->assertEquals('2 godzina', i18n::_('%d hours', 2), 'hours in polish');
|
||||
}
|
||||
|
||||
public function testBrowserLanguageAnyDetection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = '*';
|
||||
i18n::loadTranslations();
|
||||
$this->assertTrue(strlen(i18n::_('en')) == 2, 'browser language any');
|
||||
}
|
||||
|
||||
public function testVariableInjection()
|
||||
|
||||
@@ -108,23 +108,6 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content = ob_get_contents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConfMissingExpireLabel()
|
||||
{
|
||||
$this->reset();
|
||||
$options = parse_ini_file($this->_conf, true);
|
||||
$options['expire_options']['foobar123'] = 10;
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
ini_set('magic_quotes_gpc', 1);
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
@@ -461,7 +444,9 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment);
|
||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists before posting data');
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST['parentid'] = self::$pasteid;
|
||||
@@ -747,9 +732,12 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->reset();
|
||||
$expiredPaste = self::$paste;
|
||||
$expiredPaste['meta']['expire_date'] = $expiredPaste['meta']['postdate'];
|
||||
$expiredPaste['meta']['expire_date'] = 1000;
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not exist before being created');
|
||||
$this->_model->create(self::$pasteid, $expiredPaste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$_GET['deletetoken'] = 'does not matter in this context, but has to be set';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
|
||||
Reference in New Issue
Block a user