はじまりの大地

This commit is contained in:
miteruzo
2024-07-08 03:32:47 +09:00
commit c616a96f53
7749 changed files with 478270 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace dokuwiki\plugin\move\test;
use DokuWikiTest;
/**
* General tests for the move plugin
*
* @group plugin_move
* @group plugins
*/
class GeneralTest extends DokuWikiTest
{
/**
* Simple test to make sure the plugin.info.txt is in correct format
*/
public function testPluginInfo(): void
{
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file);
$info = confToHash($file);
$this->assertArrayHasKey('base', $info);
$this->assertArrayHasKey('author', $info);
$this->assertArrayHasKey('email', $info);
$this->assertArrayHasKey('date', $info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('desc', $info);
$this->assertArrayHasKey('url', $info);
$this->assertEquals('move', $info['base']);
$this->assertRegExp('/^https?:\/\//', $info['url']);
$this->assertTrue(mail_isvalid($info['email']));
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
$this->assertTrue(false !== strtotime($info['date']));
}
/**
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
* conf/metadata.php.
*/
public function testPluginConf(): void
{
$conf_file = __DIR__ . '/../conf/default.php';
$meta_file = __DIR__ . '/../conf/metadata.php';
if (!file_exists($conf_file) && !file_exists($meta_file)) {
self::markTestSkipped('No config files exist -> skipping test');
}
if (file_exists($conf_file)) {
include($conf_file);
}
if (file_exists($meta_file)) {
include($meta_file);
}
$this->assertEquals(
gettype($conf),
gettype($meta),
'Both ' . DOKU_PLUGIN . 'move/conf/default.php and ' . DOKU_PLUGIN . 'move/conf/metadata.php have to exist and contain the same keys.'
);
if ($conf !== null && $meta !== null) {
foreach ($conf as $key => $value) {
$this->assertArrayHasKey(
$key,
$meta,
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'move/conf/metadata.php'
);
}
foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'move/conf/default.php'
);
}
}
}
}
@@ -0,0 +1,58 @@
<?php
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_affectedPagesNS_test extends DokuWikiTest {
protected $pluginsEnabled = array('move',);
public function setUp(): void {
parent::setUp();
global $USERINFO;
global $conf;
$conf['useacl'] = 1;
$conf['superuser'] = 'john';
$_SERVER['REMOTE_USER'] = 'john'; //now it's testing as admin
$USERINFO['grps'] = array('admin','user');
}
/**
* @coversNothing
*/
public function tearDown(): void {
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$plan->abort();
parent::tearDown();
}
/**
* @covers helper_plugin_move_plan::findAffectedPages
* @uses Doku_Indexer
*/
public function test_affectedPagesNS_Media() {
saveWikiText('oldns:start', '{{oldnsimage_missing.png}}', 'setup');
idx_addPage('oldns:start');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper','move_plan');
$this->assertFalse($plan->inProgress());
$plan->addMediaNamespaceMove('oldns', 'newns');
$plan->commit();
$affected_file = file(TMP_DIR . '/data/meta/__move_affected');
$this->assertSame('oldns:start',trim($affected_file[0]));
}
}
@@ -0,0 +1,47 @@
<?php
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_cache_handling_test extends DokuWikiTest {
function setUp(): void {
parent::setUpBeforeClass();
$this->pluginsEnabled[] = 'move';
parent::setUp();
}
/**
* @group slow
*/
function test_cache_handling() {
$testid = 'wiki:bar:test';
saveWikiText($testid,
'[[wiki:foo:]]', 'Test setup');
idx_addPage($testid);
saveWikiText('wiki:foo:start',
'bar', 'Test setup');
idx_addPage('wiki:foo:start');
sleep(1); // wait in order to make sure that conditions with < give the right result.
p_wiki_xhtml($testid); // populate cache
$cache = new cache_renderer($testid, wikiFN($testid), 'xhtml');
$this->assertTrue($cache->useCache());
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('wiki:foo:start', 'wiki:foo2:start'));
$cache = new cache_renderer($testid, wikiFN($testid), 'xhtml');
$this->assertFalse($cache->useCache());
}
}
@@ -0,0 +1,113 @@
<?php
class helper_plugin_move_plan_findMissingDocuments_mock extends helper_plugin_move_plan {
public function findMissingDocuments($src, $dst, $type = self::TYPE_PAGES) {
parent::findMissingDocuments($src, $dst, $type);
}
public function getTmpstore() {
return $this->tmpstore;
}
}
/**
* Test cases for helper_plugin_move_plan::stepThroughDocuments function of the move plugin
*
* @group plugin_move
* @group plugin_move_unittests
* @group plugins
* @group unittests
* @covers helper_plugin_move_plan::findMissingDocuments
*/
class plugin_move_findMissingPages_test extends DokuWikiTest {
protected $pluginsEnabled = array('move',);
/** @var helper_plugin_move_plan_findMissingDocuments_mock $plan */
protected $plan;
/**
* @coversNothing
*/
public function setUp(): void {
parent::setUp();
$this->plan = new helper_plugin_move_plan_findMissingDocuments_mock();
}
/**
* @coversNothing
*/
public function tearDown(): void {
global $conf;
$dirs = array('indexdir','datadir','metadir', 'mediadir');
foreach ($dirs as $dir) {
io_rmdir($conf[$dir],true);
mkdir($conf[$dir]);
}
$this->plan->abort();
parent::tearDown();
}
function test_findMissingPages_empty () {
$this->plan->findMissingDocuments('oldns','newns:');
$tmpstore = $this->plan->getTmpstore();
$this->assertSame(array(),$tmpstore['miss']);
}
function test_findMissingPages_missingPage_default () {
saveWikiText('start','[[oldns:missing]]','test edit');
idx_addPage('start');
$this->plan->findMissingDocuments('oldns:','newns:');
$tmpstore = $this->plan->getTmpstore();
$this->assertSame(array('oldns:missing' => 'newns:missing',),$tmpstore['miss']);
}
function test_findMissingPages_missingPage_explicit () {
saveWikiText('start','[[oldns:missing]]','test edit');
idx_addPage('start');
$this->plan->findMissingDocuments('oldns:','newns:',helper_plugin_move_plan::TYPE_PAGES);
$tmpstore = $this->plan->getTmpstore();
$this->assertSame(array('oldns:missing' => 'newns:missing',),$tmpstore['miss']);
}
function test_findMissingPages_missingPage_integrated () {
saveWikiText('oldns:start','[[oldns:missing]] {{oldns:missing.png}}','test edit');
idx_addPage('oldns:start');
$this->plan->addPageNamespaceMove('oldns', 'newns');
$this->plan->addMediaNamespaceMove('oldns', 'newns');
$this->plan->commit();
$missing_file = file(TMP_DIR . '/data/meta/__move_missing');
$this->assertSame(array("oldns:missing\tnewns:missing\n",),$missing_file,'new configuration fails');
$missing_media_file = file(TMP_DIR . '/data/meta/__move_missing_media');
$this->assertSame(array("oldns:missing.png\tnewns:missing.png\n",),$missing_media_file,'new configuration fails');
}
function test_findMissingPages_missingMedia () {
saveWikiText('start','{{oldns:missing.png}}','test edit');
idx_addPage('start');
$this->plan->findMissingDocuments('oldns:','newns:',helper_plugin_move_plan::TYPE_MEDIA);
$tmpstore = $this->plan->getTmpstore();
$this->assertSame(array('oldns:missing.png' => 'newns:missing.png',),$tmpstore['miss_media']);
}
function test_findMissingDocuments_nonMissingMedia () {
$filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('start','{{oldns:oldnsimage.png}}','test edit');
idx_addPage('start');
$this->plan->findMissingDocuments('oldns:','newns:',helper_plugin_move_plan::TYPE_MEDIA);
$tmpstore = $this->plan->getTmpstore();
$this->assertSame(array(),$tmpstore['miss_media']);
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
require_once(__DIR__ . '/../helper/handler.php');
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_handler_test extends DokuWikiTest {
public function setUp(): void {
$this->pluginsEnabled[] = 'move';
parent::setUp();
}
public function test_relativeLink() {
/** @var $handler helper_plugin_move_handler */
$handler = plugin_load('helper', 'move_handler');
$handler->init('deep:namespace:page', 'used:to:be:here', array(), array(), array());
$tests = array(
'deep:namespace:new1' => 'new1',
'deep:new2' => '..:new2',
'new3' => ':new3', // absolute is shorter than relative
'deep:namespace:deeper:new4' => '.deeper:new4',
'deep:namespace:deeper:deepest:new5' => '.deeper:deepest:new5',
'deep:foobar:new6' => '..:foobar:new6',
);
foreach($tests as $new => $rel) {
$this->assertEquals($rel, $handler->relativeLink('foo', $new, 'page'));
}
$this->assertEquals('.deeper:', $handler->relativeLink('.deeper:', 'deep:namespace:deeper:start', 'page'));
$this->assertEquals('.:', $handler->relativeLink('.:', 'deep:namespace:start', 'page'));
}
public function test_resolveMoves() {
/** @var $handler helper_plugin_move_handler */
$handler = plugin_load('helper', 'move_handler');
$handler->init(
'deep:namespace:page',
'used:to:be:here',
array(
array('used:to:be:here', 'deep:namespace:page'),
array('foo', 'bar'),
array('used:to:be:this1', 'used:to:be:that1'),
array('used:to:be:this2', 'deep:namespace:that1'),
array('used:to:be:this3', 'deep:that3'),
array('deep:that3', 'but:got:moved3'),
),
array(),
array()
);
$tests = array(
'used:to:be:here' => 'deep:namespace:page', // full link to self
':foo' => 'bar', // absolute link that moved
':bang' => 'bang', // absolute link that did not move
'foo' => 'used:to:be:foo', // relative link that did not move
'this1' => 'used:to:be:that1', // relative link that did not move but is in move list
'this2' => 'deep:namespace:that1', // relative link that moved
'this3' => 'but:got:moved3', // relative link that moved twice
);
foreach($tests as $match => $id) {
$this->assertEquals($id, $handler->resolveMoves($match, 'page'));
}
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* Test cases log functionality of the move plugin
*
* @group plugin_move
* @group plugin_move_unittests
* @group plugins
* @group unittests
*/
class plugin_move_log_test extends DokuWikiTest {
protected $pluginsEnabled = array('move',);
public function test_log_one_line_success() {
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$now = time();
$date = date('Y-m-d H:i:s', $now);
$actual_log = $plan->build_log_line('P','oldpage','newpage',true);
$expected_log = "$now\t$date\tP\toldpage\tnewpage\tsuccess\t\n";
$this->assertSame($expected_log, $actual_log);
}
public function test_log_build_line_failure() {
global $MSG;
$MSG = array();
$msg = array('msg'=>"TestMessage01",);
array_push($MSG,$msg);
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$now = time();
$date = date('Y-m-d H:i:s', $now);
$actual_log = $plan->build_log_line('P','oldpage','newpage',false);
$expected_log = "$now\t$date\tP\toldpage\tnewpage\tfailed\tTestMessage01\n";
$this->assertSame($expected_log, $actual_log);
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_mediamove_test extends DokuWikiTest {
public function setUp(): void {
$this->pluginsEnabled[] = 'move';
parent::setUp();
}
/**
* @group slow
*/
public function test_movePageWithRelativeMedia() {
$src = 'mediareltest:foo';
saveWikiText($src,
'{{ myimage.png}} [[:start|{{ testimage.png?200x800 }}]] [[bar|{{testimage.gif?400x200}}]]
[[doku>wiki:dokuwiki|{{wiki:logo.png}}]] [[http://www.example.com|{{testimage.jpg}}]]
[[doku>wiki:foo|{{foo.gif?200x3000}}]]', 'Test setup');
idx_addPage($src);
$dst = 'foo';
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage($src, $dst));
$this->assertEquals('{{ mediareltest:myimage.png}} [[:start|{{ mediareltest:testimage.png?200x800 }}]] [[mediareltest:bar|{{mediareltest:testimage.gif?400x200}}]]
[[doku>wiki:dokuwiki|{{wiki:logo.png}}]] [[http://www.example.com|{{mediareltest:testimage.jpg}}]]
[[doku>wiki:foo|{{mediareltest:foo.gif?200x3000}}]]', rawWiki('foo'));
}
/**
* @group slow
*/
public function test_moveSingleMedia() {
global $AUTH_ACL;
$AUTH_ACL[] = "wiki:*\t@ALL\t16";
$AUTH_ACL[] = "foobar:*\t@ALL\t8";
saveWikiText('wiki:movetest', '{{wiki:dokuwiki-128.png?200}}', 'Test initialized');
idx_addPage('wiki:movetest');
$src = 'wiki:dokuwiki-128.png';
$dst = 'foobar:logo.png';
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->moveMedia($src, $dst));
$this->assertTrue(@file_exists(mediaFn('foobar:logo.png')));
$this->assertEquals('{{foobar:logo.png?200}}', rawWiki('wiki:movetest'));
}
/**
* @group slow
*/
public function test_moveSingleMedia_colonstart() {
global $AUTH_ACL;
$AUTH_ACL[] = "wiki:*\t@ALL\t16";
$AUTH_ACL[] = "foobar:*\t@ALL\t16";
$AUTH_ACL[] = "*\t@ALL\t8";
$filepath = DOKU_TMP_DATA.'media/wiki/testimage.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('wiki:movetest', '{{:wiki:testimage.png?200}}', 'Test initialized');
idx_addPage('wiki:movetest');
$src = 'wiki:testimage.png';
$dst = 'foobar:logo_2.png';
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->moveMedia($src, $dst));
$this->assertTrue(@file_exists(mediaFn('foobar:logo_2.png')));
$this->assertEquals('{{foobar:logo_2.png?200}}', rawWiki('wiki:movetest'));
$this->assertTrue($move->moveMedia($dst, 'logo_2.png'));
$this->assertTrue(@file_exists(mediaFn('logo_2.png')));
$this->assertEquals('{{:logo_2.png?200}}', rawWiki('wiki:movetest'));
}
/**
* @group slow
*/
public function test_moveSingleMedia_space() {
global $AUTH_ACL;
$AUTH_ACL[] = "wiki:*\t@ALL\t16";
$AUTH_ACL[] = "foobar:*\t@ALL\t8";
$filepath = DOKU_TMP_DATA.'media/wiki/foo/test_image.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('wiki:movetest', '{{:wiki:foo:test image.png?200|test image}}', 'Test initialized');
idx_addPage('wiki:movetest');
$src = 'wiki:foo:test_image.png';
$dst = 'wiki:foobar:test_image.png';
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->moveMedia($src, $dst));
$this->assertTrue(@file_exists(mediaFn('wiki:foobar:test_image.png')));
$this->assertEquals('{{wiki:foobar:test_image.png?200|test image}}', rawWiki('wiki:movetest'));
}
}
@@ -0,0 +1,478 @@
<?php
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Test cases for namespace move functionality of the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_namespace_move_test extends DokuWikiTest {
public function setUp(): void {
$this->pluginsEnabled[] = 'move';
parent::setUp();
}
/**
* @coversNothing
*/
public function tearDown(): void {
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$plan->abort();
io_rmdir(DOKU_TMP_DATA."pages/newns",true);
io_rmdir(DOKU_TMP_DATA."media/newns",true);
io_rmdir(DOKU_TMP_DATA."meta/newns",true);
parent::tearDown();
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_wiki_namespace() {
global $AUTH_ACL;
$AUTH_ACL[] = "wiki:*\t@ALL\t16";
idx_addPage('wiki:dokuwiki');
idx_addPage('wiki:syntax');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('wiki', 'foo');
$plan->addMediaNamespaceMove('wiki', 'foo');
$plan->commit();
$this->assertSame(1, $plan->nextStep(),'pages');
$this->assertSame(1, $plan->nextStep(),'media');
$this->assertSame(1, $plan->nextStep(),'missing');
$this->assertSame(1, $plan->nextStep(),'namespace');
$this->assertSame(1, $plan->nextStep(),'autorewrite');
$this->assertSame(0, $plan->nextStep(),'done');
$this->assertFileExists(wikiFN('foo:dokuwiki'));
$this->assertFileNotExists(wikiFN('wiki:syntax'));
$this->assertFileExists(mediaFN('foo:dokuwiki-128.png'));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_missing() {
saveWikiText('oldspace:page', '[[missing]]', 'setup');
idx_addPage('oldspace:page');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('oldspace', 'newspace');
$plan->commit();
$this->assertSame(1, $plan->nextStep(),'page');
$this->assertSame(1, $plan->nextStep(),'missing');
$this->assertSame(1, $plan->nextStep(),'namespace');
$this->assertSame(1, $plan->nextStep(),'autorewrite');
$this->assertSame(0, $plan->nextStep(),'done');
$this->assertFileExists(wikiFN('newspace:page'));
$this->assertFileNotExists(wikiFN('oldspace:page'));
$this->assertEquals('[[missing]]', rawWiki('newspace:page'));
}
/**
* @covers helper_plugin_move_plan::findAffectedPages
* @uses Doku_Indexer
*/
public function test_move_affected() {
saveWikiText('oldaffectedspace:page', '[[missing]]', 'setup');
idx_addPage('oldaffectedspace:page');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('oldaffectedspace', 'newaffectedspace');
$plan->commit();
$affected_file = file(TMP_DIR . '/data/meta/__move_affected');
$this->assertSame('newaffectedspace:page',trim($affected_file[0]));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
function test_move_large_ns(){
$this->markTestSkipped(
'This test randomly fails with the page "testns:start" being moved, but "start" not being rewritten in the request.'
);
global $conf;
$test = '[[testns:start]] [[testns:test_page17]]';
$summary = 'testsetup';
saveWikiText(':start', $test, $summary);
idx_addPage(':start');
saveWikiText('testns:start', $test, $summary);
idx_addPage('testns:start');
saveWikiText('testns:test_page1', $test, $summary);
idx_addPage('testns:test_page1');
saveWikiText('testns:test_page2', $test, $summary);
idx_addPage('testns:test_page2');
saveWikiText('testns:test_page3', $test, $summary);
idx_addPage('testns:test_page3');
saveWikiText('testns:test_page4', $test, $summary);
idx_addPage('testns:test_page4');
saveWikiText('testns:test_page5', $test, $summary);
idx_addPage('testns:test_page5');
saveWikiText('testns:test_page6', $test, $summary);
idx_addPage('testns:test_page6');
saveWikiText('testns:test_page7', $test, $summary);
idx_addPage('testns:test_page7');
saveWikiText('testns:test_page8', $test, $summary);
idx_addPage('testns:test_page8');
saveWikiText('testns:test_page9', $test, $summary);
idx_addPage('testns:test_page9');
saveWikiText('testns:test_page10', $test, $summary);
idx_addPage('testns:test_page10');
saveWikiText('testns:test_page11', $test, $summary);
idx_addPage('testns:test_page11');
saveWikiText('testns:test_page12', $test, $summary);
idx_addPage('testns:test_page12');
saveWikiText('testns:test_page13', $test, $summary);
idx_addPage('testns:test_page13');
saveWikiText('testns:test_page14', $test, $summary);
idx_addPage('testns:test_page14');
saveWikiText('testns:test_page15', $test, $summary);
idx_addPage('testns:test_page15');
saveWikiText('testns:test_page16', $test, $summary);
idx_addPage('testns:test_page16');
saveWikiText('testns:test_page17', $test, $summary);
idx_addPage('testns:test_page17');
saveWikiText('testns:test_page18', $test, $summary);
idx_addPage('testns:test_page18');
saveWikiText('testns:test_page19', $test, $summary);
idx_addPage('testns:test_page19');
$conf['plugin']['move']['autorewrite'] = 0;
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('testns', 'foo:testns');
$plan->commit();
global $conf;
$lockfile = $conf['lockdir'] . 'move.lock';
$this->assertSame(10, $plan->nextStep(),"After processing first chunk of pages, 10 steps should be left");
$request = new TestRequest();
$response = $request->get();
$actual_response = $response->getContent();
//clean away clutter
$actual_response = substr($actual_response,strpos($actual_response,"<!-- wikipage start -->") + 23);
$actual_response = substr($actual_response,strpos($actual_response, 'doku.php'));
$actual_response = substr($actual_response,0,strpos($actual_response,"<!-- wikipage stop -->"));
$actual_response = trim($actual_response);
$actual_response = rtrim($actual_response,"</p>");
$actual_response = trim($actual_response);
$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>';
$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>
$expected_file_contents = '[[testns:start]] [[testns:test_page17]]';
$start_file = file(TMP_DIR . '/data/pages/start.txt');
$actual_file_contents = $start_file[0];
$this->assertSame($expected_file_contents,$actual_file_contents);
/** @var helper_plugin_move_rewrite $rewrite */
$rewrite = plugin_load('helper', 'move_rewrite');
$expected_move_meta = array('origin'=> 'testns:start', 'pages' => array(array('testns:start','foo:testns:start')),'media' => array());
$actual_move_media = $rewrite->getMoveMeta('foo:testns:start');
$this->assertSame($expected_move_meta,$actual_move_media);
$this->assertFileExists($lockfile);
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_pages() {
global $AUTH_ACL;
$AUTH_ACL[] = "oldns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
saveWikiText('start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]]', 'setup');
idx_addPage('start');
saveWikiText('oldns:start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[page]]', 'setup');
idx_addPage('oldns:start');
saveWikiText('oldns:page', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[start]]', 'setup');
idx_addPage('oldns:page');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('oldns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'pages');
$this->assertSame(1, $plan->nextStep(), 'missing');
$this->assertSame(1, $plan->nextStep(), 'namespace');
$this->assertSame(1, $plan->nextStep(), 'autorewrite');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(wikiFN('newns:start'));
$this->assertFileExists(wikiFN('newns:page'));
$this->assertFileNotExists(wikiFN('oldns:start'));
$this->assertFileNotExists(wikiFN('oldns:page'));
$this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]] [[missing]] [[page]]',rawWiki('newns:start'));
$this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]] [[missing]] [[start]]',rawWiki('newns:page'));
$this->assertSame('[[newns:start]] [[newns:page]] [[newns:missing]]',rawWiki('start'));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_media() {
global $AUTH_ACL;
$AUTH_ACL[] = "oldns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
$filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('start', '{{oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{image_missing.png}}', 'setup');
idx_addPage('start');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addMediaNamespaceMove('oldns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'media');
$this->assertSame(1, $plan->nextStep(), 'missing_media');
$this->assertSame(1, $plan->nextStep(), 'autorewrite');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(mediaFN('newns:oldnsimage.png'));
$this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
$this->assertSame('{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{image_missing.png}}',rawWiki('start'));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_media_affected() {
global $AUTH_ACL;
$AUTH_ACL[] = "oldns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
$filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('oldns:start', '{{:oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{oldnsimage_missing.png}} {{oldnsimage.png}}', 'setup');
idx_addPage('oldns:start');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addMediaNamespaceMove('oldns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'media');
$this->assertSame(1, $plan->nextStep(), 'missing_media');
$this->assertSame(1, $plan->nextStep(), 'autorewrite');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(mediaFN('newns:oldnsimage.png'));
$this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
$this->assertSame('{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{newns:oldnsimage_missing.png}} {{newns:oldnsimage.png}}',rawWiki('oldns:start'));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_combi() {
global $AUTH_ACL;
$AUTH_ACL[] = "oldns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
$filepath = DOKU_TMP_DATA.'media/oldns/oldnsimage.png';
io_makeFileDir($filepath);
io_saveFile($filepath,'');
saveWikiText('start', "[[oldns:start]] [[oldns:page]] [[oldns:missing]]\n{{oldns:oldnsimage.png}} {{oldns:oldnsimage_missing.png}} {{oldnsimage_missing.png}}", 'setup');
idx_addPage('start');
saveWikiText('oldns:start', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[page]]', 'setup');
idx_addPage('oldns:start');
saveWikiText('oldns:page', '[[oldns:start]] [[oldns:page]] [[oldns:missing]] [[missing]] [[start]]', 'setup');
idx_addPage('oldns:page');
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addMediaNamespaceMove('oldns', 'newns');
$plan->addPageNamespaceMove('oldns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'pages');
$this->assertSame(1, $plan->nextStep(), 'media');
$this->assertSame(1, $plan->nextStep(), 'missing');
$this->assertSame(1, $plan->nextStep(), 'missing_media');
$this->assertSame(1, $plan->nextStep(), 'namespaces');
$this->assertSame(1, $plan->nextStep(), 'autorewrite');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(mediaFN('newns:oldnsimage.png'));
$this->assertFileNotExists(mediaFN('oldns:oldnsimage.png'));
$this->assertSame("[[newns:start]] [[newns:page]] [[newns:missing]]\n{{newns:oldnsimage.png}} {{newns:oldnsimage_missing.png}} {{oldnsimage_missing.png}}",rawWiki('start'));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_subscription_ns() {
global $AUTH_ACL;
$AUTH_ACL[] = "subns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
saveWikiText('subns:start', 'Lorem Ipsum', 'setup');
idx_addPage('subns:start');
$oldfilepath = DOKU_TMP_DATA.'meta/subns/.mlist';
$subscription = 'doe every 1427984341';
io_makeFileDir($oldfilepath);
io_saveFile($oldfilepath,$subscription);
$newfilepath = DOKU_TMP_DATA.'meta/newns/.mlist';
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('subns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'pages');
$this->assertSame(1, $plan->nextStep(), 'namespace');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(wikiFN('newns:start'));
$this->assertFileExists($newfilepath);
$this->assertFileNotExists(wikiFN('subns:start'));
$this->assertFileNotExists($oldfilepath);
$this->assertSame($subscription,file_get_contents($newfilepath));
}
/**
* This is an integration test, which checks the correct working of an entire namespace move.
* Hence it is not an unittest, hence it @coversNothing
*
* @group slow
*/
public function test_move_small_namespace_subscription_page() {
global $AUTH_ACL;
$AUTH_ACL[] = "subns:*\t@ALL\t16";
$AUTH_ACL[] = "newns:*\t@ALL\t16";
saveWikiText('subns:start', 'Lorem Ipsum', 'setup');
idx_addPage('subns:start');
$oldfilepath = DOKU_TMP_DATA.'meta/subns/start.mlist';
$subscription = 'doe every 1427984341';
io_makeFileDir($oldfilepath);
io_saveFile($oldfilepath,$subscription);
$newfilepath = DOKU_TMP_DATA.'meta/newns/start.mlist';
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
$this->assertFalse($plan->inProgress());
$plan->addPageNamespaceMove('subns', 'newns');
$plan->commit();
$this->assertSame(1, $plan->nextStep(), 'pages');
$this->assertSame(1, $plan->nextStep(), 'namespace');
$this->assertSame(0, $plan->nextStep(), 'done');
$this->assertFileExists(wikiFN('newns:start'));
$this->assertFileExists($newfilepath);
$this->assertFileNotExists(wikiFN('subns:start'));
$this->assertFileNotExists($oldfilepath);
$this->assertSame($subscription,file_get_contents($newfilepath));
}
}
+629
View File
@@ -0,0 +1,629 @@
<?php
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_pagemove_test extends DokuWikiTest {
var $movedToId = '';
var $movedId = 'parent_ns:current_ns:test_page';
var $parentBacklinkingId = 'parent_ns:some_page';
var $currentNsBacklinkingId = 'parent_ns:current_ns:some_page';
var $otherBacklinkingId = 'level0:level1:other_backlinking_page';
var $subNsPage = 'parent_ns:current_ns:sub_ns:some_page';
// @todo Move page to an ID which already exists
// @todo Check backlinks of a sub-namespace page (moving same, up, down, different)
function setUp(): void {
parent::setUpBeforeClass();
$this->pluginsEnabled[] = 'move';
global $ID;
global $INFO;
global $conf;
$ID = $this->movedId;
$text = <<<EOT
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$summary = 'Test';
saveWikiText($this->movedId, $text, $summary);
$INFO = pageinfo();
$references = array_keys(p_get_metadata($this->movedId, 'relation references', METADATA_RENDER_UNLIMITED));
idx_get_indexer()->addMetaKeys($this->movedId, 'relation_references', $references);
$text = <<<EOT
[[$this->movedId|$this->movedId]]
[[:$this->movedId|:$this->movedId]]
[[.current_ns:test_page|.current_ns:test_page]]
[[.:current_ns:test_page|.:current_ns:test_page]]
[[..parent_ns:current_ns:test_page|..parent_ns:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
saveWikiText($this->parentBacklinkingId, $text, $summary);
$references = array_keys(p_get_metadata($this->parentBacklinkingId, 'relation references', METADATA_RENDER_UNLIMITED));
idx_get_indexer()->addMetaKeys($this->parentBacklinkingId, 'relation_references', $references);
$text = <<<EOT
[[$this->movedId|$this->movedId]]
[[:$this->movedId|:$this->movedId]]
[[..current_ns:test_page|..current_ns:test_page]]
[[..:current_ns:test_page|..:current_ns:test_page]]
[[test_page|test_page]]
[[.test_page|.test_page]]
[[.:test_page|.:test_page]]
[[..test_page|..test_page]]
[[..:test_page|..:test_page]]
[[.:..:test_page|.:..:test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
saveWikiText($this->currentNsBacklinkingId, $text, $summary);
$references = array_keys(p_get_metadata($this->currentNsBacklinkingId, 'relation references', METADATA_RENDER_UNLIMITED));
idx_get_indexer()->addMetaKeys($this->currentNsBacklinkingId, 'relation_references', $references);
$text = <<<EOT
[[$this->movedId|$this->movedId]]
[[:$this->movedId|:$this->movedId]]
[[.current_ns:test_page|.current_ns:test_page]]
[[.:current_ns:test_page|.:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
saveWikiText($this->otherBacklinkingId, $text, $summary);
$references = array_keys(p_get_metadata($this->otherBacklinkingId, 'relation references', METADATA_RENDER_UNLIMITED));
idx_get_indexer()->addMetaKeys($this->otherBacklinkingId, 'relation_references', $references);
$text = <<<EOT
[[$this->movedId|$this->movedId]]
[[:$this->movedId|:$this->movedId]]
[[..:..current_ns:test_page|..:..current_ns:test_page]]
[[..:..:current_ns:test_page|..:..:current_ns:test_page]]
[[test_page|test_page]]
[[..:test_page|..:test_page]]
[[..:test_page|..:test_page]]
[[.:..:test_page|.:..:test_page]]
[[new_page|new_page]]
[[..:new_page|..:new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
saveWikiText($this->subNsPage, $text, $summary);
$references = array_keys(p_get_metadata($this->subNsPage, 'relation references', METADATA_RENDER_UNLIMITED));
idx_get_indexer()->addMetaKeys($this->subNsPage, 'relation_references', $references);
parent::setUp();
// we test under useslash conditions
$conf['useslash'] = 1;
}
/**
* @group slow
*/
function test_move_page_in_same_ns() {
global $ID;
$newId = getNS($ID).':new_page';
$this->movedToId = $newId;
/** @var helper_plugin_move_op $MoveOp */
$MoveOp = plugin_load('helper', 'move_op');
$result = $MoveOp->movePage($ID, $this->movedToId);
$this->assertTrue($result);
$newContent = rawWiki($this->movedToId);
$expectedContent = <<<EOT
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->parentBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:current_ns:new_page|$this->movedId]]
[[parent_ns:current_ns:new_page|:$this->movedId]]
[[.current_ns:new_page|.current_ns:test_page]]
[[.current_ns:new_page|.:current_ns:test_page]]
[[.current_ns:new_page|..parent_ns:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->currentNsBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:current_ns:new_page|$this->movedId]]
[[parent_ns:current_ns:new_page|:$this->movedId]]
[[new_page|..current_ns:test_page]]
[[new_page|..:current_ns:test_page]]
[[new_page|test_page]]
[[new_page|.test_page]]
[[new_page|.:test_page]]
[[..test_page|..test_page]]
[[..:test_page|..:test_page]]
[[.:..:test_page|.:..:test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->otherBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:current_ns:new_page|$this->movedId]]
[[$newId|:$this->movedId]]
[[.current_ns:test_page|.current_ns:test_page]]
[[.:current_ns:test_page|.:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
}
/**
* @group slow
*/
function test_move_page_to_parallel_ns() {
global $ID;
$newId = 'parent_ns:parallel_ns:new_page';
$this->movedToId = $newId;
/** @var helper_plugin_move_op $MoveOp */
$MoveOp = plugin_load('helper', 'move_op');
$result = $MoveOp->movePage($ID, $newId);
$this->assertTrue($result);
$newContent = rawWiki($this->movedToId);
$expectedContent = <<<EOT
[[..:current_ns:start|start]]
[[..:current_ns:parallel_page|parallel_page]]
[[..:current_ns:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->parentBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:parallel_ns:new_page|$this->movedId]]
[[parent_ns:parallel_ns:new_page|:$this->movedId]]
[[.parallel_ns:new_page|.current_ns:test_page]]
[[.parallel_ns:new_page|.:current_ns:test_page]]
[[.parallel_ns:new_page|..parent_ns:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->currentNsBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:parallel_ns:new_page|$this->movedId]]
[[$newId|:$this->movedId]]
[[..:parallel_ns:new_page|..current_ns:test_page]]
[[..:parallel_ns:new_page|..:current_ns:test_page]]
[[..:parallel_ns:new_page|test_page]]
[[..:parallel_ns:new_page|.test_page]]
[[..:parallel_ns:new_page|.:test_page]]
[[..test_page|..test_page]]
[[..:test_page|..:test_page]]
[[.:..:test_page|.:..:test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->otherBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:parallel_ns:new_page|$this->movedId]]
[[$newId|:$this->movedId]]
[[.current_ns:test_page|.current_ns:test_page]]
[[.:current_ns:test_page|.:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
}
/**
* @group slow
*/
function test_move_page_to_parent_ns() {
global $ID;
$newId = 'parent_ns:new_page';
$this->movedToId = $newId;
/** @var helper_plugin_move_op $MoveOp */
$MoveOp = plugin_load('helper', 'move_op');
$result = $MoveOp->movePage($ID, $newId); //parent_ns:current_ns:test_page -> parent_ns:new_page
$this->assertTrue($result);
$newContent = rawWiki($this->movedToId);
$expectedContent = <<<EOT
[[.current_ns:start|start]]
[[.current_ns:parallel_page|parallel_page]]
[[.current_ns:|.:]]
[[.current_ns:|..current_ns:]]
[[.current_ns:|..:current_ns:]]
[[.parallel_ns:|..parallel_ns:]]
[[.parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
// Note: ..:..: is not a great link for a page in a namespace 'parent_ns', but it is correctly resolved.
$this->assertEquals($expectedContent, $newContent);
// page is moved to same NS as backlinking page (parent_ns)
$newContent = rawWiki($this->parentBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:new_page|$this->movedId]]
[[parent_ns:new_page|:$this->movedId]]
[[new_page|.current_ns:test_page]]
[[new_page|.:current_ns:test_page]]
[[new_page|..parent_ns:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->currentNsBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:new_page|$this->movedId]]
[[$newId|:$this->movedId]]
[[..:new_page|..current_ns:test_page]]
[[..:new_page|..:current_ns:test_page]]
[[..:new_page|test_page]]
[[..:new_page|.test_page]]
[[..:new_page|.:test_page]]
[[..test_page|..test_page]]
[[..:test_page|..:test_page]]
[[.:..:test_page|.:..:test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
$newContent = rawWiki($this->otherBacklinkingId);
$expectedContent = <<<EOT
[[parent_ns:new_page|$this->movedId]]
[[$newId|:$this->movedId]]
[[.current_ns:test_page|.current_ns:test_page]]
[[.:current_ns:test_page|.:current_ns:test_page]]
[[test_page|test_page]]
[[new_page|new_page]]
[[ftp://somewhere.com|ftp://somewhere.com]]
[[http://somewhere.com|http://somewhere.com]]
[[start|start]]
[[parallel_page|parallel_page]]
[[.:|.:]]
[[..current_ns:|..current_ns:]]
[[..:current_ns:|..:current_ns:]]
[[..parallel_ns:|..parallel_ns:]]
[[..:parallel_ns:|..:parallel_ns:]]
[[..:..:|..:..:]]
[[..:..:parent_ns:|..:..:parent_ns:]]
[[parent_ns:new_page|parent_ns:new_page]]
[[parent_ns/new_page|parent_ns/new_page]]
[[/start|/start]]
EOT;
$this->assertEquals($expectedContent, $newContent);
}
/**
* Ensure that absolute links stay absolute. See https://github.com/michitux/dokuwiki-plugin-move/pull/6#discussion_r15698440
*
* @group slow
*/
function test_move_startpage_of_ns() {
saveWikiText('wiki:bar:test',
'[[wiki:foo:]]', 'Test setup');
idx_addPage('wiki:bar:test');
saveWikiText('wiki:foo:start',
'bar', 'Test setup');
idx_addPage('wiki:foo:start');
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('wiki:foo:start', 'wiki:foo2:start'));
$this->assertEquals('[[wiki:foo2:]]', rawWiki('wiki:bar:test'));
}
/**
* If the relative part would be too large, create an absolute link instead.
* If the original link ended with a colon and the new link also points to a namespace's startpage: keep the colon.
*
* @group slow
*/
function test_move_no_long_rel_links_keep_colon() {
saveWikiText('wiki:foo:start', '[[..:..:one_ns_up:]]', 'Test setup');
idx_addPage('wiki:foo:start');
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('wiki:foo:start', 'wiki:foo:bar:start'));
$this->assertEquals('[[one_ns_up:]]', rawWiki('wiki:foo:bar:start'));
}
/**
* @covers helper_plugin_move_handler::_nsStartCheck
* @group slow
*/
function test_move_to_thisns_start(){
saveWikiText('wiki:foo:test_page', '[[..:..:bar:]]', 'Test setup');
idx_addPage('wiki:foo:test_page');
saveWikiText('bar:start', 'foo', 'Test setup');
idx_addPage('bar:start');
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('bar:start', 'wiki:foo:start'));
$this->assertEquals('[[.:]]', rawWiki('wiki:foo:test_page'));
}
function test_move_ns_in_same_ns() {
$newNamespace = 'new_ns';
$newPagename = '';
$opts = array();
$opts['page_ns'] = 'ns';
$opts['newns'] = 'parent_ns'.':'.$newNamespace;
$opts['newname'] = $newPagename;
$this->movedToId = $opts['newns'].':'.$newPagename;
//$this->move->_pm_move_recursive($opts);
$this->markTestIncomplete('Test must yet be implemented.');
}
function test_move_start_ns_into_ns_page() {
saveWikiText('bugs:start', 'Bug page', 'created');
idx_addPage('bugs:start');
saveWikiText('foo:bugs:test', '[[bugs:start]]', 'created');
idx_addPage('foo:bugs:test');
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('bugs:start', 'bugs'));
$this->assertEquals('[[:bugs]]', rawWiki('foo:bugs:test'));
$this->assertTrue($move->movePage('bugs', 'start'));
$this->assertEquals('[[:start]]', rawWiki('foo:bugs:test'));
}
function test_clean_id_move() {
saveWikiText('some_space:start', 'Space page', 'created');
idx_addPage('some_space:start');
saveWikiText('foo:bar:test', '[[some space:start]]', 'created');
idx_addPage('foo:bar:test');
/** @var helper_plugin_move_op $move */
$move = plugin_load('helper', 'move_op');
$this->assertTrue($move->movePage('some_space:start', 'spaceless:start'));
$this->assertEquals('[[spaceless:start]]', rawWiki('foo:bar:test'));
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
require_once(__DIR__ . '/../helper/plan.php');
/**
* Test cases for the move plugin
*
* @group plugin_move
* @group plugins
*/
class plugin_move_plan_test extends DokuWikiTest {
/**
* Create some page namespace structure
*/
function setUp():void {
$pages = array(
'animals:mammals:bear:brownbear',
'animals:mammals:bear:blackbear',
'animals:mammals:cute:otter',
'animals:mammals:cute:cat',
'animals:mammals:cute:dog',
'animals:insects:butterfly:fly',
'animals:insects:butterfly:moth',
'animals:monkey',
'humans:programmers:andi',
'humans:programmers:joe',
'humans:programmers:john',
'yeti'
);
foreach($pages as $page) {
saveWikiText($page, $page, 'test setup');
}
parent::setUp();
}
/**
* Check that the plan is sorted into the right order
*/
function test_sorting() {
$plan = new test_helper_plugin_move_plan();
$plan->addPageNamespaceMove('animals:mammals:bear', 'animals:mammals:cute:bear');
$plan->addPageNamespaceMove('humans:programmers', 'animals:mammals:cute:programmers');
$plan->addPageMove('humans:programmers:andi', 'animals:insects:butterfly:andi');
$plan->addPageMove('yeti', 'humans:yeti');
$plan->addPageMove('animals:monkey', 'monkey');
$sorted = $plan->sortedPlan();
// the plan is sorted FORWARD (first things first)
$this->assertEquals(5, count($sorted));
$this->assertEquals('humans:programmers:andi', $sorted[0]['src']);
$this->assertEquals('animals:monkey', $sorted[1]['src']);
$this->assertEquals('yeti', $sorted[2]['src']);
$this->assertEquals('animals:mammals:bear', $sorted[3]['src']);
$this->assertEquals('humans:programmers', $sorted[4]['src']);
}
/**
* Move a page out of a namespace and then move the namespace elsewhere
*/
function test_pageinnamespace() {
$plan = new test_helper_plugin_move_plan();
$plan->addPageNamespaceMove('animals:mammals:cute', 'animals:mammals:funny');
$plan->addPageMove('animals:mammals:cute:otter', 'animals:mammals:otter');
$plan->commit();
$list = $plan->getList('pagelist');
// the files are sorted BACKWARDS (first things last)
$this->assertEquals(3, count($list));
$this->assertEquals("animals:mammals:cute:otter\tanimals:mammals:otter", trim($list[2]));
$this->assertEquals("animals:mammals:cute:cat\tanimals:mammals:funny:cat", trim($list[1]));
$this->assertEquals("animals:mammals:cute:dog\tanimals:mammals:funny:dog", trim($list[0]));
}
}
/**
* Class test_helper_plugin_move_plan
*
* gives access to some internal stuff of the class
*/
class test_helper_plugin_move_plan extends helper_plugin_move_plan {
/**
* Access the sorted plan
*
* @return array
*/
function sortedPlan() {
usort($this->plan, array($this, 'planSorter'));
return $this->plan;
}
/**
* Get the full saved list specified by name
*
* @param $name
* @return array
*/
function getList($name) {
return file($this->files[$name]);
}
}
@@ -0,0 +1,274 @@
<?php
/**
* mock class to access the helper_plugin_move_plan::stepThroughDocuments function in tests
*/
class helper_plugin_move_plan_mock extends helper_plugin_move_plan {
public $moveLog = array();
public function __construct() {
parent::__construct();
$this->MoveOperator = new helper_plugin_move_op_mock;
}
public function stepThroughDocumentsCall($type = parent::TYPE_PAGES, $skip = false) {
return $this->stepThroughDocuments($type, $skip);
}
public function getMoveOperator() {
return $this->MoveOperator;
}
public function setMoveOperator($newMoveOPerator) {
$this->MoveOperator = $newMoveOPerator;
}
public function build_log_line($type, $from, $to, $success) {
$logEntry = array($type,$from,$to,$success);
array_push($this->moveLog,$logEntry);
return parent::build_log_line($type, $from, $to, $success);
}
}
class helper_plugin_move_op_mock extends helper_plugin_move_op {
public $movedPages = array();
public $fail = false;
public function movePage($src, $dst) {
if ($this->fail !== false && count($this->movedPages) == $this->fail) {
$this->fail=false;
// Store a msg as it is expected by the plugin
msg("Intentional failure in test case.", -1);
return false;
}
$moveOperation = array($src => $dst);
array_push($this->movedPages,$moveOperation);
return true;
}
}
/**
* Test cases for helper_plugin_move_plan::stepThroughDocuments function of the move plugin
*
* @group plugin_move
* @group plugin_move_unittests
* @group plugins
* @group unittests
*/
class plugin_move_stepThroughDocuments_test extends DokuWikiTest {
public function setUp(): void {
parent::setUp();
$opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts';
if(file_exists($opts_file)){
unlink($opts_file);
}
$file = "oldns:page01\tnewns:page01\n"
. "oldns:page02\tnewns:page02\n"
. "oldns:page03\tnewns:page03\n"
. "oldns:page04\tnewns:page04\n"
. "oldns:page05\tnewns:page05\n"
. "oldns:page06\tnewns:page06\n"
. "oldns:page07\tnewns:page07\n"
. "oldns:page08\tnewns:page08\n"
. "oldns:page09\tnewns:page09\n"
. "oldns:page10\tnewns:page10\n"
. "oldns:page11\tnewns:page11\n"
. "oldns:page12\tnewns:page12\n"
. "oldns:page13\tnewns:page13\n"
. "oldns:page14\tnewns:page14\n"
. "oldns:page15\tnewns:page15\n"
. "oldns:page16\tnewns:page16\n"
. "oldns:page17\tnewns:page17\n"
. "oldns:page18\tnewns:page18";
$file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist';
io_saveFile($file_path,$file);
}
/**
* @covers helper_plugin_move_plan::stepThroughDocuments
*/
public function test_stepThroughPages() {
$file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist';
$mock = new helper_plugin_move_plan_mock();
$actual_return = $mock->stepThroughDocumentsCall();
$actual_file = file_get_contents($file_path);
$expected_file = "oldns:page01\tnewns:page01\n"
. "oldns:page02\tnewns:page02\n"
. "oldns:page03\tnewns:page03\n"
. "oldns:page04\tnewns:page04\n"
. "oldns:page05\tnewns:page05\n"
. "oldns:page06\tnewns:page06\n"
. "oldns:page07\tnewns:page07\n"
. "oldns:page08\tnewns:page08";
$expected_pages_run = -10;
$this->assertSame($expected_pages_run,$actual_return,"return values differ");
$this->assertSame($expected_file,$actual_file, "files differ");
$actual_move_Operator = $mock->getMoveOperator();
$this->assertSame(array('oldns:page18' => 'newns:page18',),$actual_move_Operator->movedPages[0]);
$this->assertSame(array('oldns:page09' => 'newns:page09',),$actual_move_Operator->movedPages[9]);
$this->assertTrue(!isset($actual_move_Operator->movedPages[10]));
$expected_log = array('P','oldns:page18','newns:page18',true);
$this->assertSame($expected_log,$mock->moveLog[0]);
$expected_log = array('P','oldns:page09','newns:page09',true);
$this->assertSame($expected_log,$mock->moveLog[9]);
$this->assertTrue(!isset($mock->moveLog[10]));
$opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts';
$actual_options = unserialize(io_readFile($opts_file));
$this->assertSame($expected_pages_run,$actual_options['pages_run'],'saved options are wrong');
}
/**
* @covers helper_plugin_move_plan::stepThroughDocuments
*/
public function test_stepThroughPages_skip() {
$file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist';
$mock = new helper_plugin_move_plan_mock();
$actual_return = $mock->stepThroughDocumentsCall(1,true);
$actual_file = file_get_contents($file_path);
$expected_file = "oldns:page01\tnewns:page01\n"
. "oldns:page02\tnewns:page02\n"
. "oldns:page03\tnewns:page03\n"
. "oldns:page04\tnewns:page04\n"
. "oldns:page05\tnewns:page05\n"
. "oldns:page06\tnewns:page06\n"
. "oldns:page07\tnewns:page07\n"
. "oldns:page08\tnewns:page08";
$expected_pages_run = -10;
$this->assertSame($expected_pages_run,$actual_return,"return values differ");
$this->assertSame($expected_file,$actual_file, "files differ");
$actual_move_Operator = $mock->getMoveOperator();
$this->assertSame(array('oldns:page17' => 'newns:page17',),$actual_move_Operator->movedPages[0]);
$this->assertSame(array('oldns:page09' => 'newns:page09',),$actual_move_Operator->movedPages[8]);
$this->assertTrue(!isset($actual_move_Operator->movedPages[9]));
$expected_log = array('P','oldns:page17','newns:page17',true);
$this->assertSame($expected_log,$mock->moveLog[0]);
$expected_log = array('P','oldns:page09','newns:page09',true);
$this->assertSame($expected_log,$mock->moveLog[8]);
$this->assertTrue(!isset($mock->moveLog[9]));
$opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts';
$actual_options = unserialize(io_readFile($opts_file));
$this->assertSame($expected_pages_run,$actual_options['pages_run'],'saved options are wrong');
}
/**
* @covers helper_plugin_move_plan::stepThroughDocuments
*/
public function test_stepThroughPages_fail() {
$file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist';
$mock = new helper_plugin_move_plan_mock();
$fail_at_item = 5;
$actual_move_Operator = $mock->getMoveOperator();
$actual_move_Operator->fail = $fail_at_item;
$mock->setMoveOperator($actual_move_Operator);
$actual_return = $mock->stepThroughDocumentsCall();
$actual_file = file_get_contents($file_path);
$expected_file = "oldns:page01\tnewns:page01\n"
. "oldns:page02\tnewns:page02\n"
. "oldns:page03\tnewns:page03\n"
. "oldns:page04\tnewns:page04\n"
. "oldns:page05\tnewns:page05\n"
. "oldns:page06\tnewns:page06\n"
. "oldns:page07\tnewns:page07\n"
. "oldns:page08\tnewns:page08\n"
. "oldns:page09\tnewns:page09\n"
. "oldns:page10\tnewns:page10\n"
. "oldns:page11\tnewns:page11\n"
. "oldns:page12\tnewns:page12\n"
. "oldns:page13\tnewns:page13";
$expected_pages_run = false;
$this->assertSame($expected_pages_run,$actual_return,"return values differ");
$this->assertSame($expected_file,$actual_file, "files differ");
$actual_move_Operator = $mock->getMoveOperator();
$this->assertSame(array('oldns:page18' => 'newns:page18',),$actual_move_Operator->movedPages[0]);
$lastIndex = 4;
$this->assertSame(array('oldns:page14' => 'newns:page14',),$actual_move_Operator->movedPages[$lastIndex]);
$this->assertTrue(!isset($actual_move_Operator->movedPages[$lastIndex + 1]));
$expected_log = array('P','oldns:page13','newns:page13',false);
$this->assertSame($expected_log,$mock->moveLog[5]);
$this->assertTrue(!isset($mock->moveLog[6]));
$opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts';
$actual_options = unserialize(io_readFile($opts_file));
$this->assertSame(-$fail_at_item,$actual_options['pages_run'],'saved options are wrong');
}
/**
* @covers helper_plugin_move_plan::stepThroughDocuments
*/
public function test_stepThroughPages_fail_autoskip() {
global $conf;
$conf['plugin']['move']['autoskip'] = '1';
$file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist';
$mock = new helper_plugin_move_plan_mock();
$actual_move_Operator = $mock->getMoveOperator();
$actual_move_Operator->fail = 5;
$mock->setMoveOperator($actual_move_Operator);
$actual_return = $mock->stepThroughDocumentsCall();
$expected_pages_run = -10;
$this->assertSame($expected_pages_run,$actual_return,"return values differ");
$actual_file = file_get_contents($file_path);
$expected_file = "oldns:page01\tnewns:page01\n"
. "oldns:page02\tnewns:page02\n"
. "oldns:page03\tnewns:page03\n"
. "oldns:page04\tnewns:page04\n"
. "oldns:page05\tnewns:page05\n"
. "oldns:page06\tnewns:page06\n"
. "oldns:page07\tnewns:page07\n"
. "oldns:page08\tnewns:page08";
$this->assertSame($expected_file,$actual_file, "files differ");
$actual_move_Operator = $mock->getMoveOperator();
$this->assertSame(array('oldns:page18' => 'newns:page18',),$actual_move_Operator->movedPages[0]);
$lastIndex = 8;
$this->assertSame(array('oldns:page09' => 'newns:page09',),$actual_move_Operator->movedPages[$lastIndex]);
$this->assertTrue(!isset($actual_move_Operator->movedPages[$lastIndex + 1]), "The number of moved pages is incorrect");
$expected_log = array('P','oldns:page18','newns:page18',true);
$this->assertSame($expected_log,$mock->moveLog[0]);
$expected_log = array('P','oldns:page13','newns:page13',false);
$this->assertSame($expected_log,$mock->moveLog[5]);
$expected_log = array('P','oldns:page09','newns:page09',true);
$this->assertSame($expected_log,$mock->moveLog[9]);
$this->assertTrue(!isset($mock->moveLog[10]), "The number of logged items is incorrect");
$opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts';
$actual_options = unserialize(io_readFile($opts_file));
$this->assertSame($expected_pages_run,$actual_options['pages_run'],'saved options are wrong');
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* tests for the template button of the move plugin
*
* @author Michael Große <grosse@cosmocode.de>
* @group plugin_move
* @group plugins
*/
class move_tpl_test extends DokuWikiTest {
public function setUp(): void {
parent::setUp();
}
protected $pluginsEnabled = array('move');
/**
* @coversNothing
* Integration-ish kind of test testing action_plugin_move_rename::handle_pagetools
*//*
function test_tpl () {
saveWikiText('wiki:foo:start', '[[..:..:one_ns_up:]]', 'Test setup');
idx_addPage('wiki:foo:start');
$request = new TestRequest();
$response = $request->get(array(),'/doku.php?id=wiki:foo:start');
$this->assertTrue(strstr($response->getContent(),'class="plugin_move_page"') !== false);
}*/
/**
* @covers action_plugin_move_rename::renameOkay
*/
function test_renameOkay() {
global $conf;
global $USERINFO;
$conf['superuser'] = 'john';
$_SERVER['REMOTE_USER'] = 'john';
$USERINFO['grps'] = array('admin','user');
saveWikiText('wiki:foo:start', '[[..:..:one_ns_up:]]', 'Test setup');
idx_addPage('wiki:foo:start');
$move_rename = new action_plugin_move_rename();
$this->assertTrue($move_rename->renameOkay('wiki:foo:start'));
}
}