1<?php 2/** 3 * General tests for the simplenavi plugin 4 * 5 * @author Michael Große <grosse@cosmocode.de> 6 * 7 * @group Michael Große <grosse@cosmocode.de> 8 * @group plugin_simplenavi 9 * @group plugins 10 */ 11 12class parser_plugin_simplenavi_test extends DokuWikiTest { 13 14 protected $pluginsEnabled = array('simplenavi'); 15 16 function setUp() { 17 parent::setUp(); 18 saveWikiText('sidebar', '{{simplenavi>}}', 'create test sidebar'); 19 saveWikiText('namespace1:foo', 'bar', 'foobar'); 20 saveWikiText('namespace2:foo', 'bar', 'foobar'); 21 saveWikiText('namespace12:foo', 'bar', 'foobar'); 22 saveWikiText('namespace123:foo', 'bar', 'foobar'); 23 saveWikiText('namespace21:foo', 'bar', 'foobar'); 24 25 } 26 27 function tearDown() { 28 parent::tearDown(); 29 30 } 31 32 /** 33 * @covers syntax_plugin_simplenavi 34 */ 35 function test_output_natural() { 36 global $ID, $conf; 37 $conf['plugin']['simplenavi']['sort'] = 'natural'; 38 39 $ID = 'wiki:start'; 40 $request = new TestRequest(); 41 $input = array( 42 'id' => 'namespace1:foo' 43 ); 44 saveWikiText('wiki:start', 'some text', 'Test init'); 45 $response = $request->post($input); 46 $naviBegin = strpos($response->getContent(), '<!-- ********** ASIDE ********** -->')+36; 47 $naviEnd = strpos($response->getContent(), '<!-- /aside -->'); 48 $navi = substr($response->getContent(),$naviBegin,$naviEnd-$naviBegin); 49 $navilines = explode("\n",$navi); 50 $listlines = array(); 51 foreach ($navilines as $line) { 52 if (substr($line,0,4) != '<li ') continue; 53 if (strpos($line,'namespace') === false) continue; 54 $listlines[] = $line; 55 } 56 57 $this->assertTrue(strpos($listlines[0],'href="/./doku.php?id=namespace1:start"') !== false, 'namespace1 should be before other namespaces and espacially before its subpages and namespaces'); 58 $this->assertTrue(strpos($listlines[1],'href="/./doku.php?id=namespace1:foo"') !== false, 'level2 should follow open level1'); 59 $this->assertTrue(strpos($listlines[2],'href="/./doku.php?id=namespace2:start"') !== false, 'namespace2 should be after namespace1 and its pages.'); 60 $this->assertTrue(strpos($listlines[3],'href="/./doku.php?id=namespace12:start"') !== false, 'namespace12 should be after namespace2.'); 61 $this->assertTrue(strpos($listlines[4],'href="/./doku.php?id=namespace21:start"') !== false, 'namespace21 should be after namespace12.'); 62 $this->assertTrue(strpos($listlines[5],'href="/./doku.php?id=namespace123:start"') !== false, 'namespace123 should be after namespace21.'); 63 } 64 65 /** 66 * @covers syntax_plugin_simplenavi 67 */ 68 function test_output_ascii() { 69 global $ID, $conf; 70 $conf['plugin']['simplenavi']['sort'] = 'ascii'; 71 72 $ID = 'wiki:start'; 73 $request = new TestRequest(); 74 $input = array( 75 'id' => 'namespace1:foo' 76 ); 77 saveWikiText('wiki:start', 'some text', 'Test init'); 78 $response = $request->post($input); 79 $naviBegin = strpos($response->getContent(), '<!-- ********** ASIDE ********** -->')+36; 80 $naviEnd = strpos($response->getContent(), '<!-- /aside -->'); 81 $navi = substr($response->getContent(),$naviBegin,$naviEnd-$naviBegin); 82 $navilines = explode("\n",$navi); 83 $listlines = array(); 84 foreach ($navilines as $line) { 85 if (substr($line,0,4) != '<li ') continue; 86 if (strpos($line,'namespace') === false) continue; 87 $listlines[] = $line; 88 } 89 90 $this->assertTrue(strpos($listlines[0],'href="/./doku.php?id=namespace1:start"') !== false, 'namespace1 should be before other namespaces and espacially before its subpages and namespaces'); 91 $this->assertTrue(strpos($listlines[1],'href="/./doku.php?id=namespace1:foo"') !== false, 'level2 should follow open level1.'); 92 $this->assertTrue(strpos($listlines[2],'href="/./doku.php?id=namespace12:start"') !== false, 'namespace12 should be after namespace1 and its pages.'); 93 $this->assertTrue(strpos($listlines[3],'href="/./doku.php?id=namespace123:start"') !== false, 'namespace123 should be after namespace12.'); 94 $this->assertTrue(strpos($listlines[4],'href="/./doku.php?id=namespace2:start"') !== false, 'namespace2 should be after namespace123.'); 95 $this->assertTrue(strpos($listlines[5],'href="/./doku.php?id=namespace21:start"') !== false, 'namespace21 should be after namespace2.'); 96 } 97 98} 99 100 101 102