public function test_sort() { saveWikiText('title1', 'test', 'test'); $title = new Title('title1'); $title->setTitle('This is a title'); saveWikiText('title2', 'test', 'test'); $title = new Title('title2'); $title->setTitle('This is a title'); saveWikiText('title3', 'test', 'test'); $title = new Title('title3'); $title->setTitle('Another Title'); $this->loadSchemaJSON('pageschema'); $this->saveData('test1', 'pageschema', array('singletitle' => 'title1')); $this->saveData('test2', 'pageschema', array('singletitle' => 'title2')); $this->saveData('test3', 'pageschema', array('singletitle' => 'title3')); $search = new Search(); $search->addSchema('pageschema'); $search->addColumn('%pageid%'); $search->addColumn('singletitle'); $search->addSort('singletitle', true); /** @var Value[][] $result */ $result = $search->execute(); $this->assertEquals(3, count($result)); $this->assertEquals('test3', $result[0][0]->getValue()); $this->assertEquals('test1', $result[1][0]->getValue()); $this->assertEquals('test2', $result[2][0]->getValue()); }
function test_p_set_metadata_during_rendering() { global $EVENT_HANDLER; $this->id = 'test:p_set_metadata_during_rendering'; $this->active = true; // write the wiki page so it exists and needs to be rendered saveWikiText($this->id, 'Test ' . time(), 'Test data setup'); $EVENT_HANDLER->register_hook('PARSER_METADATA_RENDER', 'BEFORE', $this, 'helper_set_metadata', array('test_before_set' => 'test')); $EVENT_HANDLER->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'helper_set_metadata', array('test_after_set' => 'test')); $EVENT_HANDLER->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'helper_inject_test_instruction'); // Change the global plugin controller so this test can be a fake syntax plugin global $plugin_controller; $this->plugin_controller = $plugin_controller; $plugin_controller = $this; // the actual rendering, all hooks should be executed here $newMeta = p_get_metadata($this->id); // restore the plugin controller $plugin_controller = $this->plugin_controller; // assert that all three calls to p_set_metadata have been successful $this->assertEqual($newMeta['test_before_set'], 'test'); $this->assertEqual($newMeta['test_after_set'], 'test'); $this->assertEqual($newMeta['test_during_rendering'], 'test'); // clean up $this->active = false; // make sure the saved metadata is the one that has been rendered $this->assertEqual($newMeta, p_get_metadata($this->id)); saveWikiText($this->id, '', 'Test data remove'); }
function test_parameters() { saveWikiText('test:links', '[[wiki:syntax?do=export_raw]] [[:web:scripts:add_vhost.sh?do=export_raw]]', 'Init tests'); idx_addPage('test:links'); $this->assertEquals(array('test:links'), ft_backlinks('wiki:syntax')); $this->assertEquals(array('test:links'), ft_backlinks('web:scripts:add_vhost.sh')); }
function handle_approve(&$event, $param) { global $ID, $REV; if (!$this->can_approve()) { return; } if ($event->data == 'show' && isset($_GET['approve'])) { //Add or remove the new line from the end of the page. Silly but needed. $content = rawWiki($ID, ''); if (substr($content, -1) == "\n") { $content = substr($content, 0, -1); } else { $content .= "\n"; } saveWikiText($ID, $content, APPROVED); header('Location: ?id=' . $ID); } /*czytacze wydzą najnowszą zatwierdzaną*/ $last = $this->find_lastest_approved(); /*użytkownik może tylko czytać i jednocześnie istnieje jakaś zatwierdzona strona*/ if (auth_quickaclcheck($ID) <= AUTH_READ && $last != -1) { /*najnowsza zatwierdzona nie jest najnowszą*/ /*i jednocześnie znajdujemy się w stronach nowszych niż aktualna zatwierdzona*/ if ($last != 0 && ($REV > $last || $REV == 0)) { $REV = $last; } } }
public function test_media_in_deleted_pages() { saveWikiText('test:internalmedia_usage', '{{internalmedia.png}} {{..:internal media.png}}', 'Test initialization'); idx_addPage('test:internalmedia_usage'); saveWikiText('test:internalmedia_usage', '', 'Deleted'); $this->assertEquals(array(), ft_mediause('internal_media.png')); $this->assertEquals(array(), ft_mediause('test:internalmedia.png')); }
public function setUp() { parent::setUp(); saveWikiText('testpage', 'Foo bar baz.', 'Test initialization'); saveWikiText('notfound', 'Foon barn bazn.', 'Test initialization'); idx_addPage('testpage'); idx_addPage('notfound'); }
/** * Create some page namespace structure */ function setUp() { $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(); }
/** * @coversNothing */ public function test_no_aprroved_banner() { global $conf; $conf['plugin']['publish']['hide_approved_banner'] = 1; saveWikiText('foo', 'bar', 'foobar'); $request = new TestRequest(); $response = $request->get(array(), '/doku.php?id=foo&publish_approve=1'); $this->assertTrue(strpos($response->getContent(), '<div class="approval') === false, 'The approved banner is still showing even so it is supposed not to show.'); }
public function test_relation_references_without_link() { $text = "My page without a link."; $id = "source"; saveWikiText($id, $text, 'Created'); self::assertEquals(null, p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); $text .= DOKU_LF . "~~META:relation references=foo~~"; saveWikiText($id, $text, 'Updated'); self::assertEquals(array('foo' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); }
public function test_media_in_footnotes() { saveWikiText('test:media_footnotes', '(({{footnote.png?20x50}} [[foonote|{{:footlink.png}}]]))', 'Test initialization'); idx_addPage('test:media_footnotes'); $query = array('test:footnote.png', 'footlink.png'); $this->assertEquals(array( 'test:footnote.png' => array('test:media_footnotes'), 'footlink.png' => array('test:media_footnotes') ), idx_get_indexer()->lookupKey('relation_media', $query)); }
public function setUp() { parent::setUp(); saveWikiText('foo', "====== Page-Heading ======", 'summary'); $req = new TestRequest(); $req->get(array(), '/doku.php?id=foo'); saveWikiText('testpage', "---- dataentry Testentry ----\n" . "test1_title: foo|bar\n" . "----\n", 'summary'); //trigger save to db $req = new TestRequest(); $req->get(array(), '/doku.php?id=testpage'); }
public function test_PageLockedByYou() { $page_id = 'test:main'; $GLOBALS['INPUT']->server->set('REMOTE_USER', 'testuser'); saveWikiText($page_id, 'some text', 'some summary'); lock($page_id); $json = $this->doCall($page_id, null, 'testuser'); $this->assertInstanceOf('\\stdClass', $json); $this->assertObjectHasAttribute('error', $json); $this->assertRegExp("/^\\d{2}:\\d{2}:\\d{2} Page is locked by You. You cannot delete page during edit.\$/", $json->error); }
public function setUp() { $this->pluginsEnabled[] = 'tag'; parent::setUp(); saveWikiText('tagged_page', '{{tag>mytag test2tag}}', 'Test'); saveWikiText('negative_page', '{{tag>negative_tag mytag}}', 'Test setup'); saveWikiText('third_page', '{{tag>third_tag}}', 'Test setup'); idx_addPage('tagged_page'); idx_addPage('negative_page'); idx_addPage('third_page'); }
public function setUp() { global $conf; $this->pluginsEnabled[] = 'tag'; parent::setUp(); $conf['plugin']['tag']['sortkey'] = 'ns'; $this->helper = plugin_load('helper', 'tag'); foreach ($this->pages as $page) { saveWikiText($page, '{{tag>mytag}}', 'Test'); idx_addPage($page); } }
/** * @covers action_plugin_move_rename::renameOkay */ function test_renameOkay() { global $conf; global $USERINFO; $conf['superuser'] = '******'; $_SERVER['REMOTE_USER'] = '******'; $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')); }
/** * @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])); }
public function setUp() { $this->pluginsEnabled[] = 'include'; parent::setUp(); $this->helper = plugin_load('helper', 'include'); saveWikiText('included', 'Example content with link [[#jump]]', 'Test setup'); idx_addPage('test:included'); saveWikiText('test:includefull', '{{page>..:included}}', 'Test setup'); idx_addPage('test:includefull'); saveWikiText('test:includefirst', '{{page>..:included&firstseconly}}', 'Test setup'); idx_addPage('test:includefirst'); }
/** * Handle the user input [required] * * @param helper_plugin_bureaucracy_field[] $fields the list of fields in the form * @param string $thanks the thank you message as defined in the form * or default one. Might be modified by the action * before returned * @param array $argv additional arguments passed to the action * @return bool|string false on error, $thanks on success */ public function run($fields, $thanks, $argv) { global $ID; // prepare replacements $this->prepareNamespacetemplateReplacements(); $this->prepareDateTimereplacements(); $this->prepareLanguagePlaceholder(); $this->prepareNoincludeReplacement(); $this->prepareFieldReplacements($fields); //handle arguments $page_to_modify = array_shift($argv); if ($page_to_modify === '_self') { # shortcut to modify the same page as the submitter $page_to_modify = $ID; } else { //resolve against page which contains the form resolve_pageid(getNS($ID), $page_to_modify, $ignored); } $template_section_id = cleanID(array_shift($argv)); if (!page_exists($page_to_modify)) { msg(sprintf($this->getLang('e_pagenotexists'), html_wikilink($page_to_modify)), -1); return false; } // check auth // // This is an important point. In order to be able to modify a page via this method ALL you need is READ access to the page // This is good for admins to be able to only allow people to modify a page via a certain method. If you want to protect the page // from people to WRITE via this method, deny access to the form page. $auth = $this->aclcheck($page_to_modify); // runas if ($auth < AUTH_READ) { msg($this->getLang('e_denied'), -1); return false; } // fetch template $template = rawWiki($page_to_modify); if (empty($template)) { msg(sprintf($this->getLang('e_template'), $page_to_modify), -1); return false; } // do the replacements $template = $this->updatePage($template, $template_section_id); if (!$template) { msg(sprintf($this->getLang('e_failedtoparse'), $page_to_modify), -1); return false; } // save page saveWikiText($page_to_modify, $template, sprintf($this->getLang('summary'), $ID)); //thanks message with redirect $link = wl($page_to_modify); return sprintf($this->getLang('pleasewait'), "<script type='text/javascript' charset='utf-8'>location.replace('{$link}')</script>", html_wikilink($page_to_modify)); }
public function test_basic_weekpicker_syntax() { global $INFO; $id = 'test:plugin_datepicker:syntax4'; $INFO['id'] = $id; saveWikiText($id, '<weekpicker 14/02>' . DOKU_LF . '<weekpicker# 14/02>' . DOKU_LF . '<weekpicker\\ 14/02>' . DOKU_LF, 'test'); $xhtml = p_wiki_xhtml($id); $doc = phpQuery::newDocument($xhtml); $mselector = pq("span.weekpicker", $doc); $this->assertTrue($mselector->length === 3); $this->assertEquals('14/02', trim($mselector->eq(0)->text())); $this->assertEquals('14/02', trim($mselector->eq(1)->text())); $this->assertEquals('14/02', trim($mselector->eq(2)->text())); }
public function test_rename() { /** @var $move helper_plugin_move_op */ $move = plugin_load('helper', 'move_op'); if (!$move) { return; } // disable the test when move is not installed saveWikiText('editx', 'Page to rename', 'Testcase create'); saveWikiText('links', '{{section>links#foo}} {{page>editx}} {{page>:eDitX&nofooter}} {{section>editx#test}} {{page>editx&nofooter}}', 'Testcase created'); idx_addPage('editx'); idx_addPage('links'); $this->assertTrue($move->movePage('editx', 'test:edit')); $this->assertEquals('{{section>links#foo}} {{page>test:edit}} {{page>test:edit&nofooter}} {{section>test:edit#test}} {{page>test:edit&nofooter}}', rawWiki('links')); }
public function setUp() { $this->pluginsEnabled[] = 'include'; parent::setUp(); $this->helper = plugin_load('helper', 'include'); saveWikiText('wiki:included', <<<EOF * [[test|{{dokuwiki.png}}]] * [[#test|{{dokuwiki.png?w=200}}]] * [[doku>test|{{dokuwiki.png?w=300}}]] * [[test|{{https://www.dokuwiki.org/lib/tpl/dokuwiki/images/logo.png}}]] EOF , 'Test setup'); idx_addPage('wiki:included'); saveWikiText('test:include', '{{page>..:wiki:included}}', 'Test setup'); idx_addPage('test:include'); }
function setUp() { global $ID, $conf; parent::setUp(); $ID = 'cached'; $file = wikiFN($ID); $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching saveWikiText($ID, 'Content', 'Created'); $this->cache = new cache_renderer($ID, $file, 'xhtml'); $this->cache->storeCache('Test'); // set the modification times explicitly (overcome Issue #694) $time = time(); touch($file, $time - 1); touch($this->cache->cache, $time); }
public function test_rename() { global $ID; /** @var $pagemove helper_plugin_pagemove */ $pagemove = plugin_load('helper', 'pagemove'); if (!$pagemove) return; // disable the test when pagemove is not installed saveWikiText('editx', 'Page to rename', 'Testcase create'); saveWikiText('links', '{{section>links#foo}} {{page>editx}} {{page>:eDitX&nofooter}} {{section>editx#test}} {{page>editx&nofooter}}', 'Testcase created'); idx_addPage('editx'); idx_addPage('links'); $ID = 'editx'; $opts['ns'] = ''; $opts['newname'] = 'edit'; $opts['newns'] = 'test'; $pagemove->move_page($opts); $this->assertEquals('{{section>links#foo}} {{page>test:edit}} {{page>test:edit&nofooter}} {{section>test:edit#test}} {{page>test:edit&nofooter}}', rawWiki('links')); }
function test_topic_tag() { saveWikiText('tagged_page', '{{tag>mytag test2tag}}', 'Test'); saveWikiText('topic_page', '{{topic>mytag}}' . DOKU_LF . DOKU_LF . '{{tag>topictag mytag}}' . DOKU_LF, 'Test'); idx_addPage('topic_page'); idx_addPage('tagged_page'); $this->assertContains('tag:topictag', p_wiki_xhtml('topic_page'), 'Page with tag syntax doesn\'t contain tag output'); $this->assertNotContains('tag:test2tag', p_wiki_xhtml('topic_page'), 'Page with tag and topic syntax tag which is listed in a page that is listed in the topic syntax but not on the page itself'); $this->assertContains('topic_page', p_wiki_xhtml('topic_page'), 'Page with topic and tag syntax doesn\'t list itself in the topic syntax'); $this->assertContains('tagged_page', p_wiki_xhtml('topic_page'), 'Page with topic syntax doesn\'t list matching page'); $this->assertContains('tag:mytag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax doesn\'t contain tag output'); $this->assertContains('tag:test2tag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax doesn\'t contain tag output'); $this->assertNotContains('tag:topictag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax contains tag from a page in which it is listed in the topic syntax'); saveWikiText('tagged_page', '{{tag>test2tag}}', 'Deleted mytag'); $this->assertNotContains('tagged_page', p_wiki_xhtml('topic_page'), 'Page that no longer contains the tag is still listed in the topic syntax (caching problems?)'); $this->assertNotContains('tag:mytag', p_wiki_xhtml('tagged_page'), 'Removed tag is still listed in XHTML output'); }
/** * @group slow */ public function test_moveSingleMedia_colonstart() { global $AUTH_ACL; $AUTH_ACL[] = "wiki:*\t@ALL\t16"; $AUTH_ACL[] = "foobar:*\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')); }
/** * Blackbox integration test of action_plugin_publish_mail::getLastApproved * * @coversNothing */ public function test_getLastApproved() { global $ID; $ID = 'foo'; saveWikiText('foo', 'bar old', 'foobar'); saveWikiText('foo', 'bar approved', 'foobar'); $data = pageinfo(); $expected_revision = $data['currentrev']; //Make sure we have the rights to actully approve a revision $this->assertSame(255, auth_quickaclcheck('foo')); $request = new TestRequest(); $request->get(array(), '/doku.php?id=foo&publish_approve'); saveWikiText('foo', 'bar new', 'foobar'); /** @var helper_plugin_publish $helper */ $helper = plugin_load('helper', 'publish'); $actual_lastapproved_helper = $helper->getLatestApprovedRevision($ID); $this->assertSame($expected_revision, $actual_lastapproved_helper); }
function test_meta_rename_to_existing_value() { $this->indexer->addMetaKeys($this->old_id, array('mkey' => array('old_value', 'new_value'))); saveWikiText('newvalue', 'Test page', ''); idx_addPage('newvalue'); $this->indexer->addMetaKeys('newvalue', array('mkey' => array('new_value'))); saveWikiText('oldvalue', 'Test page', ''); idx_addPage('oldvalue'); $this->indexer->addMetaKeys('oldvalue', array('mkey' => array('old_value'))); $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to existing value failed'); $query = 'old_value'; $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); $query = 'new_value'; $result = $this->indexer->lookupKey('mkey', $query); $this->assertContains($this->old_id, $result, 'Page with both values can\'t be found anymore'); $this->assertContains('newvalue', $result, 'Page with new value can\'t be found anymore'); $this->assertContains('oldvalue', $result, 'Page with only the old value can\'t be found anymore'); }
public function test_safeindex() { global $conf; global $AUTH_ACL; $conf['superuser'] = '******'; $conf['useacl'] = 1; $AUTH_ACL = array('* @ALL 0', '* @user 8', 'public @ALL 1'); $_SERVER['REMOTE_USER'] = '******'; saveWikiText('parent', "{{page>child}}\n\n[[public_link]]\n\n{{page>public}}", 'Test parent created'); saveWikiText('child', "[[foo:private]]", 'Test child created'); saveWikiText('public', "[[foo:public]]", 'Public page created'); idx_addPage('parent'); idx_addPage('child'); idx_addPage('public'); $this->assertEquals(array('parent', 'public'), ft_backlinks('foo:public')); $this->assertEquals(array('child'), ft_backlinks('foo:private')); $this->assertEquals(array('parent'), ft_backlinks('public_link')); }
function test_staleness() { global $ID; $ID = 'stale'; $file = wikiFN($ID); # Prepare test page saveWikiText($ID, 'Fresh', 'Created'); # Create stale cache $cache = new cache_renderer($ID, $file, 'xhtml'); $cache->storeCache('Stale'); $stale = $cache->retrieveCache(); # Prepare stale cache for testing $time = filemtime($file); touch($cache->cache, $time); # Make the test $fresh = p_cached_output($file, 'xhtml', $ID); $this->assertNotEquals($fresh, $stale, 'Stale cache failed to expire'); }
protected function prepareLookup() { saveWikiText('title1', 'test', 'test'); $title = new Title('title1'); $title->setTitle('This is a title'); saveWikiText('title2', 'test', 'test'); $title = new Title('title2'); $title->setTitle('This is a 2nd title'); saveWikiText('title3', 'test', 'test'); $title = new Title('title3'); $title->setTitle('Another Title'); $this->loadSchemaJSON('pageschema', '', 0, true); $access = AccessTable::byTableName('pageschema', 0); $access->saveData(array('singlepage' => 'title1', 'multipage' => array('title1'), 'singletitle' => 'title1', 'multititle' => array('title1'))); $access = AccessTable::byTableName('pageschema', 0); $access->saveData(array('singlepage' => 'title2', 'multipage' => array('title2'), 'singletitle' => 'title2', 'multititle' => array('title2'))); $access = AccessTable::byTableName('pageschema', 0); $access->saveData(array('singlepage' => 'title3', 'multipage' => array('title3'), 'singletitle' => 'title3', 'multititle' => array('title3'))); }