mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-12-24 23:09:28 -05:00
turning Filter::formatHumanReadableTime() test case into property based one, clarifying the allowed units
This commit is contained in:
parent
e41f0a7561
commit
79dafd5af4
@ -39,7 +39,9 @@ class Filter
|
||||
/**
|
||||
* format a given time string into a human readable label (localized)
|
||||
*
|
||||
* accepts times in the format "[integer][time unit]"
|
||||
* accepts times in the format "[integer][time unit]", valid time units are:
|
||||
* sec, second, seconds, min, minute, minutes, hour, hours, day, days, week,
|
||||
* weeks, month, months, year, years
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
use PrivateBin\Filter;
|
||||
use Eris\Generator;
|
||||
|
||||
class FilterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
use Eris\TestTrait;
|
||||
|
||||
public function testFilterStripsSlashesDeeply()
|
||||
{
|
||||
$this->assertEquals(
|
||||
@ -14,10 +17,43 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFilterMakesTimesHumanlyReadable()
|
||||
{
|
||||
$this->assertEquals('5 minutes', Filter::formatHumanReadableTime('5min'));
|
||||
$this->assertEquals('90 seconds', Filter::formatHumanReadableTime('90sec'));
|
||||
$this->assertEquals('1 week', Filter::formatHumanReadableTime('1week'));
|
||||
$this->assertEquals('6 months', Filter::formatHumanReadableTime('6months'));
|
||||
$this->forAll(
|
||||
Generator\nat(),
|
||||
Generator\oneOf(
|
||||
'sec', 'second', 'seconds'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' second' . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\nat(),
|
||||
Generator\oneOf(
|
||||
'min', 'minute', 'minutes'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' minute' . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\nat(),
|
||||
Generator\oneOf(
|
||||
'hour', 'hours', 'day', 'days', 'week', 'weeks',
|
||||
'month', 'months', 'year', 'years'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' ' . rtrim($unit, 's') . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,16 +41,14 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||
$vz = new Vizhash16x16();
|
||||
$pngdata = $vz->generate($string1);
|
||||
|
||||
if (empty($string1))
|
||||
{
|
||||
if (empty($string1)) {
|
||||
$this->assertEquals($pngdata, '');
|
||||
} else {
|
||||
$this->assertNotEquals($pngdata, '');
|
||||
file_put_contents($this->_file, $pngdata);
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$this->assertEquals('image/png', $finfo->file($this->_file));
|
||||
if ($string1 !== $string2)
|
||||
{
|
||||
if ($string1 !== $string2) {
|
||||
$this->assertNotEquals($pngdata, $string2);
|
||||
}
|
||||
}
|
||||
@ -73,8 +71,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||
file_put_contents($this->_file, $pngdata);
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$this->assertEquals('image/png', $finfo->file($this->_file));
|
||||
if ($hash1 !== $hash2)
|
||||
{
|
||||
if ($hash1 !== $hash2) {
|
||||
$this->assertNotEquals($pngdata, $vz->generate($hash2));
|
||||
}
|
||||
$this->assertEquals($pngdata, $vz->generate($hash1));
|
||||
@ -96,8 +93,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||
file_put_contents($this->_file, $pngdata);
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$this->assertEquals('image/png', $finfo->file($this->_file));
|
||||
if ($hash1 !== $hash2)
|
||||
{
|
||||
if ($hash1 !== $hash2) {
|
||||
$this->assertNotEquals($pngdata, $vz->generate($hash2));
|
||||
}
|
||||
$this->assertEquals($pngdata, $vz->generate($hash1));
|
||||
|
Loading…
Reference in New Issue
Block a user