introducing automatic purging of expired pastes, triggered by default at least 5 minutes apart, deleting a maximum of 10 pastes - resolves #3

This commit is contained in:
El RIDO
2016-07-15 17:02:59 +02:00
parent 4d10fd9690
commit f8bc40b4e4
13 changed files with 404 additions and 12 deletions

View File

@@ -63,4 +63,37 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase
$this->assertEquals(json_decode(json_encode($original)), $this->_model->read(helper::getPasteId()));
}
public function testPurge()
{
$expired = helper::getPaste(array('expire_date' => 1344803344));
$paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array();
foreach ($keys as $key)
{
$ids[$key] = substr(md5($key), 0, 16);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z')))
{
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
}
else
{
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
}
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
}
$this->_model->purge(10);
foreach ($ids as $key => $id)
{
if (in_array($key, array('x', 'y', 'z')))
{
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after purge");
}
else
{
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key was purged");
}
}
}
}