Skip to content

Commit

Permalink
Merge pull request #237 from splitbrain/changelogtestsonly
Browse files Browse the repository at this point in the history
Added tests for getRevisions and getRevisionInfo from page changelog
  • Loading branch information
splitbrain committed Aug 4, 2013
2 parents 9ead677 + 7d8f322 commit f1d14ca
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 0 deletions.
24 changes: 24 additions & 0 deletions _test/data/meta/mailinglist.changes
@@ -0,0 +1,24 @@
1360110636 127.0.0.1 C mailinglist pubcie aangemaakt
1361901536 127.0.0.1 E mailinglist pubcie
1362524799 127.0.0.1 E mailinglist pubcie
1362525145 127.0.0.1 E mailinglist pubcie
1362525359 127.0.0.1 E mailinglist pubcie [Data entry]
1362525899 127.0.0.1 E mailinglist pubcie [Data entry]
1362525926 127.0.0.1 E mailinglist pubcie
1362526039 127.0.0.1 E mailinglist pubcie [Data entry]
1362526119 127.0.0.1 E mailinglist pubcie
1362526167 127.0.0.1 E mailinglist pubcie [Data entry]
1362526767 127.0.0.1 E mailinglist pubcie [Data entry]
1362526861 127.0.0.1 E mailinglist pubcie [Data entry]
1362527046 127.0.0.1 E mailinglist pubcie [Data entry]
1362527164 127.0.0.1 E mailinglist pubcie [Data entry]
1363436892 127.0.0.1 E mailinglist pubcie
1368575634 127.0.0.1 E mailinglist pubcie
1368609772 127.0.0.1 E mailinglist pubcie
1368612506 127.0.0.1 E mailinglist pubcie [Data entry]
1368612599 127.0.0.1 E mailinglist pubcie [Data entry]
1368622152 127.0.0.1 E mailinglist pubcie [Data entry]
1368622195 127.0.0.1 E mailinglist pubcie
1368622240 127.0.0.1 E mailinglist pubcie [Data entry]
1371579614 127.0.0.1 E mailinglist pubcie
1374261194 127.0.0.1 E mailinglist pubcie
11 changes: 11 additions & 0 deletions _test/data/pages/mailinglist.txt
@@ -0,0 +1,11 @@
====== Mailing Lists ======

[[DokuWiki]]'s development is coordinated through multiple Mailinglists hosted by [[http://www.freelists.org|freelists.org]].

===== Using the lists =====

First you should subscribe to one or several of the mailing lists presented below. After subscribing you can send emails to the list(s) by using the mailing list address stated in its description. If you rather want to use the mailing list through a news group interface, please read the section [[#News group interface]].

If you are new to mailing lists in general, please read [[rfc>1855|RFC 1855 - Netiquette Guidelines]], especially the sections 3.1.1 and 3.1.2. Before you ask any questions you should also have a look at [[http://www.catb.org/~esr/faqs/smart-questions.html|How To Ask Questions The Smart Way]].

:!: Please note that these documents are linked here solely for the purpose of information. Their respective authors have nothing do to with [[DokuWiki]] and in **no case** should you send email to them, asking for help related to [[DokuWiki]]!
120 changes: 120 additions & 0 deletions _test/tests/inc/changelog_getrevisioninfo.test.php
@@ -0,0 +1,120 @@
<?php

/**
* Tests for requesting revisioninfo of a revision of a page with getRevisionInfo()
*
* This class uses the files:
* - data/pages/mailinglist.txt
* - data/meta/mailinglist.changes
*/
class changelog_getrevisionsinfo_test extends DokuWikiTest {

private $logline = "1362525899 127.0.0.1 E mailinglist pubcie [Data entry] \n";
private $firstlogline = "1374261194 127.0.0.1 E mailinglist pubcie \n";
private $pageid = 'mailinglist';

function setup() {
parent::setup();
global $cache_revinfo;
$cache =& $cache_revinfo;
if(isset($cache['nonexist'])) {
unset($cache['nonexist']);
}
if(isset($cache['mailinglist'])) {
unset($cache['nonexist']);
}
}

/**
* no nonexist.changes meta file available
*/
function test_changemetadatanotexists() {
$rev = 1362525899;
$id = 'nonexist';
$revsexpected = false;

$revs = getRevisionInfo($id, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* request existing rev
*/
function test_requestrev() {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals($infoexpected, $info);
//returns cached value
$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals($infoexpected, $info);
}

/**
* request existing rev with chucked reading
*/
function test_requestrev_chuncked() {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 512, $media = false);
$this->assertEquals($infoexpected, $info);
}

/**
* request current version
*/
function test_requestrecentestlogline() {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals($infoexpected, $info);
//returns cached value
$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals($infoexpected, $info);
}

/**
* request current version, with chuncked reading
*/
function test_requestrecentestlogline_chuncked() {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 512, $media = false);
$this->assertEquals($infoexpected, $info);
}

/**
* request negative revision
*/
function test_negativerev() {
$rev = -10;

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals(false, $info);
}

/**
* request non existing revision somewhere between existing revisions
*/
function test_notexistingrev() {
$rev = 1362525890;

$info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
$this->assertEquals(false, $info);
}

/**
* sometimes chuncksize is set to true
*/
function test_chuncksizetrue() {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);

$info = getRevisionInfo($this->pageid, $rev, true);
$this->assertEquals($infoexpected, $info);
}
}
200 changes: 200 additions & 0 deletions _test/tests/inc/changelog_getrevisions.test.php
@@ -0,0 +1,200 @@
<?php
/**
* Tests for requesting revisions of a page with getRevisions()
*
* This class uses the files:
* - data/pages/mailinglist.txt
* - data/meta/mailinglist.changes
*/
class changelog_getrevisions_test extends DokuWikiTest {

/**
* $first counts inclusive zero, after the current page
*/
private $revsexpected = array(
1374261194, //current page
1371579614, 1368622240, // revisions, corresponds to respectively $first = 0 and 1
1368622195, 1368622152,
1368612599, 1368612506,
1368609772, 1368575634,
1363436892, 1362527164,
1362527046, 1362526861, //10 and 11
1362526767, 1362526167,
1362526119, 1362526039,
1362525926, 1362525899,
1362525359, 1362525145,
1362524799, 1361901536, //20 and 21
1360110636
);
private $pageid = 'mailinglist';

function setup() {
parent::setup();
global $cache_revinfo;
$cache =& $cache_revinfo;
if(isset($cache['nonexist'])) {
unset($cache['nonexist']);
}
if(isset($cache['mailinglist'])) {
unset($cache['nonexist']);
}
}

/**
* no nonexist.changes meta file available
*/
function test_changemetadatanotexists() {
$first = 0;
$num = 1;
$id = 'nonexist';

$revs = getRevisions($id, $first, $num, $chunk_size = 8192, $media = false);
$revsexpected = array();
$this->assertEquals($revsexpected, $revs);
}

/**
* request first recentest revision
* (so skips first line which belongs to the current existing page)
*/
function test_requestlastrev() {
$first = 0;
$num = 1;
$revsexpected = array($this->revsexpected[1]);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* request first recentest revision
* (so skips first line which belongs to the current existing page)
*/
function test_requestonebutlastrev() {
$first = 1;
$num = 1;
$revsexpected = array($this->revsexpected[2]);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* request first recentest revision
* (so skips first line of current existing page)
*/
function test_requestrevswithoffset() {
$first = 10;
$num = 5;
$revsexpected = array_slice($this->revsexpected, $first + 1, $num);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* first = -1 requests recentest logline, without skipping
*/
function test_requestrecentestlogline() {
$first = -1;
$num = 1;
$revsexpected = array($this->revsexpected[0]);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* chunck size = 0 skips chuncked loading
*/
function test_wholefile() {
$first = 0;
$num = 1000;
$revsexpected = array_slice($this->revsexpected, 1);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 0, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* Negative range returns no result
*/
function test_negativenum() {
$first = 0;
$num = -10;
$revsexpected = array();

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* Negative range returns no result
*/
function test_negativennumoffset() {
$first = 2;
$num = -10;
$revsexpected = array();

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* zero range returns no result
*/
function test_zeronum() {
$first = 5;
$num = 0;
$revsexpected = array();

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* get oldest revisions
*/
function test_requestlargeoffset() {
$first = 22;
$num = 50;
$revsexpected = array_slice($this->revsexpected, $first + 1);

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);
}

/**
* request with too large offset and range
*/
function test_requesttoolargenumberrevs() {
$first = 50;
$num = 50;
$revsexpected = array();

$revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);
}

}
2 changes: 2 additions & 0 deletions inc/changelog.php
Expand Up @@ -460,6 +460,8 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
$file = metaFN($id, '.changes');
}
$num = max($num, 0);
if ($num == 0) { return $revs; }

$chunk_size = max($chunk_size, 0);
if ($first<0) {
$first = 0;
Expand Down

0 comments on commit f1d14ca

Please sign in to comment.