1<?php 2 3namespace dokuwiki\plugin\farmsync\test\mock; 4 5class FarmSyncUtil extends \dokuwiki\plugin\farmsync\meta\FarmSyncUtil { 6 7 public $receivedWriteCalls; 8 public $receivedPageWriteCalls; 9 private $remoteData; 10 11 function __construct() { 12 $this->receivedWriteCalls = array(); 13 $this->receivedPageWriteCalls = array(); 14 } 15 16 /** 17 * @param string $animal 18 * @param string $page 19 * @param bool $exists 20 */ 21 public function setPageExists($animal, $page, $exists) { 22 $this->remoteData[$animal][$page]['exists'] = $exists; 23 } 24 25 public function setAnimalDataDir($animal, $dir) { 26 $this->remoteData[$animal]['datadir'] = $dir; 27 } 28 29 public function getAnimalDataDir($animal) { 30 return isset($this->remoteData[$animal]['datadir']) ? $this->remoteData[$animal]['datadir'] : '/var/www/farm/' . $animal . '/data/'; 31 } 32 33 34 public function remotePageExists($animal, $page, $clean = true) { 35 return isset($this->remoteData[$animal][$page]['exists']) ? $this->remoteData[$animal][$page]['exists'] : parent::remotePageExists($animal, $page, $clean); 36 } 37 38 public function replaceRemoteFile($remoteFile, $content, $timestamp = 0) { 39 $this->receivedWriteCalls[] = array( 40 'remoteFile' => $remoteFile, 41 'content' => $content, 42 'timestamp' => $timestamp 43 ); 44 } 45 46 public function setCommonAncestor($source, $animal, $page, $content) { 47 $this->remoteData[$source][$animal][$page]['commonAncestor'] = $content; 48 } 49 50 public function findCommonAncestor($page, $source, $target) { 51 return isset($this->remoteData[$source][$target][$page]['commonAncestor']) ? $this->remoteData[$source][$target][$page]['commonAncestor'] : parent::findCommonAncestor($page, $source, $target); 52 } 53 54 55 public function saveRemotePage($animal, $page, $content, $timestamp = false) { 56 $this->receivedPageWriteCalls[] = array( 57 'animal' => $animal, 58 'page' => $page, 59 'content' => $content, 60 'timestamp' => $timestamp 61 ); 62 } 63 64 public function setPagemtime($animal, $page, $timestamp) { 65 $this->remoteData[$animal][$page]['mtime'] = $timestamp; 66 } 67 68 69 public function getRemoteFilemtime($animal, $page, $ismedia = false, $clean = true) { 70 return isset($this->remoteData[$animal][$page]['mtime']) ? $this->remoteData[$animal][$page]['mtime'] : parent::getRemoteFilemtime($animal, $page, $ismedia, $clean); 71 } 72 73 public function setPageContent($animal, $page, $content) { 74 $this->remoteData[$animal][$page]['content'] = $content; 75 } 76 77 public function readRemotePage($animal, $page, $clean = true, $timestamp = null) { 78 return isset($this->remoteData[$animal][$page]['content']) ? $this->remoteData[$animal][$page]['content'] : parent::readRemotePage($animal, $page, $clean, $timestamp); 79 } 80 81 82} 83