]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/lib/InlineParserTest.php
Properly save and restore the request args for each test.
[SourceForge/phpwiki.git] / tests / unit / lib / InlineParserTest.php
1 <?php
2 rcs_id('$Id: InlineParserTest.php,v 1.4 2004-07-09 12:29:26 rurban Exp $');
3
4 /* Copyright (C) 2004, Dan Frankowski <dfrankow@cs.umn.edu>
5  * testLinks: Reini Urban
6  */
7
8 require_once 'lib/InlineParser.php';
9 require_once 'PHPUnit.php';
10
11 class InlineParserTest extends phpwiki_TestCase {
12
13     function testNoWikiWords() {
14         $str1 = 'This has no wiki words, and is all text.';
15         $xmlc1 = TransformInline($str1);
16         $this->assertTrue(isa($xmlc1, 'XmlContent'));
17         $c1 = $xmlc1->getContent();
18         $this->assertEquals(1, count($c1)); 
19         $this->assertEquals($str1, $c1[0]); 
20     }
21
22     function testWikiWord() {
23         $ww = 'WikiWord';
24         $str1 = "This has 1 $ww.";
25         $xml = TransformInline($str1);
26         $this->assertTrue(isa($xml, 'XmlContent'));
27         $c1 = $xml->getContent();
28         $this->assertEquals(3, count($c1));
29         $this->assertTrue(isa($c1[1], 'Cached_WikiLink')); 
30
31         $this->assertEquals('This has 1 ', $c1[0]); 
32         $this->assertEquals($ww, $c1[1]->asString()); 
33         $this->assertEquals('.', $c1[2]); 
34     }
35     
36     function testLinks() {
37         $uplink = 'http://'.(defined('SERVER_NAME')?SERVER_NAME:'').DATA_PATH.'/uploads/image.jpg';
38         $tests = array("[label|link]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}',
39                        "[ label | link.jpg ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";}i:2;s:0:"";}}',
40                        "[ image.jpg | link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";b:0;s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}',
41                        //"[ Upload:image.jpg | link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";s:'.strlen($uplink).':"'.$uplink.'";s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}',
42                        //"[ http://server/image.jpg | link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}',
43                        "[ label | http://server/link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}',
44                        "[ label | Upload:link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"cached_interwikilink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}',
45                        "[ label | phpwiki:action=link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"cached_phpwikiurl":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}',
46                        "Upload:image.jpg" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"cached_interwikilink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}',
47                        "http://server/image.jpg" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}',
48                        "http://server/link" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}',
49                        "[http:/server/~name/]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}',
50                        "http:/server/~name/" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}'
51                        );
52         //$i = 0;
53         foreach ($tests as $wiki => $dump) {
54             //print $i++ . " .. ";
55             $xml = TransformInline($wiki);
56             $this->assertTrue(isa($xml, 'XmlContent'));
57             //echo var_export($xml),"\n";
58             //echo serialize($xml),"\n";
59             $this->assertEquals($dump, serialize($xml));
60         }
61     }
62     
63 }
64
65
66 // (c-file-style: "gnu")
67 // Local Variables:
68 // mode: php
69 // tab-width: 8
70 // c-basic-offset: 4
71 // c-hanging-comment-ender-p: nil
72 // indent-tabs-mode: nil
73 // End:   
74 ?>