1<?php 2/** 3 * Unit tests for Conflict Merger Plugin for Dokuwiki 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Daniel Calviño Sánchez <danxuliu@gmail.com> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10require_once(DOKU_INC.'lib/plugins/conflictmerger/action.php'); 11 12require_once(DOKU_INC.'inc/utf8.php'); 13 14//TODO Necessary to be run from the browser, but... is this the proper way to do it? 15global $conf; 16if (!isset($conf['datadir'])) $conf['datadir'] = DOKU_INC . $conf['savedir'].'/pages'; 17 18class Merge_test extends UnitTestCase { 19 20 var $id = 'testmerge'; 21 var $action; 22 23 function setUp() { 24 $this->action = new action_plugin_conflictmerger(); 25 } 26 27 function getBasename() { 28 return wikiFN($this->id); 29 } 30 31 function testMerge() { 32 $old = "First paragraph\n\nSecond paragraph\n\nThird paragraph"; 33 $mine = "First paragraph modified by user 1\n\nSecond paragraph\n\nThird paragraph"; 34 $yours = "First paragraph\n\nSecond paragraph modified by user 2\n\nThird paragraph"; 35 $result; 36 37 $this->assertTrue($this->action->merge($this->id, $old, $mine, $yours, $result)); 38 $this->assertEqual("First paragraph modified by user 1\n\nSecond paragraph modified by user 2\n\nThird paragraph", $result); 39 40 $this->assertFalse(file_exists($this->getBasename() . '-merge-mine')); 41 $this->assertFalse(file_exists($this->getBasename() . '-merge-old')); 42 $this->assertFalse(file_exists($this->getBasename() . '-merge-your')); 43 } 44 45 function testMergeConflictSingleLine() { 46 $old = "A bunch of words in a single line"; 47 $mine = "A bunch of words edited by user 1 in a single line"; 48 $yours = "A bunch of words in a single line edited by user 2"; 49 $result = ''; 50 51 $this->assertFalse($this->action->merge($this->id, $old, $mine, $yours, $result)); 52 $this->assertNotEqual('', $result); 53 54 $this->assertFalse(file_exists($this->getBasename() . '-merge-mine')); 55 $this->assertFalse(file_exists($this->getBasename() . '-merge-old')); 56 $this->assertFalse(file_exists($this->getBasename() . '-merge-your')); 57 } 58 59 function testMergeConflict() { 60 $old = "First paragraph\n\nSecond paragraph\n\nThird paragraph"; 61 $mine = "First paragraph modified by user 1\n\nSecond paragraph\n\nThird paragraph"; 62 $yours = "First paragraph modified by user 2\n\nSecond paragraph\n\nThird paragraph"; 63 $result = ''; 64 65 $this->assertFalse($this->action->merge($this->id, $old, $mine, $yours, $result)); 66 $this->assertNotEqual('', $result); 67 68 $this->assertFalse(file_exists($this->getBasename() . '-merge-mine')); 69 $this->assertFalse(file_exists($this->getBasename() . '-merge-old')); 70 $this->assertFalse(file_exists($this->getBasename() . '-merge-your')); 71 } 72 73 function testMergeFailureEmptyDiff3() { 74 global $conf; 75 $temporalDiff3 = $conf['plugin']['conflictmerger']['diff3']; 76 $conf['plugin']['conflictmerger']['diff3'] = ''; 77 78 $old = "First paragraph\n\nSecond paragraph\n\nThird paragraph"; 79 $mine = "First paragraph modified by user 1\n\nSecond paragraph\n\nThird paragraph"; 80 $yours = "First paragraph\n\nSecond paragraph modified by user 2\n\nThird paragraph"; 81 $result = "Previous value"; 82 83 $this->assertFalse($this->action->merge($this->id, $old, $mine, $yours, $result)); 84 $this->assertEqual('', $result); 85 86 $this->assertFalse(file_exists($this->getBasename() . '-merge-mine')); 87 $this->assertFalse(file_exists($this->getBasename() . '-merge-old')); 88 $this->assertFalse(file_exists($this->getBasename() . '-merge-your')); 89 90 $conf['plugin']['conflictmerger']['diff3'] = $temporalDiff3; 91 } 92 93 function testMergeFailureWrongDiff3Path() { 94 global $conf; 95 $temporalDiff3 = $conf['plugin']['conflictmerger']['diff3']; 96 $conf['plugin']['conflictmerger']['diff3'] = '/a/path/where/you/are/not/likely/to/have/diff3'; 97 98 $old = "First paragraph\n\nSecond paragraph\n\nThird paragraph"; 99 $mine = "First paragraph modified by user 1\n\nSecond paragraph\n\nThird paragraph"; 100 $yours = "First paragraph\n\nSecond paragraph modified by user 2\n\nThird paragraph"; 101 $result = "Previous value"; 102 103 $this->assertFalse($this->action->merge($this->id, $old, $mine, $yours, $result)); 104 $this->assertEqual('', $result); 105 106 $this->assertFalse(file_exists($this->getBasename() . '-merge-mine')); 107 $this->assertFalse(file_exists($this->getBasename() . '-merge-old')); 108 $this->assertFalse(file_exists($this->getBasename() . '-merge-your')); 109 110 $conf['plugin']['conflictmerger']['diff3'] = $temporalDiff3; 111 } 112} 113 114//Setup VIM: ex: et ts=4 enc=utf-8 : 115