Skip to content

Commit

Permalink
Added more testing to ensure correct handling of delayed writes
Browse files Browse the repository at this point in the history
  • Loading branch information
michitux committed Jan 1, 2017
1 parent 2e38f57 commit ea466a9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions _test/tests/inc/common_saveWikiText.test.php
@@ -1,6 +1,12 @@
<?php

class common_saveWikiText_test extends DokuWikiTest {
/** Delay writes of old revisions by a second. */
public function handle_write(Doku_Event $event, $param) {
if ($event->data[3] !== false) {
$this->waitForTick();
}
}

/**
* Execute a whole bunch of saves on the same page and check the results
Expand All @@ -24,6 +30,7 @@ function test_savesequence() {
$this->assertEquals('first save', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_CREATE, $revinfo['type']);
$this->assertEquals(10, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

$this->waitForTick(true); // wait for new revision ID

Expand Down Expand Up @@ -100,6 +107,7 @@ function test_savesequence() {
$this->assertEquals('sixth save', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_DELETE, $revinfo['type']);
$this->assertEquals(-11, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

$this->waitForTick(); // wait for new revision ID

Expand All @@ -120,6 +128,7 @@ function test_savesequence() {
$this->assertEquals(DOKU_CHANGE_TYPE_REVERT, $revinfo['type']);
$this->assertEquals($REV, $revinfo['extra']);
$this->assertEquals(11, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));
$REV = '';

$this->waitForTick(); // wait for new revision ID
Expand Down Expand Up @@ -155,6 +164,12 @@ function test_savesequence() {
* Execute a whole bunch of saves on the same page and check the results
*/
function test_savesequencedeleteexternalrevision() {
// add an additional delay when saving files to make sure
// nobody relies on the saving happening in the same second
/** @var $EVENT_HANDLER Doku_Event_Handler */
global $EVENT_HANDLER;
$EVENT_HANDLER->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'handle_write');

$page = 'page2';
$file = wikiFN($page);

Expand All @@ -171,6 +186,7 @@ function test_savesequencedeleteexternalrevision() {
$this->assertEquals('first save', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_CREATE, $revinfo['type']);
$this->assertEquals(10, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

$this->waitForTick(true); // wait for new revision ID

Expand All @@ -186,6 +202,7 @@ function test_savesequencedeleteexternalrevision() {
$this->assertEquals('second save', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_DELETE, $revinfo['type']);
$this->assertEquals(-10, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

$this->waitForTick(); // wait for new revision ID

Expand All @@ -205,11 +222,13 @@ function test_savesequencedeleteexternalrevision() {
$this->assertEquals('third save', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']);
$this->assertEquals(0, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

$revinfo = $pagelog->getRevisionInfo($revisions[1]);
$this->assertEquals('external edit', $revinfo['sum']);
$this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']);
$this->assertEquals(11, $revinfo['sizechange']);
$this->assertFileExists(wikiFN($page, $revinfo['date']));

}

Expand Down

0 comments on commit ea466a9

Please sign in to comment.