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.
 
 
 
 
 

110 lines
3.3 KiB

  1. <?php
  2. // must be run within Dokuwiki
  3. if(!defined('DOKU_INC')) die();
  4. require_once(__DIR__ . '/../helper/plan.php');
  5. /**
  6. * Test cases for the move plugin
  7. *
  8. * @group plugin_move
  9. * @group plugins
  10. */
  11. class plugin_move_plan_test extends DokuWikiTest {
  12. /**
  13. * Create some page namespace structure
  14. */
  15. function setUp():void {
  16. $pages = array(
  17. 'animals:mammals:bear:brownbear',
  18. 'animals:mammals:bear:blackbear',
  19. 'animals:mammals:cute:otter',
  20. 'animals:mammals:cute:cat',
  21. 'animals:mammals:cute:dog',
  22. 'animals:insects:butterfly:fly',
  23. 'animals:insects:butterfly:moth',
  24. 'animals:monkey',
  25. 'humans:programmers:andi',
  26. 'humans:programmers:joe',
  27. 'humans:programmers:john',
  28. 'yeti'
  29. );
  30. foreach($pages as $page) {
  31. saveWikiText($page, $page, 'test setup');
  32. }
  33. parent::setUp();
  34. }
  35. /**
  36. * Check that the plan is sorted into the right order
  37. */
  38. function test_sorting() {
  39. $plan = new test_helper_plugin_move_plan();
  40. $plan->addPageNamespaceMove('animals:mammals:bear', 'animals:mammals:cute:bear');
  41. $plan->addPageNamespaceMove('humans:programmers', 'animals:mammals:cute:programmers');
  42. $plan->addPageMove('humans:programmers:andi', 'animals:insects:butterfly:andi');
  43. $plan->addPageMove('yeti', 'humans:yeti');
  44. $plan->addPageMove('animals:monkey', 'monkey');
  45. $sorted = $plan->sortedPlan();
  46. // the plan is sorted FORWARD (first things first)
  47. $this->assertEquals(5, count($sorted));
  48. $this->assertEquals('humans:programmers:andi', $sorted[0]['src']);
  49. $this->assertEquals('animals:monkey', $sorted[1]['src']);
  50. $this->assertEquals('yeti', $sorted[2]['src']);
  51. $this->assertEquals('animals:mammals:bear', $sorted[3]['src']);
  52. $this->assertEquals('humans:programmers', $sorted[4]['src']);
  53. }
  54. /**
  55. * Move a page out of a namespace and then move the namespace elsewhere
  56. */
  57. function test_pageinnamespace() {
  58. $plan = new test_helper_plugin_move_plan();
  59. $plan->addPageNamespaceMove('animals:mammals:cute', 'animals:mammals:funny');
  60. $plan->addPageMove('animals:mammals:cute:otter', 'animals:mammals:otter');
  61. $plan->commit();
  62. $list = $plan->getList('pagelist');
  63. // the files are sorted BACKWARDS (first things last)
  64. $this->assertEquals(3, count($list));
  65. $this->assertEquals("animals:mammals:cute:otter\tanimals:mammals:otter", trim($list[2]));
  66. $this->assertEquals("animals:mammals:cute:cat\tanimals:mammals:funny:cat", trim($list[1]));
  67. $this->assertEquals("animals:mammals:cute:dog\tanimals:mammals:funny:dog", trim($list[0]));
  68. }
  69. }
  70. /**
  71. * Class test_helper_plugin_move_plan
  72. *
  73. * gives access to some internal stuff of the class
  74. */
  75. class test_helper_plugin_move_plan extends helper_plugin_move_plan {
  76. /**
  77. * Access the sorted plan
  78. *
  79. * @return array
  80. */
  81. function sortedPlan() {
  82. usort($this->plan, array($this, 'planSorter'));
  83. return $this->plan;
  84. }
  85. /**
  86. * Get the full saved list specified by name
  87. *
  88. * @param $name
  89. * @return array
  90. */
  91. function getList($name) {
  92. return file($this->files[$name]);
  93. }
  94. }