1<?php 2/* 3 * Copyright (c) 2016 Mark C. Prins <mprins@users.sf.net> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/** 19 * Syntax tests for the backlinks plugin. 20 * 21 * @group plugin_backlinks 22 * @group plugins 23 */ 24class syntax_plugin_backlinks_test extends DokuWikiTest { 25 26 protected $pluginsEnabled = array('backlinks'); 27 28 /** 29 * copy data and add pages to the index. 30 */ 31 public static function setUpBeforeClass(){ 32 parent::setUpBeforeClass(); 33 global $conf; 34 35 TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/'); 36 37 dbglog(scandir(DOKU_TMP_DATA.'index/'),"Index dir (after copy)"); 38 dbglog(scandir(DOKU_TMP_DATA.'pages/'),"Pages dir (before test)"); 39 } 40 41 function setUp() { 42 global $conf; 43 //$this->pluginsEnabled[] = 'backlinks'; 44 parent::setUp(); 45 46 47 $conf['allowdebug'] = 1; 48 $conf['cachetime'] = -1; 49 50 $data = array(); 51 search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); 52 53 dbglog($data, "pages for indexing"); 54 55 $verbose = false; 56 $force = false; 57 //foreach($data as $val) { 58 // idx_addPage($val['id'], $verbose, $force); 59 //} 60 idx_addPage('wiki:dokuwiki', $verbose, $force); 61 idx_addPage('bob_ross_says', $verbose, $force); 62 idx_addPage('link', $verbose, $force); 63 idx_addPage('backlinks_syntax', $verbose, $force); 64 } 65 66 public function tearDown() { 67 global $conf; 68 parent::tearDown(); 69 70 // try to get the debug log 71 72 //$log = file_get_contents($conf['cachedir'].'/debug.log'); 73 $log = file_get_contents(DOKU_TMP_DATA.'/cache/debug.log'); 74 if(!$log) { 75 print_r($log); 76 unlink($conf['cachedir'].'/debug.log'); 77 } 78 } 79 80 public function testIndex() { 81 $indexer = idx_get_indexer(); 82 $query = array('Ross'); 83 84 print_r(idx_lookup($query)); 85 86 $this->assertEquals( 87 array('Ross' => array('link' => 1)), 88 idx_lookup($query) 89 ); 90 91 } 92 93 public function testDokuWikiPage() { 94 $request = new TestRequest(); 95 $response = $request->get(array('id'=>'wiki:dokuwiki'), '/doku.php'); 96 $this->assertTrue( 97 strpos($response->getContent(), 'DokuWiki') !== false, 98 'DokuWiki was not a word in the output' 99 ); 100 } 101 102 public function testLinksPage() { 103 $request = new TestRequest(); 104 $response = $request->get(array('id'=>'link'), '/doku.php'); 105 106 $this->assertTrue( 107 strpos($response->getContent(), 'A link to Bob Ross') !== false, 108 'A link to Bob Ross was not in the output' 109 ); 110 } 111 112 public function testStoryPage() { 113 $request = new TestRequest(); 114 $response = $request->get(array('id'=>'bob_ross_says'), '/doku.php'); 115 116 $this->assertTrue( 117 strpos($response->getContent(), 'Bob Ross says') !== false, 118 'Bob Ross says was not in the output' 119 ); 120 } 121 122 public function testBacklinks() { 123 $request = new TestRequest(); 124 $response = $request->get(array('id'=>'backlinks_syntax'), '/doku.php'); 125 126 $this->assertTrue( 127 strpos($response->getContent(), 'Backlinks to what Bob Ross says') !== false, 128 '"Backlinks to what Bob Ross says" was not in the output' 129 ); 130 131 $doc = phpQuery::newDocument($response->getContent()); 132 //look for id="plugin__backlinks" 133 $this->assertEquals(1, pq('#plugin__backlinks', $doc)->length, 134 'There should be one backlinks element'); 135 136 $wikilink = pq('.idx .li .wikilink1', $doc); 137 $this->assertEquals(4, $wikilink->length, 'There should be 4 backlinks'); 138 139 dbglog(pq($wikilink->contents()[0], $doc),"wikilink[0]"); 140 $this->assertEquals($wikilink->contents()[3],'A link to Bob Ross', 141 'The last backlink should be a link to Bob Ross'); 142 } 143} 144