1<?php 2 3namespace dokuwiki\plugin\farmsync\test; 4 5/** 6 * FIXME: findCommonAncestor could use some more tests for old animalrevision == current source revision and for the case that $atticdir does not exist 7 * 8 * @group plugin_farmsync 9 * @group plugins 10 * @author Michael Große <grosse@cosmocode.de> 11 * 12 */ 13class findCommonAncestor_farmsync_test extends \DokuWikiTest { 14 15 protected $pluginsEnabled = array('farmsync',); 16 17 public static function setUpBeforeClass() { 18 parent::setUpBeforeClass(); 19 $sourcedir = substr(DOKU_TMP_DATA, 0, -1) . '_source/'; 20 $targetdir = substr(DOKU_TMP_DATA, 0, -1) . '_target/'; 21 mkdir($targetdir); 22 mkdir($targetdir . 'attic'); 23 mkdir($targetdir . 'pages'); 24 mkdir($sourcedir); 25 mkdir($sourcedir . 'attic'); 26 mkdir($sourcedir . 'pages'); 27 28 io_saveFile($sourcedir . 'pages/test/page.txt', "ABCX\n\nDEF\n"); 29 io_saveFile($sourcedir . 'attic/test/page.1400000000.txt.gz', "ABC\n\nDEF\n"); 30 io_saveFile($targetdir . 'attic/test/page.1400000000.txt.gz', "ABC\n\nDEF\n"); 31 io_saveFile($targetdir . 'pages/test/page.txt', "ABCY\n\nDEF\n"); 32 33 io_saveFile($sourcedir . 'pages/test/page_noc.txt', "ABCX\n\nDEF\n"); 34 io_saveFile($targetdir . 'attic/test/page_noc.1400000000.txt.gz', "ABC\n\nDEF\n"); 35 io_saveFile($targetdir . 'attic/test/page_noc.1400000001.txt.gz', "ABC\nZ\nDEF\n"); 36 io_saveFile($targetdir . 'pages/test/page_noc.txt', "ABCY\n\nDEF\n"); 37 38 } 39 40 41 public function test_simpleCommonAncestor() { 42 // arrange 43 $mock_farm_util = new mock\FarmSyncUtil(); 44 $sourceanimal = 'sourceanimal'; 45 46 $sourcedir = substr(DOKU_TMP_DATA, 0, -1) . '_source/'; 47 $targetdir = substr(DOKU_TMP_DATA, 0, -1) . '_target/'; 48 $testanimal = 'testanimal'; 49 $mock_farm_util->setAnimalDataDir($testanimal, $targetdir); 50 $mock_farm_util->setAnimalDataDir($sourceanimal, $sourcedir); 51 $testpage = "test:page"; 52 53 // act 54 $actual_common_ancestor = $mock_farm_util->findCommonAncestor($testpage, $sourceanimal, $testanimal); 55 56 // assert 57 $this->assertEquals("ABC\n\nDEF\n", $actual_common_ancestor); 58 } 59 60 public function test_noCommonAncestor() { 61 // arrange 62 $mock_farm_util = new mock\FarmSyncUtil(); 63 $sourceanimal = 'sourceanimal'; 64 65 $sourcedir = substr(DOKU_TMP_DATA, 0, -1) . '_source/'; 66 $targetdir = substr(DOKU_TMP_DATA, 0, -1) . '_target/'; 67 $testanimal = 'testanimal'; 68 $mock_farm_util->setAnimalDataDir($testanimal, $targetdir); 69 $mock_farm_util->setAnimalDataDir($sourceanimal, $sourcedir); 70 $testpage = "test:page_noc"; 71 72 // act 73 $actual_common_ancestor = $mock_farm_util->findCommonAncestor($testpage, $sourceanimal, $testanimal); 74 75 // assert 76 $this->assertEquals("", $actual_common_ancestor); 77 } 78} 79