2016-08-09 09:54:42 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-09 09:54:42 +00:00
|
|
|
use PrivateBin\Persistence\PurgeLimiter;
|
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
class PurgeLimiterTest extends TestCase
|
2016-08-09 09:54:42 +00:00
|
|
|
{
|
|
|
|
private $_path;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
/* Setup Routine */
|
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
|
|
|
if (!is_dir($this->_path)) {
|
|
|
|
mkdir($this->_path);
|
|
|
|
}
|
|
|
|
PurgeLimiter::setPath($this->_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
|
|
|
Helper::rmDir($this->_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLimit()
|
|
|
|
{
|
|
|
|
// initialize it
|
2018-07-29 14:05:57 +00:00
|
|
|
PurgeLimiter::setLimit(1);
|
2016-08-09 09:54:42 +00:00
|
|
|
PurgeLimiter::canPurge();
|
|
|
|
|
|
|
|
// try setting it
|
|
|
|
$this->assertEquals(false, PurgeLimiter::canPurge());
|
|
|
|
sleep(2);
|
|
|
|
$this->assertEquals(true, PurgeLimiter::canPurge());
|
|
|
|
|
|
|
|
// disable it
|
|
|
|
PurgeLimiter::setLimit(0);
|
|
|
|
PurgeLimiter::canPurge();
|
|
|
|
$this->assertEquals(true, PurgeLimiter::canPurge());
|
|
|
|
}
|
|
|
|
}
|