78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Ratelimitfile;
|
|
|
|
/** Test the Ratelimitfile.php file */
|
|
class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testRatelimitfile0()
|
|
{
|
|
exec("rm -rf /tmp/testDFWratelimit");
|
|
}
|
|
|
|
public function testRatelimitfile1()
|
|
{
|
|
// Create one non ratelimited entry
|
|
$ratelimitfile = new Ratelimitfile();
|
|
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
|
$res = $ratelimitfile->set("TOTO");
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testRatelimitfile2()
|
|
{
|
|
// Too much entries
|
|
$ratelimitfile = new Ratelimitfile();
|
|
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$ratelimitfile->set("TOTO");
|
|
$res = $ratelimitfile->set("TOTO");
|
|
$this->assertSame(false, $res);
|
|
}
|
|
|
|
public function testRatelimitfile3()
|
|
{
|
|
// Del the ratelimited entry
|
|
$ratelimitfile = new Ratelimitfile();
|
|
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
|
$res = $ratelimitfile->del("TOTO");
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testRatelimitfile4()
|
|
{
|
|
// Create one non ratelimited entry
|
|
$ratelimitfile = new Ratelimitfile();
|
|
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
|
$res = $ratelimitfile->set("TOTO");
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testRatelimitfile5()
|
|
{
|
|
// Clean expired entries
|
|
sleep(2);
|
|
$ratelimitfile = new Ratelimitfile();
|
|
$ratelimitfile->unittime = 1;
|
|
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
|
$ratelimitfile->clean();
|
|
$res = count(glob("/tmp/testDFWratelimit/*"));
|
|
$this->assertSame(0, $res);
|
|
}
|
|
}
|