2016-08-09 17:54:42 +08:00
|
|
|
<?php
|
|
|
|
|
2020-10-10 18:08:58 +08:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-06-08 03:53:42 +08:00
|
|
|
use PrivateBin\Data\Filesystem;
|
2016-08-09 17:54:42 +08:00
|
|
|
use PrivateBin\Persistence\PurgeLimiter;
|
|
|
|
|
2020-10-10 18:08:58 +08:00
|
|
|
class PurgeLimiterTest extends TestCase
|
2016-08-09 17:54:42 +08:00
|
|
|
{
|
|
|
|
private $_path;
|
|
|
|
|
2020-10-10 18:22:20 +08:00
|
|
|
public function setUp(): void
|
2016-08-09 17:54:42 +08:00
|
|
|
{
|
|
|
|
/* Setup Routine */
|
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
|
|
|
if (!is_dir($this->_path)) {
|
|
|
|
mkdir($this->_path);
|
|
|
|
}
|
2021-06-08 03:53:42 +08:00
|
|
|
PurgeLimiter::setStore(
|
|
|
|
Filesystem::getInstance(array('dir' => $this->_path))
|
|
|
|
);
|
2016-08-09 17:54:42 +08:00
|
|
|
}
|
|
|
|
|
2020-10-10 18:22:20 +08:00
|
|
|
public function tearDown(): void
|
2016-08-09 17:54:42 +08:00
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
|
|
|
Helper::rmDir($this->_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLimit()
|
|
|
|
{
|
|
|
|
// initialize it
|
2018-07-29 22:05:57 +08:00
|
|
|
PurgeLimiter::setLimit(1);
|
2016-08-09 17:54:42 +08: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());
|
|
|
|
}
|
|
|
|
}
|