summaryrefslogtreecommitdiff
path: root/_test/cases/inc
diff options
context:
space:
mode:
Diffstat (limited to '_test/cases/inc')
-rw-r--r--_test/cases/inc/DifferenceEngine.test.php31
-rw-r--r--_test/cases/inc/mail_isvalid.test.php4
-rw-r--r--_test/cases/inc/parser/parser_links.test.php82
-rw-r--r--_test/cases/inc/parserutils_set_metadata_during_rendering.test.php93
4 files changed, 206 insertions, 4 deletions
diff --git a/_test/cases/inc/DifferenceEngine.test.php b/_test/cases/inc/DifferenceEngine.test.php
new file mode 100644
index 000000000..294f0e6e3
--- /dev/null
+++ b/_test/cases/inc/DifferenceEngine.test.php
@@ -0,0 +1,31 @@
+<?php
+require_once DOKU_INC.'inc/DifferenceEngine.php';
+
+class differenceengine_test extends UnitTestCase {
+
+ function test_white_between_words(){
+ // From FS#2161
+ global $lang;
+
+ $df = new Diff(explode("\n","example"),
+ explode("\n","example example2"));
+
+ $idf = new InlineDiffFormatter();
+ $tdf = new TableDiffFormatter();
+
+ $this->assertEqual($idf->format($df), '<tr><td colspan="4" class="diff-blockheader">@@ ' . $lang['line'] .
+ ' -1 +1 @@&nbsp;<span class="diff-deletedline"><del>' . $lang['deleted'] .
+ '</del></span>&nbsp;<span class="diff-addedline">' . $lang['created'] .
+ '</span></td></tr>
+
+<tr><td colspan="4">example&nbsp;<span class="diff-addedline">example2</span></td></tr>
+');
+ $this->assertEqual($tdf->format($df),
+ '<tr><td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
+&nbsp; &nbsp;&nbsp;<td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
+</tr>
+<tr><td>-</td><td class="diff-deletedline">example</td><td>+</td><td class="diff-addedline">example&nbsp;<strong>example2</strong></td></tr>
+');
+ }
+}
+//Setup VIM: ex: et ts=4 :
diff --git a/_test/cases/inc/mail_isvalid.test.php b/_test/cases/inc/mail_isvalid.test.php
index 4e047499f..d8c88765e 100644
--- a/_test/cases/inc/mail_isvalid.test.php
+++ b/_test/cases/inc/mail_isvalid.test.php
@@ -25,7 +25,8 @@ class mail_isvalid extends UnitTestCase {
$tests[] = array('bu[g]s@php.net1',false);
$tests[] = array('somebody@somewhere.museum',true);
$tests[] = array('somebody@somewhere.travel',true);
-
+ $tests[] = array('root@[2010:fb:fdac::311:2101]',true);
+ $tests[] = array('test@example', true); // we allow local addresses
// tests from http://code.google.com/p/php-email-address-validation/ below
@@ -62,7 +63,6 @@ class mail_isvalid extends UnitTestCase {
$tests[] = array('test@.org', false);
$tests[] = array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false); // 64 characters is maximum length for local part. This is 65.
$tests[] = array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false); // 255 characters is maximum length for domain. This is 256.
- $tests[] = array('test@example', false);
$tests[] = array('test@[123.123.123.123', false);
$tests[] = array('test@123.123.123.123]', false);
diff --git a/_test/cases/inc/parser/parser_links.test.php b/_test/cases/inc/parser/parser_links.test.php
index 62e3b3b99..81186ef5e 100644
--- a/_test/cases/inc/parser/parser_links.test.php
+++ b/_test/cases/inc/parser/parser_links.test.php
@@ -38,6 +38,86 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser {
$this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls);
}
+ function testExternalIPv4() {
+ $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
+ $this->P->parse("Foo http://123.123.3.21/foo Bar");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('externallink',array('http://123.123.3.21/foo', NULL)),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls);
+ }
+
+ function testExternalIPv6() {
+ $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
+ $this->P->parse("Foo http://[3ffe:2a00:100:7031::1]/foo Bar");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('externallink',array('http://[3ffe:2a00:100:7031::1]/foo', NULL)),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls);
+ }
+
+ function testExternalMulti(){
+ $this->teardown();
+
+ $links = array(
+ 'http://www.google.com',
+ 'HTTP://WWW.GOOGLE.COM',
+ 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
+ 'http://[1080:0:0:0:8:800:200C:417A]/index.html',
+ 'http://[3ffe:2a00:100:7031::1]',
+ 'http://[1080::8:800:200C:417A]/foo',
+ 'http://[::192.9.5.5]/ipng',
+ 'http://[::FFFF:129.144.52.38]:80/index.html',
+ 'http://[2010:836B:4179::836B:4179]',
+ );
+ $titles = array(false,null,'foo bar');
+ foreach($links as $link){
+ foreach($titles as $title){
+ if($title === false){
+ $source = $link;
+ $name = null;
+ }elseif($title === null){
+ $source = "[[$link]]";
+ $name = null;
+ }else{
+ $source = "[[$link|$title]]";
+ $name = $title;
+ }
+ $this->signal('failinfo',$source);
+
+ $this->setup();
+ $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink());
+ $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
+ $this->P->parse("Foo $source Bar");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('externallink',array($link, $name)),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls);
+ $this->teardown();
+ }
+ }
+
+ $this->setup();
+ }
+
function testExternalLinkJavascript() {
$this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
$this->P->parse("Foo javascript:alert('XSS'); Bar");
@@ -81,8 +161,6 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser {
$this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls);
}
function testEmail() {
-/* $this->fail('The emaillink mode seems to cause php 5.0.5 to segfault');
- return; //FIXME: is this still true?*/
$this->P->addMode('emaillink',new Doku_Parser_Mode_Emaillink());
$this->P->parse("Foo <bugs@php.net> Bar");
$calls = array (
diff --git a/_test/cases/inc/parserutils_set_metadata_during_rendering.test.php b/_test/cases/inc/parserutils_set_metadata_during_rendering.test.php
new file mode 100644
index 000000000..8319da298
--- /dev/null
+++ b/_test/cases/inc/parserutils_set_metadata_during_rendering.test.php
@@ -0,0 +1,93 @@
+<?php
+
+require_once DOKU_INC.'inc/init.php';
+
+class parserutils_set_metadata_during_rendering_test extends UnitTestCase {
+ // the id used for this test case
+ private $id;
+ // if the test case is currently running
+ private $active = false;
+ // the original plugin controller
+ private $plugin_controller;
+
+ // the actual test
+ 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');
+ }
+
+ // helper for the action plugin part of the test, tries executing p_set_metadata during rendering
+ function helper_set_metadata($event, $meta) {
+ if ($this->active) {
+ p_set_metadata($this->id, $meta, false, true);
+ $key = array_pop(array_keys($meta));
+ $this->assertTrue(is_string($meta[$key])); // ensure we really have a key
+ // ensure that the metadata property hasn't been set previously
+ $this->assertNotEqual($meta[$key], p_get_metadata($this->id, $key));
+ }
+ }
+
+ // helper for injecting an instruction for this test case
+ function helper_inject_test_instruction($event) {
+ if ($this->active)
+ $event->data->calls[] = array('plugin', array('parserutils_test', array()));
+ }
+
+ // fake syntax plugin rendering method that tries calling p_set_metadata during the actual rendering process
+ function render($format, &$renderer, $data) {
+ if ($this->active) {
+ $key = 'test_during_rendering';
+ p_set_metadata($this->id, array($key => 'test'), false, true);
+ // ensure that the metadata property hasn't been set previously
+ $this->assertNotEqual($key, p_get_metadata($this->id, $key));
+ }
+ }
+
+ // wrapper function for the fake plugin controller
+ function getList($type='',$all=false){
+ return $this->plugin_controller->getList();
+ }
+
+ // wrapper function for the fake plugin controller, return $this for the fake syntax of this test
+ function &load($type,$name,$new=false,$disabled=false){
+ if ($name == 'parserutils_test') {
+ return $this;
+ } else {
+ return $this->plugin_controller->load($type, $name, $new, $disabled);
+ }
+ }
+}
+
+// vim:ts=4:sw=4:et: