wrote a unit test to generate old style pastes and comments and check that the purge converts them to PHP files
This commit is contained in:
parent
4ded4b7f8c
commit
577586c47f
1 changed files with 42 additions and 0 deletions
|
@ -130,4 +130,46 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertFalse($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), $comment), 'unable to store broken comment');
|
$this->assertFalse($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), $comment), 'unable to store broken comment');
|
||||||
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does still not exist');
|
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does still not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOldFilesGetConverted()
|
||||||
|
{
|
||||||
|
// generate 10 (default purge batch size) pastes in the old format
|
||||||
|
$paste = Helper::getPaste();
|
||||||
|
$comment = Helper::getComment();
|
||||||
|
$commentid = Helper::getCommentId();
|
||||||
|
$ids = array();
|
||||||
|
for ($i = 0, $max = 10; $i < $max; ++$i) {
|
||||||
|
// PHPs mt_rand only supports 32 bit or up 0x7fffffff on 64 bit systems to be precise :-/
|
||||||
|
$dataid = str_pad(dechex(mt_rand(0, mt_getrandmax())), 8, '0', STR_PAD_LEFT) .
|
||||||
|
str_pad(dechex(mt_rand(0, mt_getrandmax())), 8, '0', STR_PAD_LEFT);
|
||||||
|
$storagedir = $this->_path . DIRECTORY_SEPARATOR . substr($dataid, 0, 2) .
|
||||||
|
DIRECTORY_SEPARATOR . substr($dataid, 2, 2) . DIRECTORY_SEPARATOR;
|
||||||
|
$ids[$dataid] = $storagedir;
|
||||||
|
|
||||||
|
if (!is_dir($storagedir)) {
|
||||||
|
mkdir($storagedir, 0700, true);
|
||||||
|
}
|
||||||
|
file_put_contents($storagedir . $dataid, json_encode($paste));
|
||||||
|
|
||||||
|
$storagedir .= $dataid . '.discussion' . DIRECTORY_SEPARATOR;
|
||||||
|
if (!is_dir($storagedir)) {
|
||||||
|
mkdir($storagedir, 0700, true);
|
||||||
|
}
|
||||||
|
file_put_contents($storagedir . $dataid . '.' . $commentid . '.' . $dataid, json_encode($comment));
|
||||||
|
}
|
||||||
|
// check that all 10 pastes were converted after the purge
|
||||||
|
$this->_model->purge(10);
|
||||||
|
foreach ($ids as $dataid => $storagedir) {
|
||||||
|
$this->assertFileExists($storagedir . $dataid . '.php', "paste $dataid exists in new format");
|
||||||
|
$this->assertFileNotExists($storagedir . $dataid, "old format paste $dataid got removed");
|
||||||
|
$this->assertTrue($this->_model->exists($dataid), "paste $dataid exists");
|
||||||
|
$this->assertEquals($this->_model->read($dataid), $paste, "paste $dataid wasn't modified in the conversion");
|
||||||
|
|
||||||
|
$storagedir .= $dataid . '.discussion' . DIRECTORY_SEPARATOR;
|
||||||
|
$this->assertFileExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid . '.php', "comment of $dataid exists in new format");
|
||||||
|
$this->assertFileNotExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed");
|
||||||
|
$this->assertTrue($this->_model->existsComment($dataid, $dataid, $commentid), "comment in paste $dataid exists");
|
||||||
|
$this->assertEquals($this->_model->readComment($dataid, $dataid, $commentid), $comment, "comment of $dataid wasn't modified in the conversion");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue