1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8/** 9 * Test wiki page rendering options 10 */ 11 12namespace Tiki\Lib\wiki; 13use TikiLib; 14 15class WikiLibTest extends \PHPUnit_Framework_TestCase 16{ 17 18 private $pageName = 'WikiLib Test Page'; 19 20 protected function setUp() 21 { 22 global $testhelpers; 23 24 require_once(__DIR__ . '/../TestHelpers.php'); 25 $testhelpers->simulate_tiki_script_context(); 26 27 require_once(__DIR__ . '/../../../lib/wiki/renderlib.php'); 28 } 29 30 protected function tearDown() 31 { 32 global $testhelpers; 33 34 $testhelpers->remove_all_versions($this->pageName); 35 36 $testhelpers->stop_simulating_tiki_script_context(); 37 } 38 39 /** 40 * Test per wiki page autotoc settings 41 * 42 * @throws \Exception 43 */ 44 public function testProcessPageDisplayOptions() 45 { 46 global $prefs, $testhelpers, $headerlib; 47 $wikilib = TikiLib::lib('wiki'); 48 49 // testing autotoc per page settings 50 $prefs['wiki_auto_toc'] = 'y'; 51 $prefs['feature_page_title'] = 'n'; 52 $prefs['javascript_enabled'] = 'y'; 53 54 $pageContent = '! Heading H1 55!! Heading H2 56Some text 57!!! Heading H3 58Some text 59!! Second Heading H2 60Some more text 61'; 62 63 $testhelpers->create_page($this->pageName, 0, $pageContent); 64 65 // processPageDisplayOptions needs this 66 $_REQUEST['page'] = $this->pageName; 67 68 $prefs['wiki_toc_default'] = 'on'; 69 $wikilib->set_page_auto_toc($this->pageName, 0); 70 71 $wikilib->processPageDisplayOptions(); 72 $tags = $headerlib->output_js_files(); 73 $expected = 'lib/jquery_tiki/autoToc.js'; 74 $this->assertContains($expected, $tags, 'Autotoc on, page set to default'); 75 76 $headerlib->clear_js(true); 77 $wikilib->set_page_auto_toc($this->pageName, -1); 78 $wikilib->processPageDisplayOptions(); 79 $tags = $headerlib->output_js_files(); 80 $this->assertNotContains($expected, $tags, 'Autotoc on, page set to off'); 81 82 $headerlib->clear_js(true); 83 $wikilib->set_page_auto_toc($this->pageName, 1); 84 $wikilib->processPageDisplayOptions(); 85 $tags = $headerlib->output_js_files(); 86 $this->assertContains($expected, $tags, 'Autotoc on, page set to on'); 87 88 $prefs['wiki_toc_default'] = 'off'; 89 $headerlib->clear_js(true); 90 $wikilib->set_page_auto_toc($this->pageName, 0); 91 $wikilib->processPageDisplayOptions(); 92 $tags = $headerlib->output_js_files(); 93 $this->assertNotContains($expected, $tags, 'Autotoc off, page set to default'); 94 95 $tags = $headerlib->output_js_files(); 96 $wikilib->set_page_auto_toc($this->pageName, -1); 97 $wikilib->processPageDisplayOptions(); 98 $headerlib->clear_js(true); 99 $this->assertNotContains($expected, $tags, 'Autotoc off, page set to off'); 100 101 $headerlib->clear_js(true); 102 $wikilib->set_page_auto_toc($this->pageName, 1); 103 $wikilib->processPageDisplayOptions(); 104 $tags = $headerlib->output_js_files(); 105 $this->assertContains($expected, $tags, 'Autotoc off, page set to on'); 106 107 } 108} 109