You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

479 lines
18 KiB

  1. <?php
  2. // must be run within Dokuwiki
  3. if (!defined('DOKU_INC')) die();
  4. /**
  5. * Test cases for namespace move functionality of the move plugin
  6. *
  7. * @group plugin_move
  8. * @group plugins
  9. */
  10. class plugin_move_namespace_move_test extends DokuWikiTest {
  11. public function setUp(): void {
  12. $this->pluginsEnabled[] = 'move';
  13. parent::setUp();
  14. }
  15. /**
  16. * @coversNothing
  17. */
  18. public function tearDown(): void {
  19. /** @var helper_plugin_move_plan $plan */
  20. $plan = plugin_load('helper', 'move_plan');
  21. $plan->abort();
  22. io_rmdir(DOKU_TMP_DATA."pages/newns",true);
  23. io_rmdir(DOKU_TMP_DATA."media/newns",true);
  24. io_rmdir(DOKU_TMP_DATA."meta/newns",true);
  25. parent::tearDown();
  26. }
  27. /**
  28. * This is an integration test, which checks the correct working of an entire namespace move.
  29. * Hence it is not an unittest, hence it @coversNothing
  30. *
  31. * @group slow
  32. */
  33. public function test_move_wiki_namespace() {
  34. global $AUTH_ACL;
  35. $AUTH_ACL[] = "wiki:*\t@ALL\t16";
  36. idx_addPage('wiki:dokuwiki');
  37. idx_addPage('wiki:syntax');
  38. /** @var helper_plugin_move_plan $plan */
  39. $plan = plugin_load('helper', 'move_plan');
  40. $this->assertFalse($plan->inProgress());
  41. $plan->addPageNamespaceMove('wiki', 'foo');
  42. $plan->addMediaNamespaceMove('wiki', 'foo');
  43. $plan->commit();
  44. $this->assertSame(1, $plan->nextStep(),'pages');
  45. $this->assertSame(1, $plan->nextStep(),'media');
  46. $this->assertSame(1, $plan->nextStep(),'missing');
  47. $this->assertSame(1, $plan->nextStep(),'namespace');
  48. $this->assertSame(1, $plan->nextStep(),'autorewrite');
  49. $this->assertSame(0, $plan->nextStep(),'done');
  50. $this->assertFileExists(wikiFN('foo:dokuwiki'));
  51. $this->assertFileNotExists(wikiFN('wiki:syntax'));
  52. $this->assertFileExists(mediaFN('foo:dokuwiki-128.png'));
  53. }
  54. /**
  55. * This is an integration test, which checks the correct working of an entire namespace move.
  56. * Hence it is not an unittest, hence it @coversNothing
  57. *
  58. * @group slow
  59. */
  60. public function test_move_missing() {
  61. saveWikiText('oldspace:page', '[[missing]]', 'setup');
  62. idx_addPage('oldspace:page');
  63. /** @var helper_plugin_move_plan $plan */
  64. $plan = plugin_load('helper', 'move_plan');
  65. $this->assertFalse($plan->inProgress());
  66. $plan->addPageNamespaceMove('oldspace', 'newspace');
  67. $plan->commit();
  68. $this->assertSame(1, $plan->nextStep(),'page');
  69. $this->assertSame(1, $plan->nextStep(),'missing');
  70. $this->assertSame(1, $plan->nextStep(),'namespace');
  71. $this->assertSame(1, $plan->nextStep(),'autorewrite');
  72. $this->assertSame(0, $plan->nextStep(),'done');
  73. $this->assertFileExists(wikiFN('newspace:page'));
  74. $this->assertFileNotExists(wikiFN('oldspace:page'));
  75. $this->assertEquals('[[missing]]', rawWiki('newspace:page'));
  76. }
  77. /**
  78. * @covers helper_plugin_move_plan::findAffectedPages
  79. * @uses Doku_Indexer
  80. */
  81. public function test_move_affected() {
  82. saveWikiText('oldaffectedspace:page', '[[missing]]', 'setup');
  83. idx_addPage('oldaffectedspace:page');
  84. /** @var helper_plugin_move_plan $plan */
  85. $plan = plugin_load('helper', 'move_plan');
  86. $this->assertFalse($plan->inProgress());
  87. $plan->addPageNamespaceMove('oldaffectedspace', 'newaffectedspace');
  88. $plan->commit();
  89. $affected_file = file(TMP_DIR . '/data/meta/__move_affected');
  90. $this->assertSame('newaffectedspace:page',trim($affected_file[0]));
  91. }
  92. /**
  93. * This is an integration test, which checks the correct working of an entire namespace move.
  94. * Hence it is not an unittest, hence it @coversNothing
  95. *
  96. * @group slow
  97. */
  98. function test_move_large_ns(){
  99. $this->markTestSkipped(
  100. 'This test randomly fails with the page "testns:start" being moved, but "start" not being rewritten in the request.'
  101. );
  102. global $conf;
  103. $test = '[[testns:start]] [[testns:test_page17]]';
  104. $summary = 'testsetup';
  105. saveWikiText(':start', $test, $summary);
  106. idx_addPage(':start');
  107. saveWikiText('testns:start', $test, $summary);
  108. idx_addPage('testns:start');
  109. saveWikiText('testns:test_page1', $test, $summary);
  110. idx_addPage('testns:test_page1');
  111. saveWikiText('testns:test_page2', $test, $summary);
  112. idx_addPage('testns:test_page2');
  113. saveWikiText('testns:test_page3', $test, $summary);
  114. idx_addPage('testns:test_page3');
  115. saveWikiText('testns:test_page4', $test, $summary);
  116. idx_addPage('testns:test_page4');
  117. saveWikiText('testns:test_page5', $test, $summary);
  118. idx_addPage('testns:test_page5');
  119. saveWikiText('testns:test_page6', $test, $summary);
  120. idx_addPage('testns:test_page6');
  121. saveWikiText('testns:test_page7', $test, $summary);
  122. idx_addPage('testns:test_page7');
  123. saveWikiText('testns:test_page8', $test, $summary);
  124. idx_addPage('testns:test_page8');
  125. saveWikiText('testns:test_page9', $test, $summary);
  126. idx_addPage('testns:test_page9');
  127. saveWikiText('testns:test_page10', $test, $summary);
  128. idx_addPage('testns:test_page10');
  129. saveWikiText('testns:test_page11', $test, $summary);
  130. idx_addPage('testns:test_page11');
  131. saveWikiText('testns:test_page12', $test, $summary);
  132. idx_addPage('testns:test_page12');
  133. saveWikiText('testns:test_page13', $test, $summary);
  134. idx_addPage('testns:test_page13');
  135. saveWikiText('testns:test_page14', $test, $summary);
  136. idx_addPage('testns:test_page14');
  137. saveWikiText('testns:test_page15', $test, $summary);
  138. idx_addPage('testns:test_page15');
  139. saveWikiText('testns:test_page16', $test, $summary);
  140. idx_addPage('testns:test_page16');
  141. saveWikiText('testns:test_page17', $test, $summary);
  142. idx_addPage('testns:test_page17');
  143. saveWikiText('testns:test_page18', $test, $summary);
  144. idx_addPage('testns:test_page18');
  145. saveWikiText('testns:test_page19', $test, $summary);
  146. idx_addPage('testns:test_page19');
  147. $conf['plugin']['move']['autorewrite'] = 0;
  148. /** @var helper_plugin_move_plan $plan */
  149. $plan = plugin_load('helper', 'move_plan');
  150. $this->assertFalse($plan->inProgress());
  151. $plan->addPageNamespaceMove('testns', 'foo:testns');
  152. $plan->commit();
  153. global $conf;
  154. $lockfile = $conf['lockdir'] . 'move.lock';
  155. $this->assertSame(10, $plan->nextStep(),"After processing first chunk of pages, 10 steps should be left");
  156. $request = new TestRequest();
  157. $response = $request->get();
  158. $actual_response = $response->getContent();
  159. //clean away clutter
  160. $actual_response = substr($actual_response,strpos($actual_response,"<!-- wikipage start -->") + 23);
  161. $actual_response = substr($actual_response,strpos($actual_response, 'doku.php'));
  162. $actual_response = substr($actual_response,0,strpos($actual_response,"<!-- wikipage stop -->"));
  163. $actual_response = trim($actual_response);
  164. $actual_response = rtrim($actual_response,"</p>");
  165. $actual_response = trim($actual_response);
  166. $expected_response = 'doku.php?id=foo:testns:start" class="wikilink1" title="foo:testns:start">testns</a> <a href="/./doku.php?id=testns:test_page17" class="wikilink1" title="testns:test_page17">test_page17</a>';
  167. $this->assertSame($expected_response,$actual_response); // todo: this assert fails occaisionally, but not reproduciably. It then has the following oputput: <a href="/./doku.php?id=testns:start" class="wikilink2" title="testns:start" rel="nofollow">testns</a> <a href="/./doku.php?id=testns:test_page17" class="wikilink1" title="testns:test_page17">test_page17</a>
  168. $expected_file_contents = '[[testns:start]] [[testns:test_page17]]';
  169. $start_file = file(TMP_DIR . '/data/pages/start.txt');
  170. $actual_file_contents = $start_file[0];
  171. $this->assertSame($expected_file_contents,$actual_file_contents);
  172. /** @var helper_plugin_move_rewrite $rewrite */
  173. $rewrite = plugin_load('helper', 'move_rewrite');
  174. $expected_move_meta = array('origin'=> 'testns:start', 'pages' => array(array('testns:start','foo:testns:start')),'media' => array());
  175. $actual_move_media = $rewrite->getMoveMeta('foo:testns:start');
  176. $this->assertSame($expected_move_meta,$actual_move_media);
  177. $this->assertFileExists($lockfile);
  178. }
  179. /**
  180. * This is an integration test, which checks the correct working of an entire namespace move.
  181. * Hence it is not an unittest, hence it @coversNothing
  182. *
  183. * @group slow
  184. */
  185. public function test_move_small_namespace_pages() {
  186. global $AUTH_ACL;
  187. $AUTH_ACL[] = "oldns:*\t@ALL\t16";
  188. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  189. saveWikiText('start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]]', 'setup');
  190. idx_addPage('start');
  191. saveWikiText('oldns:start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[page]]', 'setup');
  192. idx_addPage('oldns:start');
  193. saveWikiText('oldns:page', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[start]]', 'setup');
  194. idx_addPage('oldns:page');
  195. /** @var helper_plugin_move_plan $plan */
  196. $plan = plugin_load('helper', 'move_plan');
  197. $this->assertFalse($plan->inProgress());
  198. $plan->addPageNamespaceMove('oldns', 'newns');
  199. $plan->commit();
  200. $this->assertSame(1, $plan->nextStep(), 'pages');
  201. $this->assertSame(1, $plan->nextStep(), 'missing');
  202. $this->assertSame(1, $plan->nextStep(), 'namespace');
  203. $this->assertSame(1, $plan->nextStep(), 'autorewrite');
  204. $this->assertSame(0, $plan->nextStep(), 'done');
  205. $this->assertFileExists(wikiFN('newns:start'));
  206. $this->assertFileExists(wikiFN('newns:page'));
  207. $this->assertFileNotExists(wikiFN('oldns:start'));
  208. $this->assertFileNotExists(wikiFN('oldns:page'));
  209. $this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]] [[missing]] [[page]]',rawWiki('newns:start'));
  210. $this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]] [[missing]] [[start]]',rawWiki('newns:page'));
  211. $this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]]',rawWiki('start'));
  212. }
  213. /**
  214. * This is an integration test, which checks the correct working of an entire namespace move.
  215. * Hence it is not an unittest, hence it @coversNothing
  216. *
  217. * @group slow
  218. */
  219. public function test_move_small_namespace_media() {
  220. global $AUTH_ACL;
  221. $AUTH_ACL[] = "oldns:*\t@ALL\t16";
  222. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  223. $filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
  224. io_makeFileDir($filepath);
  225. io_saveFile($filepath,'');
  226. saveWikiText('start', '{{oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{image_missing.png}}', 'setup');
  227. idx_addPage('start');
  228. /** @var helper_plugin_move_plan $plan */
  229. $plan = plugin_load('helper', 'move_plan');
  230. $this->assertFalse($plan->inProgress());
  231. $plan->addMediaNamespaceMove('oldns', 'newns');
  232. $plan->commit();
  233. $this->assertSame(1, $plan->nextStep(), 'media');
  234. $this->assertSame(1, $plan->nextStep(), 'missing_media');
  235. $this->assertSame(1, $plan->nextStep(), 'autorewrite');
  236. $this->assertSame(0, $plan->nextStep(), 'done');
  237. $this->assertFileExists(mediaFN('newns:oldnsimage.png'));
  238. $this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
  239. $this->assertSame('{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{image_missing.png}}',rawWiki('start'));
  240. }
  241. /**
  242. * This is an integration test, which checks the correct working of an entire namespace move.
  243. * Hence it is not an unittest, hence it @coversNothing
  244. *
  245. * @group slow
  246. */
  247. public function test_move_small_namespace_media_affected() {
  248. global $AUTH_ACL;
  249. $AUTH_ACL[] = "oldns:*\t@ALL\t16";
  250. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  251. $filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
  252. io_makeFileDir($filepath);
  253. io_saveFile($filepath,'');
  254. saveWikiText('oldns:start', '{{:oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{oldnsimage_missing.png}} {{oldnsimage.png}}', 'setup');
  255. idx_addPage('oldns:start');
  256. /** @var helper_plugin_move_plan $plan */
  257. $plan = plugin_load('helper', 'move_plan');
  258. $this->assertFalse($plan->inProgress());
  259. $plan->addMediaNamespaceMove('oldns', 'newns');
  260. $plan->commit();
  261. $this->assertSame(1, $plan->nextStep(), 'media');
  262. $this->assertSame(1, $plan->nextStep(), 'missing_media');
  263. $this->assertSame(1, $plan->nextStep(), 'autorewrite');
  264. $this->assertSame(0, $plan->nextStep(), 'done');
  265. $this->assertFileExists(mediaFN('newns:oldnsimage.png'));
  266. $this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
  267. $this->assertSame('{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{newns:oldnsimage_missing.png}} {{newns:oldnsimage.png}}',rawWiki('oldns:start'));
  268. }
  269. /**
  270. * This is an integration test, which checks the correct working of an entire namespace move.
  271. * Hence it is not an unittest, hence it @coversNothing
  272. *
  273. * @group slow
  274. */
  275. public function test_move_small_namespace_combi() {
  276. global $AUTH_ACL;
  277. $AUTH_ACL[] = "oldns:*\t@ALL\t16";
  278. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  279. $filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
  280. io_makeFileDir($filepath);
  281. io_saveFile($filepath,'');
  282. saveWikiText('start', "[[oldns:start]] [[oldns:page]] [[oldns:missing]]\n{{oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{oldnsimage_missing.png}}", 'setup');
  283. idx_addPage('start');
  284. saveWikiText('oldns:start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[page]]', 'setup');
  285. idx_addPage('oldns:start');
  286. saveWikiText('oldns:page', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[start]]', 'setup');
  287. idx_addPage('oldns:page');
  288. /** @var helper_plugin_move_plan $plan */
  289. $plan = plugin_load('helper', 'move_plan');
  290. $this->assertFalse($plan->inProgress());
  291. $plan->addMediaNamespaceMove('oldns', 'newns');
  292. $plan->addPageNamespaceMove('oldns', 'newns');
  293. $plan->commit();
  294. $this->assertSame(1, $plan->nextStep(), 'pages');
  295. $this->assertSame(1, $plan->nextStep(), 'media');
  296. $this->assertSame(1, $plan->nextStep(), 'missing');
  297. $this->assertSame(1, $plan->nextStep(), 'missing_media');
  298. $this->assertSame(1, $plan->nextStep(), 'namespaces');
  299. $this->assertSame(1, $plan->nextStep(), 'autorewrite');
  300. $this->assertSame(0, $plan->nextStep(), 'done');
  301. $this->assertFileExists(mediaFN('newns:oldnsimage.png'));
  302. $this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
  303. $this->assertSame("[[newns:start]] [[newns:page]] [[newns:missing]]\n{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{oldnsimage_missing.png}}",rawWiki('start'));
  304. }
  305. /**
  306. * This is an integration test, which checks the correct working of an entire namespace move.
  307. * Hence it is not an unittest, hence it @coversNothing
  308. *
  309. * @group slow
  310. */
  311. public function test_move_small_namespace_subscription_ns() {
  312. global $AUTH_ACL;
  313. $AUTH_ACL[] = "subns:*\t@ALL\t16";
  314. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  315. saveWikiText('subns:start', 'Lorem Ipsum', 'setup');
  316. idx_addPage('subns:start');
  317. $oldfilepath = DOKU_TMP_DATA.'meta/subns/.mlist';
  318. $subscription = 'doe every 1427984341';
  319. io_makeFileDir($oldfilepath);
  320. io_saveFile($oldfilepath,$subscription);
  321. $newfilepath = DOKU_TMP_DATA.'meta/newns/.mlist';
  322. /** @var helper_plugin_move_plan $plan */
  323. $plan = plugin_load('helper', 'move_plan');
  324. $this->assertFalse($plan->inProgress());
  325. $plan->addPageNamespaceMove('subns', 'newns');
  326. $plan->commit();
  327. $this->assertSame(1, $plan->nextStep(), 'pages');
  328. $this->assertSame(1, $plan->nextStep(), 'namespace');
  329. $this->assertSame(0, $plan->nextStep(), 'done');
  330. $this->assertFileExists(wikiFN('newns:start'));
  331. $this->assertFileExists($newfilepath);
  332. $this->assertFileNotExists(wikiFN('subns:start'));
  333. $this->assertFileNotExists($oldfilepath);
  334. $this->assertSame($subscription,file_get_contents($newfilepath));
  335. }
  336. /**
  337. * This is an integration test, which checks the correct working of an entire namespace move.
  338. * Hence it is not an unittest, hence it @coversNothing
  339. *
  340. * @group slow
  341. */
  342. public function test_move_small_namespace_subscription_page() {
  343. global $AUTH_ACL;
  344. $AUTH_ACL[] = "subns:*\t@ALL\t16";
  345. $AUTH_ACL[] = "newns:*\t@ALL\t16";
  346. saveWikiText('subns:start', 'Lorem Ipsum', 'setup');
  347. idx_addPage('subns:start');
  348. $oldfilepath = DOKU_TMP_DATA.'meta/subns/start.mlist';
  349. $subscription = 'doe every 1427984341';
  350. io_makeFileDir($oldfilepath);
  351. io_saveFile($oldfilepath,$subscription);
  352. $newfilepath = DOKU_TMP_DATA.'meta/newns/start.mlist';
  353. /** @var helper_plugin_move_plan $plan */
  354. $plan = plugin_load('helper', 'move_plan');
  355. $this->assertFalse($plan->inProgress());
  356. $plan->addPageNamespaceMove('subns', 'newns');
  357. $plan->commit();
  358. $this->assertSame(1, $plan->nextStep(), 'pages');
  359. $this->assertSame(1, $plan->nextStep(), 'namespace');
  360. $this->assertSame(0, $plan->nextStep(), 'done');
  361. $this->assertFileExists(wikiFN('newns:start'));
  362. $this->assertFileExists($newfilepath);
  363. $this->assertFileNotExists(wikiFN('subns:start'));
  364. $this->assertFileNotExists($oldfilepath);
  365. $this->assertSame($subscription,file_get_contents($newfilepath));
  366. }
  367. }