Merge pull request #85 from helpfulrobot/convert-to-psr-2

Converted to PSR-2
This commit is contained in:
Daniel Hensby 2015-11-21 12:25:47 +00:00
commit 974f5b7b81
26 changed files with 4223 additions and 4033 deletions

View File

@ -5,8 +5,8 @@
*
* @package docsviewer
*/
class DocumentationHelper {
class DocumentationHelper
{
/**
* String helper for cleaning a file name to a readable version.
*
@ -14,7 +14,8 @@ class DocumentationHelper {
*
* @return string $name output
*/
public static function clean_page_name($name) {
public static function clean_page_name($name)
{
$name = self::trim_extension_off($name);
$name = self::trim_sort_number($name);
@ -30,7 +31,8 @@ class DocumentationHelper {
*
* @return string $name output
*/
public static function clean_page_url($name) {
public static function clean_page_url($name)
{
$name = str_replace(array(' '), '_', $name);
$name = self::trim_extension_off($name);
@ -50,7 +52,8 @@ class DocumentationHelper {
*
* @return string
*/
public static function trim_sort_number($name) {
public static function trim_sort_number($name)
{
$name = preg_replace("/^[0-9]*[_-]+/", '', $name);
return $name;
@ -65,7 +68,8 @@ class DocumentationHelper {
*
* @return string
*/
public static function trim_extension_off($name) {
public static function trim_extension_off($name)
{
if (strrpos($name, '.') !== false) {
return substr($name, 0, strrpos($name, '.'));
}
@ -80,7 +84,8 @@ class DocumentationHelper {
*
* @return string
*/
public static function get_extension($name) {
public static function get_extension($name)
{
if (preg_match('/\.[a-z]+$/', $name)) {
return substr($name, strrpos($name, '.') + 1);
}

View File

@ -27,8 +27,8 @@
* @package framework
* @subpackage manifest
*/
class DocumentationManifest {
class DocumentationManifest
{
/**
* @config
*
@ -78,7 +78,8 @@ class DocumentationManifest {
* @param bool $includeTests Include tests in the manifest.
* @param bool $forceRegen Force the manifest to be regenerated.
*/
public function __construct($forceRegen = false) {
public function __construct($forceRegen = false)
{
$this->cacheKey = 'manifest';
$this->forceRegen = $forceRegen;
$this->registeredEntities = new ArrayList();
@ -97,7 +98,8 @@ class DocumentationManifest {
* Either manually registered through the YAML syntax or automatically
* loaded through investigating the file system for `docs` folder.
*/
public function setupEntities() {
public function setupEntities()
{
if ($this->registeredEntities->Count() > 0) {
return;
}
@ -164,7 +166,8 @@ class DocumentationManifest {
}
}
public function getRealPath($path) {
public function getRealPath($path)
{
if (substr($path, 0, 1) != '/') {
$path = Controller::join_links(BASE_PATH, $path);
}
@ -175,7 +178,8 @@ class DocumentationManifest {
/**
* @return ArrayList
*/
public function getEntities() {
public function getEntities()
{
return $this->registeredEntities;
}
@ -185,7 +189,8 @@ class DocumentationManifest {
*
* @return void
*/
public function populateEntitiesFromInstall() {
public function populateEntitiesFromInstall()
{
if ($this->automaticallyPopulated) {
// already run
return;
@ -224,7 +229,8 @@ class DocumentationManifest {
/**
*
*/
protected function init() {
protected function init()
{
if (!$this->forceRegen && $data = $this->cache->load($this->cacheKey)) {
$this->pages = $data['pages'];
$this->redirects = $data['redirects'];
@ -240,7 +246,8 @@ class DocumentationManifest {
*
* @return array
*/
public function getPages() {
public function getPages()
{
if (!$this->inited) {
$this->init();
}
@ -248,7 +255,8 @@ class DocumentationManifest {
return $this->pages;
}
public function getRedirects() {
public function getRedirects()
{
if (!$this->inited) {
$this->init();
}
@ -261,7 +269,8 @@ class DocumentationManifest {
*
* @return DocumentationPage
*/
public function getPage($url) {
public function getPage($url)
{
$pages = $this->getPages();
$url = $this->normalizeUrl($url);
@ -292,7 +301,8 @@ class DocumentationManifest {
* @param type $url
* @return string
*/
public function getRedirect($url) {
public function getRedirect($url)
{
$pages = $this->getRedirects();
$url = $this->normalizeUrl($url);
@ -306,7 +316,8 @@ class DocumentationManifest {
*
* @param bool $cache
*/
public function regenerate($cache = true) {
public function regenerate($cache = true)
{
$finder = new DocumentationManifestFileFinder();
$finder->setOptions(array(
'dir_callback' => array($this, 'handleFolder'),
@ -373,7 +384,8 @@ class DocumentationManifest {
* @param string $link
* @return string
*/
protected function stripLinkBase($link) {
protected function stripLinkBase($link)
{
return ltrim(str_replace(
Config::inst()->get('DocumentationViewer', 'link_base'),
'',
@ -387,7 +399,8 @@ class DocumentationManifest {
* @param string $basename
* @param string $path
*/
protected function addPage($page, $basename, $path) {
protected function addPage($page, $basename, $path)
{
$link = $this->stripLinkBase($page->Link());
$this->pages[$link] = array(
@ -406,7 +419,8 @@ class DocumentationManifest {
* @param string $from
* @param string $to
*/
protected function addRedirect($from, $to) {
protected function addRedirect($from, $to)
{
$fromLink = $this->stripLinkBase($from);
$toLink = $this->stripLinkBase($to);
$this->redirects[$fromLink] = $toLink;
@ -415,7 +429,8 @@ class DocumentationManifest {
/**
*
*/
public function handleFolder($basename, $path, $depth) {
public function handleFolder($basename, $path, $depth)
{
$folder = Injector::inst()->create(
'DocumentationFolder', $this->entity, $basename, $path
);
@ -443,7 +458,8 @@ class DocumentationManifest {
* @param string $path
* @param int $depth
*/
public function handleFile($basename, $path, $depth) {
public function handleFile($basename, $path, $depth)
{
$page = Injector::inst()->create(
'DocumentationPage',
$this->entity, $basename, $path
@ -471,7 +487,8 @@ class DocumentationManifest {
*
* @return ArrayList
*/
public function generateBreadcrumbs($record, $base) {
public function generateBreadcrumbs($record, $base)
{
$output = new ArrayList();
$parts = explode('/', trim($record->getRelativeLink(), '/'));
@ -509,7 +526,8 @@ class DocumentationManifest {
*
* @return ArrayData
*/
public function getNextPage($filepath, $entityBase) {
public function getNextPage($filepath, $entityBase)
{
$grabNext = false;
$fallback = null;
@ -550,7 +568,8 @@ class DocumentationManifest {
*
* @return ArrayData
*/
public function getPreviousPage($filepath, $entityPath) {
public function getPreviousPage($filepath, $entityPath)
{
$previousUrl = $previousPage = null;
foreach ($this->getPages() as $url => $page) {
@ -577,7 +596,8 @@ class DocumentationManifest {
*
* @return string
*/
public function normalizeUrl($url) {
public function normalizeUrl($url)
{
$url = trim($url, '/') .'/';
// if the page is the index page then hide it from the menu
@ -597,7 +617,8 @@ class DocumentationManifest {
*
* @return ArrayList
*/
public function getChildrenFor($entityPath, $recordPath = null) {
public function getChildrenFor($entityPath, $recordPath = null)
{
if (!$recordPath) {
$recordPath = $entityPath;
}
@ -624,11 +645,9 @@ class DocumentationManifest {
$currentPagePath = end($pagePathParts);
if ($currentPagePath == $currentRecordPath) {
$mode = 'current';
}
else if(strpos($recordPath, $pagePath) !== false) {
} elseif (strpos($recordPath, $pagePath) !== false) {
$mode = 'section';
}
else {
} else {
$mode = 'link';
}
@ -656,7 +675,8 @@ class DocumentationManifest {
*
* @return ArrayList
*/
public function getAllVersionsOfEntity(DocumentationEntity $entity) {
public function getAllVersionsOfEntity(DocumentationEntity $entity)
{
$all = new ArrayList();
foreach ($this->getEntities() as $check) {
@ -675,7 +695,8 @@ class DocumentationManifest {
*
* @return DocumentationEntity
*/
public function getStableVersion(DocumentationEntity $entity) {
public function getStableVersion(DocumentationEntity $entity)
{
foreach ($this->getEntities() as $check) {
if ($check->getKey() == $entity->getKey()) {
if ($check->getLanguage() == $entity->getLanguage()) {
@ -694,7 +715,8 @@ class DocumentationManifest {
*
* @return ArrayList
*/
public function getVersions($entity) {
public function getVersions($entity)
{
if (!$entity) {
return null;
}
@ -712,7 +734,6 @@ class DocumentationManifest {
'LinkingMode' => ($same) ? 'current' : 'link',
'IsStable' => $check->getIsStable()
)));
}
}
}
@ -723,7 +744,8 @@ class DocumentationManifest {
/**
* Returns a sorted array of all the unique versions registered
*/
public function getAllVersions() {
public function getAllVersions()
{
$versions = array();
foreach ($this->getEntities() as $entity) {

View File

@ -1,7 +1,7 @@
<?php
class DocumentationManifestFileFinder extends SS_FileFinder {
class DocumentationManifestFileFinder extends SS_FileFinder
{
/**
* @var array
*/
@ -23,7 +23,8 @@ class DocumentationManifestFileFinder extends SS_FileFinder {
/**
*
*/
public function acceptDir($basename, $pathname, $depth) {
public function acceptDir($basename, $pathname, $depth)
{
$ignored = Config::inst()->get('DocumentationManifestFileFinder', 'ignored_files');
if ($ignored) {
@ -34,5 +35,4 @@ class DocumentationManifestFileFinder extends SS_FileFinder {
return true;
}
}

View File

@ -7,8 +7,8 @@
*
* @package docsviewer
*/
class DocumentationParser {
class DocumentationParser
{
const CODE_BLOCK_BACKTICK = 1;
const CODE_BLOCK_COLON = 2;
@ -41,7 +41,8 @@ class DocumentationParser {
*
* @return String
*/
public static function parse(DocumentationPage $page, $baselink = null) {
public static function parse(DocumentationPage $page, $baselink = null)
{
if (!$page || (!$page instanceof DocumentationPage)) {
return false;
}
@ -65,7 +66,8 @@ class DocumentationParser {
return $text;
}
public static function rewrite_code_blocks($md) {
public static function rewrite_code_blocks($md)
{
$started = false;
$inner = false;
$mode = false;
@ -76,7 +78,9 @@ class DocumentationParser {
$output = array();
foreach ($lines as $i => $line) {
if($debug) var_dump('Line '. ($i + 1) . ' '. $line);
if ($debug) {
var_dump('Line '. ($i + 1) . ' '. $line);
}
// if line just contains whitespace, continue down the page.
// Prevents code blocks with leading tabs adding an extra line.
@ -86,15 +90,18 @@ class DocumentationParser {
if (!$started && preg_match('/^[\t]*:::\s*(.*)/', $line, $matches)) {
// first line with custom formatting
if($debug) var_dump('Starts a new block with :::');
if ($debug) {
var_dump('Starts a new block with :::');
}
$started = true;
$mode = self::CODE_BLOCK_COLON;
$output[$i] = sprintf('```%s', (isset($matches[1])) ? trim($matches[1]) : "");
} elseif (!$started && preg_match('/^\t*```\s*(.*)/', $line, $matches)) {
if($debug) var_dump('Starts a new block with ```');
if ($debug) {
var_dump('Starts a new block with ```');
}
$started = true;
$mode = self::CODE_BLOCK_BACKTICK;
@ -103,13 +110,16 @@ class DocumentationParser {
} elseif ($started && $mode == self::CODE_BLOCK_BACKTICK) {
// inside a backtick fenced box
if (preg_match('/^\t*```\s*/', $line, $matches)) {
if($debug) var_dump('End a block with ```');
if ($debug) {
var_dump('End a block with ```');
}
// end of the backtick fenced box. Unset the line that contains the backticks
$end = true;
} else {
if ($debug) {
var_dump('Still in a block with ```');
}
else {
if($debug) var_dump('Still in a block with ```');
// still inside the line.
if (!$started) {
@ -124,18 +134,24 @@ class DocumentationParser {
// inner line of block, or first line of standard markdown code block
// regex removes first tab (any following tabs are part of the code).
if (!$started) {
if($debug) var_dump('Start code block because of tab. No fence');
if ($debug) {
var_dump('Start code block because of tab. No fence');
}
$output[$i - 1] = '```';
} else {
if($debug) var_dump('Content is still tabbed so still inner');
if ($debug) {
var_dump('Content is still tabbed so still inner');
}
}
$output[$i] = $matches[1];
$inner = true;
$started = true;
} elseif ($started && $inner && trim($line) === "") {
if($debug) var_dump('Inner line of code block');
if ($debug) {
var_dump('Inner line of code block');
}
// still inside a colon based block, if the line is only whitespace
// then continue with with it. We can continue with it for now as
@ -164,7 +180,9 @@ class DocumentationParser {
}
if ($end) {
if($debug) var_dump('End of code block');
if ($debug) {
var_dump('End of code block');
}
$output = self::finalize_code_output($i, $output);
// reset state
@ -177,7 +195,6 @@ class DocumentationParser {
}
return implode("\n", $output);
}
/**
@ -188,18 +205,19 @@ class DocumentationParser {
*
* @return array
*/
private static function finalize_code_output($i, $output) {
private static function finalize_code_output($i, $output)
{
if (isset($output[$i]) && trim($output[$i])) {
$output[$i] .= "\n```\n";
}
else {
} else {
$output[$i] = "```";
}
return $output;
}
public static function rewrite_image_links($md, $page) {
public static function rewrite_image_links($md, $page)
{
// Links with titles
$re = '/
!
@ -240,7 +258,7 @@ class DocumentationParser {
}
// Resolve relative paths
while(strpos($relativeUrl, '/..') !== FALSE) {
while (strpos($relativeUrl, '/..') !== false) {
$relativeUrl = preg_replace('/\w+\/\.\.\//', '', $relativeUrl);
}
@ -278,7 +296,8 @@ class DocumentationParser {
* @param DocumentationPage $page
* @return String
*/
public static function rewrite_api_links($md, $page) {
public static function rewrite_api_links($md, $page)
{
// Links with titles
$re = '/
`?
@ -344,7 +363,8 @@ class DocumentationParser {
/**
*
*/
public static function rewrite_heading_anchors($md, $page) {
public static function rewrite_heading_anchors($md, $page)
{
$re = '/^\#+(.*)/m';
$md = preg_replace_callback($re, array('DocumentationParser', '_rewrite_heading_anchors_callback'), $md);
@ -354,16 +374,18 @@ class DocumentationParser {
/**
*
*/
public static function _rewrite_heading_anchors_callback($matches) {
public static function _rewrite_heading_anchors_callback($matches)
{
$heading = $matches[0];
$headingText = $matches[1];
if(preg_match('/\{\#.*\}/', $headingText)) return $heading;
if (preg_match('/\{\#.*\}/', $headingText)) {
return $heading;
}
if (!isset(self::$heading_counts[$headingText])) {
self::$heading_counts[$headingText] = 1;
}
else {
} else {
self::$heading_counts[$headingText]++;
$headingText .= "-" . self::$heading_counts[$headingText];
}
@ -376,7 +398,8 @@ class DocumentationParser {
*
* @return String
*/
public static function generate_html_id($title) {
public static function generate_html_id($title)
{
$t = $title;
$t = str_replace('&amp;', '-and-', $t);
$t = str_replace('&', '-and-', $t);
@ -396,7 +419,8 @@ class DocumentationParser {
*
* @return String Markdown
*/
public static function rewrite_relative_links($md, $page) {
public static function rewrite_relative_links($md, $page)
{
$baselink = $page->getEntity()->Link();
$re = '/
@ -437,11 +461,15 @@ class DocumentationParser {
$url = $matches[3][$i];
// Don't process API links
if(preg_match('/^api:/', $url)) continue;
if (preg_match('/^api:/', $url)) {
continue;
}
// Don't process absolute links (based on protocol detection)
$urlParts = parse_url($url);
if($urlParts && isset($urlParts['scheme'])) continue;
if ($urlParts && isset($urlParts['scheme'])) {
continue;
}
// for images we need to use the file base path
if (preg_match('/_images/', $url)) {
@ -450,8 +478,7 @@ class DocumentationParser {
$fileBaseLink,
$url
);
}
else {
} else {
// Rewrite public URL
if (preg_match('/^\//', $url)) {
// Absolute: Only path to module base
@ -463,7 +490,7 @@ class DocumentationParser {
}
// Resolve relative paths
while(strpos($relativeUrl, '..') !== FALSE) {
while (strpos($relativeUrl, '..') !== false) {
$relativeUrl = preg_replace('/[-\w]+\/\.\.\//', '', $relativeUrl);
}
@ -487,7 +514,8 @@ class DocumentationParser {
*
* @param DocumentationPage
*/
public static function retrieve_meta_data(DocumentationPage &$page) {
public static function retrieve_meta_data(DocumentationPage &$page)
{
if ($md = $page->getMarkdown()) {
$matches = preg_match_all('/
(?<key>[A-Za-z0-9_-]+):

View File

@ -9,8 +9,8 @@
* @package docsviewer
*/
class DocumentationPermalinks {
class DocumentationPermalinks
{
/**
* @var array
*/
@ -30,11 +30,11 @@ class DocumentationPermalinks {
*
* @param array
*/
public static function add($map = array()) {
public static function add($map = array())
{
if (ArrayLib::is_associative($map)) {
self::$mapping = array_merge(self::$mapping, $map);
}
else {
} else {
user_error("DocumentationPermalinks::add() requires an associative array", E_USER_ERROR);
}
}
@ -44,7 +44,8 @@ class DocumentationPermalinks {
*
* @return string|false
*/
public static function map($url) {
public static function map($url)
{
return (isset(self::$mapping[$url])) ? self::$mapping[$url] : false;
}
}

View File

@ -31,8 +31,8 @@ require_once 'Zend/Search/Lucene.php';
* @package docsviewer
*/
class DocumentationSearch {
class DocumentationSearch
{
/**
* @var bool - Is search enabled
*/
@ -82,11 +82,13 @@ class DocumentationSearch {
*/
private $modules, $versions;
public function setModules($modules) {
public function setModules($modules)
{
$this->modules = $modules;
}
public function setVersions($versions) {
public function setVersions($versions)
{
$this->versions = $versions;
}
@ -95,7 +97,8 @@ class DocumentationSearch {
*
* @param string
*/
public function setQuery($query) {
public function setQuery($query)
{
$this->query = $query;
}
@ -104,7 +107,8 @@ class DocumentationSearch {
*
* @return string
*/
public function getQuery() {
public function getQuery()
{
return $this->query;
}
@ -114,7 +118,8 @@ class DocumentationSearch {
*
* @param Controller
*/
public function setOutputController($controller) {
public function setOutputController($controller)
{
$this->outputController = $controller;
}
@ -129,7 +134,8 @@ class DocumentationSearch {
/**
* @return string
*/
public static function get_index_location() {
public static function get_index_location()
{
$location = Config::inst()->get('DocumentationSearch', 'index_location');
if (!$location) {
@ -142,8 +148,8 @@ class DocumentationSearch {
/**
* Perform a search query on the index
*/
public function performSearch() {
public function performSearch()
{
try {
$index = Zend_Search_Lucene::open(self::get_index_location());
@ -178,8 +184,7 @@ class DocumentationSearch {
$this->results = $index->find($query);
error_reporting($er);
$this->totalResults = $index->numDocs();
}
catch(Zend_Search_Lucene_Exception $e) {
} catch (Zend_Search_Lucene_Exception $e) {
user_error($e .'. Ensure you have run the rebuld task (/dev/tasks/RebuildLuceneDocsIndex)', E_USER_ERROR);
}
}
@ -187,7 +192,8 @@ class DocumentationSearch {
/**
* @return ArrayData
*/
public function getSearchResults($request) {
public function getSearchResults($request)
{
$pageLength = (isset($_GET['length'])) ? (int) $_GET['length'] : 10;
$data = array(
@ -283,7 +289,9 @@ class DocumentationSearch {
));
$obj->Current = false;
if ( $i == $currentPage ) $obj->Current = true;
if ($i == $currentPage) {
$obj->Current = true;
}
$data['SearchPages']->push($obj);
}
}
@ -296,13 +304,20 @@ class DocumentationSearch {
*
* @return string
*/
private function buildQueryUrl($params) {
private function buildQueryUrl($params)
{
$url = parse_url($_SERVER['REQUEST_URI']);
if ( ! array_key_exists('query', $url) ) $url['query'] = '';
if (! array_key_exists('query', $url)) {
$url['query'] = '';
}
parse_str($url['query'], $url['query']);
if ( ! is_array($url['query']) ) $url['query'] = array();
if (! is_array($url['query'])) {
$url['query'] = array();
}
// Remove 'start parameter if it exists
if ( array_key_exists('start', $url['query']) ) unset( $url['query']['start'] );
if (array_key_exists('start', $url['query'])) {
unset($url['query']['start']);
}
// Add extra parameters from argument
$url['query'] = array_merge($url['query'], $params);
$url['query'] = http_build_query($url['query']);
@ -314,7 +329,8 @@ class DocumentationSearch {
/**
* @return int
*/
public function getTotalResults() {
public function getTotalResults()
{
return (int) $this->totalResults;
}
@ -323,16 +339,20 @@ class DocumentationSearch {
*
* @return void
*/
public function optimizeIndex() {
public function optimizeIndex()
{
$index = Zend_Search_Lucene::open(self::get_index_location());
if($index) $index->optimize();
if ($index) {
$index->optimize();
}
}
/**
* @return String
*/
public function getTitle() {
public function getTitle()
{
return ($this->outputController) ? $this->outputController->Title : _t('DocumentationSearch.SEARCH', 'Search');
}
@ -342,13 +362,13 @@ class DocumentationSearch {
*
* @param array
*/
public static function set_meta_data($data) {
public static function set_meta_data($data)
{
if (is_array($data)) {
foreach ($data as $key => $value) {
self::$meta_data[strtolower($key)] = $value;
}
}
else {
} else {
user_error("set_meta_data must be passed an array", E_USER_ERROR);
}
}
@ -358,7 +378,8 @@ class DocumentationSearch {
*
* @return array
*/
public static function get_meta_data() {
public static function get_meta_data()
{
$data = self::$meta_data;
$defaults = array(
@ -370,7 +391,9 @@ class DocumentationSearch {
);
foreach ($defaults as $key => $value) {
if(isset($data[$key])) $defaults[$key] = $data[$key];
if (isset($data[$key])) {
$defaults[$key] = $data[$key];
}
}
return $defaults;
@ -380,7 +403,8 @@ class DocumentationSearch {
* Renders the search results into a template. Either the search results
* template or the Atom feed.
*/
public function renderResults() {
public function renderResults()
{
if (!$this->results && $this->query) {
$this->performSearch();
}

View File

@ -7,17 +7,19 @@
* @package docsviewer
*/
class DocumentationOpenSearchController extends Controller {
class DocumentationOpenSearchController extends Controller
{
private static $allowed_actions = array(
'description'
);
public function index() {
public function index()
{
return $this->httpError(404);
}
public function description() {
public function description()
{
$viewer = new DocumentationViewer();
if (!$viewer->canView()) {

View File

@ -12,8 +12,8 @@
* @package docsviewer
*/
class DocumentationViewer extends Controller {
class DocumentationViewer extends Controller
{
/**
* @var array
*/
@ -82,7 +82,8 @@ class DocumentationViewer extends Controller {
/**
*
*/
public function init() {
public function init()
{
parent::init();
if (!$this->canView()) {
@ -111,18 +112,21 @@ class DocumentationViewer extends Controller {
*
* @return bool
*/
public function canView() {
public function canView()
{
return (Director::isDev() || Director::is_cli() ||
!$this->config()->get('check_permission') ||
Permission::check($this->config()->get('check_permission'))
);
}
public function hasAction($action) {
public function hasAction($action)
{
return true;
}
public function checkAccessAction($action) {
public function checkAccessAction($action)
{
return true;
}
@ -136,7 +140,8 @@ class DocumentationViewer extends Controller {
*
* @return SS_HTTPResponse
*/
public function handleAction($request, $action) {
public function handleAction($request, $action)
{
// if we submitted a form, let that pass
if (!$request->isGET()) {
return parent::handleAction($request, $action);
@ -174,7 +179,6 @@ class DocumentationViewer extends Controller {
strlen($base)
);
} else {
}
//
@ -270,7 +274,8 @@ class DocumentationViewer extends Controller {
*
* @return SS_HTTPResponse
*/
public function httpError($status, $message = null) {
public function httpError($status, $message = null)
{
$this->init();
$class = get_class($this);
@ -284,7 +289,8 @@ class DocumentationViewer extends Controller {
/**
* @return DocumentationManifest
*/
public function getManifest() {
public function getManifest()
{
if (!$this->manifest) {
$flush = SapphireTest::is_running_test() || (isset($_GET['flush']));
@ -297,7 +303,8 @@ class DocumentationViewer extends Controller {
/**
* @return string
*/
public function getLanguage() {
public function getLanguage()
{
if (!$lang = $this->request->param('Lang')) {
$lang = $this->request->param('Action');
}
@ -313,7 +320,8 @@ class DocumentationViewer extends Controller {
*
* @return DataObject
*/
public function getMenu() {
public function getMenu()
{
$entities = $this->getManifest()->getEntities();
$output = new ArrayList();
$record = $this->getPage();
@ -372,7 +380,8 @@ class DocumentationViewer extends Controller {
*
* @return HTMLText
*/
public function getContent() {
public function getContent()
{
$page = $this->getPage();
$html = $page->getHTML();
$html = $this->replaceChildrenCalls($html);
@ -380,7 +389,8 @@ class DocumentationViewer extends Controller {
return $html;
}
public function replaceChildrenCalls($html) {
public function replaceChildrenCalls($html)
{
$codes = new ShortcodeParser();
$codes->register('CHILDREN', array($this, 'includeChildren'));
@ -390,7 +400,8 @@ class DocumentationViewer extends Controller {
/**
* Short code parser
*/
public function includeChildren($args) {
public function includeChildren($args)
{
if (isset($args['Folder'])) {
$children = $this->getManifest()->getChildrenFor(
Controller::join_links(dirname($this->record->getPath()), $args['Folder'])
@ -421,7 +432,8 @@ class DocumentationViewer extends Controller {
/**
* @return ArrayList
*/
public function getChildren() {
public function getChildren()
{
if ($this->record instanceof DocumentationFolder) {
return $this->getManifest()->getChildrenFor(
$this->record->getPath()
@ -440,7 +452,8 @@ class DocumentationViewer extends Controller {
*
* @return ArrayList
*/
public function getBreadcrumbs() {
public function getBreadcrumbs()
{
if ($this->record) {
return $this->getManifest()->generateBreadcrumbs(
$this->record,
@ -452,21 +465,24 @@ class DocumentationViewer extends Controller {
/**
* @return DocumentationPage
*/
public function getPage() {
public function getPage()
{
return $this->record;
}
/**
* @return DocumentationEntity
*/
public function getEntity() {
public function getEntity()
{
return ($this->record) ? $this->record->getEntity() : null;
}
/**
* @return ArrayList
*/
public function getVersions() {
public function getVersions()
{
return $this->getManifest()->getVersions($this->getEntity());
}
@ -475,14 +491,16 @@ class DocumentationViewer extends Controller {
*
* @return string
*/
public function getTitle() {
public function getTitle()
{
return ($this->record) ? $this->record->getTitle() : null;
}
/**
* @return string
*/
public function AbsoluteLink($action) {
public function AbsoluteLink($action)
{
return Controller::join_links(
Director::absoluteBaseUrl(),
$this->Link($action)
@ -494,7 +512,8 @@ class DocumentationViewer extends Controller {
*
* @return string
*/
public function Link($action = '') {
public function Link($action = '')
{
$link = Controller::join_links(
Config::inst()->get('DocumentationViewer', 'link_base'),
$this->getLanguage(),
@ -511,7 +530,8 @@ class DocumentationViewer extends Controller {
*
* @return GroupedList
*/
public function AllPages() {
public function AllPages()
{
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
@ -536,7 +556,8 @@ class DocumentationViewer extends Controller {
*
* @return Form
*/
public function DocumentationSearchForm() {
public function DocumentationSearchForm()
{
if (!Config::inst()->get('DocumentationSearch', 'enabled')) {
return false;
}
@ -568,7 +589,8 @@ class DocumentationViewer extends Controller {
* @param string link
* @param array options ('rewritetrunktomaster')
*/
public static function set_edit_link($module, $link, $options = array()) {
public static function set_edit_link($module, $link, $options = array())
{
self::$edit_links[$module] = array(
'url' => $link,
'options' => $options
@ -580,12 +602,11 @@ class DocumentationViewer extends Controller {
*
* @return string
*/
public function getEditLink() {
public function getEditLink()
{
$page = $this->getPage();
if ($page) {
$entity = $page->getEntity();
@ -632,7 +653,8 @@ class DocumentationViewer extends Controller {
*
* @return DocumentationPage
*/
public function getNextPage() {
public function getNextPage()
{
return ($this->record)
? $this->getManifest()->getNextPage(
$this->record->getPath(), $this->getEntity()->getPath())
@ -645,7 +667,8 @@ class DocumentationViewer extends Controller {
*
* @return DocumentationPage
*/
public function getPreviousPage() {
public function getPreviousPage()
{
return ($this->record)
? $this->getManifest()->getPreviousPage(
$this->record->getPath(), $this->getEntity()->getPath())
@ -655,7 +678,8 @@ class DocumentationViewer extends Controller {
/**
* @return string
*/
public function getGoogleAnalyticsCode() {
public function getGoogleAnalyticsCode()
{
$code = $this->config()->get('google_analytics_code');
if ($code) {
@ -666,11 +690,13 @@ class DocumentationViewer extends Controller {
/**
* @return string
*/
public function getDocumentationTitle() {
public function getDocumentationTitle()
{
return $this->config()->get('documentation_title');
}
public function getDocumentationBaseHref() {
public function getDocumentationBaseHref()
{
return Config::inst()->get('DocumentationViewer', 'link_base');
}
}

View File

@ -1,20 +1,20 @@
<?php
class DocumentationSearchExtension extends Extension {
class DocumentationSearchExtension extends Extension
{
/**
* Return an array of folders and titles
*
* @return array
*/
public function getSearchedEntities() {
public function getSearchedEntities()
{
$entities = array();
if (!empty($_REQUEST['Entities'])) {
if (is_array($_REQUEST['Entities'])) {
$entities = Convert::raw2att($_REQUEST['Entities']);
}
else {
} else {
$entities = explode(',', Convert::raw2att($_REQUEST['Entities']));
$entities = array_combine($entities, $entities);
}
@ -28,15 +28,15 @@ class DocumentationSearchExtension extends Extension {
*
* @return array
*/
public function getSearchedVersions() {
public function getSearchedVersions()
{
$versions = array();
if (!empty($_REQUEST['Versions'])) {
if (is_array($_REQUEST['Versions'])) {
$versions = Convert::raw2att($_REQUEST['Versions']);
$versions = array_combine($versions, $versions);
}
else {
} else {
$version = Convert::raw2att($_REQUEST['Versions']);
$versions[$version] = $version;
}
@ -50,7 +50,8 @@ class DocumentationSearchExtension extends Extension {
*
* @return HTMLText|null
*/
public function getSearchQuery() {
public function getSearchQuery()
{
if (isset($_REQUEST['Search'])) {
return DBField::create_field('HTMLText', $_REQUEST['Search']);
} elseif (isset($_REQUEST['q'])) {
@ -61,7 +62,8 @@ class DocumentationSearchExtension extends Extension {
/**
* Past straight to results, display and encode the query.
*/
public function getSearchResults() {
public function getSearchResults()
{
$query = $this->getSearchQuery();
$search = new DocumentationSearch();
@ -79,15 +81,16 @@ class DocumentationSearchExtension extends Extension {
*
* @return Form
*/
public function AdvancedSearchForm() {
public function AdvancedSearchForm()
{
return new DocumentationAdvancedSearchForm($this->owner);
}
/**
* @return bool
*/
public function getAdvancedSearchEnabled() {
public function getAdvancedSearchEnabled()
{
return Config::inst()->get("DocumentationSearch", 'advanced_search_enabled');
}
}

View File

@ -25,9 +25,10 @@
*
* @package docsviewer
*/
class DocumentationStaticPublisherExtension extends Extension {
public function alterExportUrls(&$urls) {
class DocumentationStaticPublisherExtension extends Extension
{
public function alterExportUrls(&$urls)
{
$manifest = new DocumentationManifest(true);
foreach ($manifest->getPages() as $url => $page) {

View File

@ -7,9 +7,10 @@
* @return false|ArrayData
*/
class DocumentationViewerVersionWarning extends Extension {
public function VersionWarning() {
class DocumentationViewerVersionWarning extends Extension
{
public function VersionWarning()
{
$page = $this->owner->getPage();
if (!$page) {
@ -36,8 +37,7 @@ class DocumentationViewerVersionWarning extends Extension {
'FutureRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())
)));
}
else {
} else {
return $this->owner->customise(new ArrayData(array(
'OutdatedRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())

View File

@ -3,9 +3,10 @@
/**
* @package docsviewer
*/
class DocumentationAdvancedSearchForm extends Form {
public function __construct($controller) {
class DocumentationAdvancedSearchForm extends Form
{
public function __construct($controller)
{
$versions = $controller->getManifest()->getAllVersions();
$entities = $controller->getManifest()->getEntities();

View File

@ -1,10 +1,9 @@
<?php
class DocumentationSearchForm extends Form {
public function __construct($controller) {
class DocumentationSearchForm extends Form
{
public function __construct($controller)
{
$fields = new FieldList(
TextField::create('q', _t('DocumentationViewer.SEARCH', 'Search'), '')
->setAttribute('placeholder', _t('DocumentationViewer.SEARCH', 'Search'))

View File

@ -16,8 +16,8 @@
* @subpackage models
*/
class DocumentationEntity extends ViewableData {
class DocumentationEntity extends ViewableData
{
/**
* The key to match entities with that is not localized. For instance, you
* may have three entities (en, de, fr) that you want to display a nice
@ -79,7 +79,8 @@ class DocumentationEntity extends ViewableData {
/**
*
*/
public function __construct($key) {
public function __construct($key)
{
$this->key = DocumentationHelper::clean_page_url($key);
}
@ -89,7 +90,8 @@ class DocumentationEntity extends ViewableData {
*
* @return string
*/
public function getTitle() {
public function getTitle()
{
if (!$this->title) {
$this->title = DocumentationHelper::clean_page_name($this->key);
}
@ -101,7 +103,8 @@ class DocumentationEntity extends ViewableData {
* @param string $title
* @return this
*/
public function setTitle($title) {
public function setTitle($title)
{
$this->title = $title;
return $this;
@ -116,7 +119,8 @@ class DocumentationEntity extends ViewableData {
* This might omit the version number if this is the default version.
* @return string
*/
public function Link($short = false) {
public function Link($short = false)
{
if ($this->getIsDefaultEntity()) {
$base = Controller::join_links(
Config::inst()->get('DocumentationViewer', 'link_base'),
@ -148,7 +152,8 @@ class DocumentationEntity extends ViewableData {
/**
* @return string
*/
public function __toString() {
public function __toString()
{
return sprintf('DocumentationEntity: %s)', $this->getPath());
}
@ -157,7 +162,8 @@ class DocumentationEntity extends ViewableData {
*
* @return boolean
*/
public function hasRecord($page) {
public function hasRecord($page)
{
if (!$page) {
return false;
}
@ -168,7 +174,8 @@ class DocumentationEntity extends ViewableData {
/**
* @param boolean $bool
*/
public function setIsDefaultEntity($bool) {
public function setIsDefaultEntity($bool)
{
$this->defaultEntity = $bool;
return $this;
@ -177,21 +184,24 @@ class DocumentationEntity extends ViewableData {
/**
* @return boolean
*/
public function getIsDefaultEntity() {
public function getIsDefaultEntity()
{
return $this->defaultEntity;
}
/**
* @return string
*/
public function getKey() {
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getLanguage() {
public function getLanguage()
{
return $this->language;
}
@ -200,7 +210,8 @@ class DocumentationEntity extends ViewableData {
*
* @return this
*/
public function setLanguage($language) {
public function setLanguage($language)
{
$this->language = $language;
return $this;
@ -209,7 +220,8 @@ class DocumentationEntity extends ViewableData {
/**
* @param string
*/
public function setVersion($version) {
public function setVersion($version)
{
$this->version = $version;
return $this;
@ -218,14 +230,16 @@ class DocumentationEntity extends ViewableData {
/**
* @return float
*/
public function getVersion() {
public function getVersion()
{
return $this->version;
}
/**
* @param string
*/
public function setBranch($branch) {
public function setBranch($branch)
{
$this->branch = $branch;
return $this;
@ -234,14 +248,16 @@ class DocumentationEntity extends ViewableData {
/**
* @return float
*/
public function getBranch() {
public function getBranch()
{
return $this->branch;
}
/**
* @return string
*/
public function getPath() {
public function getPath()
{
return $this->path;
}
@ -250,7 +266,8 @@ class DocumentationEntity extends ViewableData {
*
* @return this
*/
public function setPath($path) {
public function setPath($path)
{
$this->path = $path;
return $this;
@ -259,7 +276,8 @@ class DocumentationEntity extends ViewableData {
/**
* @param boolean
*/
public function setIsStable($stable) {
public function setIsStable($stable)
{
$this->stable = $stable;
return $this;
@ -268,7 +286,8 @@ class DocumentationEntity extends ViewableData {
/**
* @return boolean
*/
public function getIsStable() {
public function getIsStable()
{
return $this->stable;
}
@ -282,14 +301,16 @@ class DocumentationEntity extends ViewableData {
* @param string $version
* @return int
*/
public function compare(DocumentationEntity $other) {
public function compare(DocumentationEntity $other)
{
return version_compare($this->getVersion(), $other->getVersion());
}
/**
* @return array
*/
public function toMap() {
public function toMap()
{
return array(
'Key' => $this->key,
'Path' => $this->getPath(),

View File

@ -8,13 +8,13 @@
* @package docsviewer
* @subpackage model
*/
class DocumentationFolder extends DocumentationPage {
class DocumentationFolder extends DocumentationPage
{
/**
* @return string
*/
public function getTitle() {
public function getTitle()
{
return $this->getTitleFromFolder();
}
}

View File

@ -10,8 +10,8 @@
* @package docsviewer
* @subpackage model
*/
class DocumentationPage extends ViewableData {
class DocumentationPage extends ViewableData
{
/**
* @var string
*/
@ -41,7 +41,8 @@ class DocumentationPage extends ViewableData {
* @param string $filename
* @param string $path
*/
public function __construct(DocumentationEntity $entity, $filename, $path) {
public function __construct(DocumentationEntity $entity, $filename, $path)
{
$this->filename = $filename;
$this->path = $path;
$this->entity = $entity;
@ -50,7 +51,8 @@ class DocumentationPage extends ViewableData {
/**
* @return string
*/
public function getExtension() {
public function getExtension()
{
return DocumentationHelper::get_extension($this->filename);
}
@ -59,7 +61,8 @@ class DocumentationPage extends ViewableData {
*
* @return string
*/
public function getBreadcrumbTitle($divider = ' - ') {
public function getBreadcrumbTitle($divider = ' - ')
{
$pathParts = explode('/', trim($this->getRelativePath(), '/'));
// from the page from this
@ -88,14 +91,16 @@ class DocumentationPage extends ViewableData {
/**
* @return DocumentationEntity
*/
public function getEntity() {
public function getEntity()
{
return $this->entity;
}
/**
* @return string
*/
public function getTitle() {
public function getTitle()
{
if ($this->title) {
return $this->title;
}
@ -109,7 +114,8 @@ class DocumentationPage extends ViewableData {
return $page;
}
public function getTitleFromFolder() {
public function getTitleFromFolder()
{
$folder = $this->getPath();
$entity = $this->getEntity()->getPath();
@ -130,7 +136,8 @@ class DocumentationPage extends ViewableData {
/**
* @return string
*/
public function getSummary() {
public function getSummary()
{
return $this->summary;
}
@ -141,7 +148,8 @@ class DocumentationPage extends ViewableData {
*
* @return string
*/
public function getMarkdown($removeMetaData = false) {
public function getMarkdown($removeMetaData = false)
{
try {
if ($md = file_get_contents($this->getPath())) {
$this->populateMetaDataFromText($md, $removeMetaData);
@ -150,21 +158,21 @@ class DocumentationPage extends ViewableData {
}
$this->read = true;
}
catch(InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
}
return false;
}
public function setMetaData($key, $value) {
public function setMetaData($key, $value)
{
$key = strtolower($key);
$this->$key = $value;
}
public function getIntroduction() {
public function getIntroduction()
{
if (!$this->read) {
$this->getMarkdown();
}
@ -179,7 +187,8 @@ class DocumentationPage extends ViewableData {
*
* @return string
*/
public function getHTML() {
public function getHTML()
{
$html = DocumentationParser::parse(
$this,
$this->entity->Link()
@ -195,7 +204,8 @@ class DocumentationPage extends ViewableData {
*
* @return string
*/
public function getRelativeLink() {
public function getRelativeLink()
{
$path = $this->getRelativePath();
$url = explode('/', $path);
$url = implode('/', array_map(function ($a) {
@ -213,15 +223,16 @@ class DocumentationPage extends ViewableData {
*
* @return string
*/
public function getRelativePath() {
public function getRelativePath()
{
return str_replace($this->entity->getPath(), '', $this->getPath());
}
/**
* @return string
*/
public function getPath() {
public function getPath()
{
return $this->path;
}
@ -233,7 +244,8 @@ class DocumentationPage extends ViewableData {
* This might omit the version number if this is the default version.
* @return string
*/
public function Link($short = false) {
public function Link($short = false)
{
return ltrim(Controller::join_links(
$this->entity->Link($short),
$this->getRelativeLink()
@ -247,7 +259,8 @@ class DocumentationPage extends ViewableData {
* @param DocumentationPage $md
* @param bool $remove
*/
public function populateMetaDataFromText(&$md, $removeMetaData = false) {
public function populateMetaDataFromText(&$md, $removeMetaData = false)
{
if ($md) {
// get the text up to the first whiteline
$extPattern = "/^(.+)\n(\r)*\n/Uis";
@ -279,11 +292,13 @@ class DocumentationPage extends ViewableData {
}
}
public function getVersion() {
public function getVersion()
{
return $this->entity->getVersion();
}
public function __toString() {
public function __toString()
{
return sprintf(get_class($this) .': %s)', $this->getPath());
}
}

View File

@ -1,14 +1,14 @@
<?php
class DocumentationBuild extends BuildTask {
public function run($request) {
class DocumentationBuild extends BuildTask
{
public function run($request)
{
$manifest = new DocumentationManifest(true);
echo "<pre>";
print_r($manifest->getPages());
echo "</pre>";
die();;
die();
;
}
}

View File

@ -9,18 +9,20 @@
* @subpackage tasks
*/
class RebuildLuceneDocsIndex extends BuildTask {
class RebuildLuceneDocsIndex extends BuildTask
{
protected $title = "Rebuild Documentation Search Indexes";
protected $description = "
Rebuilds the indexes used for the search engine in the docsviewer.";
public function run($request) {
public function run($request)
{
$this->rebuildIndexes();
}
public function rebuildIndexes($quiet = false) {
public function rebuildIndexes($quiet = false)
{
require_once 'Zend/Search/Lucene.php';
ini_set("memory_limit", -1);
@ -46,15 +48,13 @@ class RebuildLuceneDocsIndex extends BuildTask {
try {
$index = Zend_Search_Lucene::open(DocumentationSearch::get_index_location());
$index->removeReference();
}
catch (Zend_Search_Lucene_Exception $e) {
} catch (Zend_Search_Lucene_Exception $e) {
user_error($e);
}
try {
$index = Zend_Search_Lucene::create(DocumentationSearch::get_index_location());
}
catch(Zend_Search_Lucene_Exception $c) {
} catch (Zend_Search_Lucene_Exception $c) {
user_error($c);
}
@ -117,8 +117,11 @@ class RebuildLuceneDocsIndex extends BuildTask {
$index->addDocument($doc);
if (!$quiet) {
if(Director::is_cli()) echo " * adding ". $page->getPath() ."\n";
else echo "<li>adding ". $page->getPath() ."</li>\n";
if (Director::is_cli()) {
echo " * adding ". $page->getPath() ."\n";
} else {
echo "<li>adding ". $page->getPath() ."</li>\n";
}
}
}
}

View File

@ -4,15 +4,17 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationHelperTests extends SapphireTest {
public function testCleanName() {
class DocumentationHelperTests extends SapphireTest
{
public function testCleanName()
{
$this->assertEquals("File path", DocumentationHelper::clean_page_name(
'00_file-path.md'
));
}
public function testCleanUrl() {
public function testCleanUrl()
{
$this->assertEquals("some_path", DocumentationHelper::clean_page_url(
'Some Path'
));
@ -22,7 +24,8 @@ class DocumentationHelperTests extends SapphireTest {
));
}
public function testTrimSortNumber() {
public function testTrimSortNumber()
{
$this->assertEquals('file', DocumentationHelper::trim_sort_number(
'0_file'
));
@ -36,7 +39,8 @@ class DocumentationHelperTests extends SapphireTest {
));
}
public function testTrimExtension() {
public function testTrimExtension()
{
$this->assertEquals('file', DocumentationHelper::trim_extension_off(
'file.md'
));
@ -46,7 +50,8 @@ class DocumentationHelperTests extends SapphireTest {
));
}
public function testGetExtension() {
public function testGetExtension()
{
$this->assertEquals('md', DocumentationHelper::get_extension(
'file.md'
));

View File

@ -4,11 +4,12 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationManifestTests extends SapphireTest {
class DocumentationManifestTests extends SapphireTest
{
private $manifest;
public function setUp() {
public function setUp()
{
parent::setUp();
Config::nest();
@ -57,7 +58,8 @@ class DocumentationManifestTests extends SapphireTest {
$this->manifest = new DocumentationManifest(true);
}
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
@ -67,7 +69,8 @@ class DocumentationManifestTests extends SapphireTest {
/**
* Check that the manifest matches what we'd expect.
*/
public function testRegenerate() {
public function testRegenerate()
{
$match = array(
'de/testdocs/2.3/',
'de/testdocs/2.3/german/',
@ -100,7 +103,8 @@ class DocumentationManifestTests extends SapphireTest {
$this->assertEquals($match, array_keys($this->manifest->getPages()));
}
public function testGetNextPage() {
public function testGetNextPage()
{
// get next page at the end of one subfolder goes back up to the top
// most directory
$this->assertStringEndsWith('2.3/test/', $this->manifest->getNextPage(
@ -129,7 +133,8 @@ class DocumentationManifestTests extends SapphireTest {
));
}
public function testGetPreviousPage() {
public function testGetPreviousPage()
{
// goes right into subfolders
$this->assertContains('subfolder/subsubfolder/subsubpage', $this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/test.md',
@ -149,15 +154,18 @@ class DocumentationManifestTests extends SapphireTest {
));
}
public function testGetPage() {
public function testGetPage()
{
$this->markTestIncomplete();
}
public function testGenerateBreadcrumbs() {
public function testGenerateBreadcrumbs()
{
$this->markTestIncomplete();
}
public function testGetChildrenFor() {
public function testGetChildrenFor()
{
$expected = array(
array('Title' => 'Test', 'LinkingMode' => 'link')
);
@ -178,7 +186,8 @@ class DocumentationManifestTests extends SapphireTest {
));
}
public function testGetAllVersions() {
public function testGetAllVersions()
{
$expected = array(
'2.3' => '2.3',
'2.4' => '2.4',
@ -189,7 +198,8 @@ class DocumentationManifestTests extends SapphireTest {
$this->assertEquals($expected, $this->manifest->getAllVersions());
}
public function testGetAllEntityVersions() {
public function testGetAllEntityVersions()
{
$expected = array(
'Version' => '2.3',
'Version' => '2.4',
@ -205,7 +215,8 @@ class DocumentationManifestTests extends SapphireTest {
$this->assertEquals(1, $this->manifest->getAllVersionsOfEntity($entity)->count());
}
public function testGetStableVersion() {
public function testGetStableVersion()
{
$this->markTestIncomplete();
}
}

View File

@ -4,11 +4,12 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationPageTest extends SapphireTest {
class DocumentationPageTest extends SapphireTest
{
protected $entity;
public function setUp() {
public function setUp()
{
parent::setUp();
$this->entity = new DocumentationEntity('doctest');
@ -26,13 +27,15 @@ class DocumentationPageTest extends SapphireTest {
$manifest = new DocumentationManifest(true);
}
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
public function testGetLink() {
public function testGetLink()
{
$page = new DocumentationPage(
$this->entity,
'test.md',
@ -61,7 +64,8 @@ class DocumentationPageTest extends SapphireTest {
$this->assertEquals('dev/docs/en/doctest/2.4/sort/basic/', $page->Link());
}
public function testGetBreadcrumbTitle() {
public function testGetBreadcrumbTitle()
{
$page = new DocumentationPage(
$this->entity,
'test.md',
@ -85,6 +89,5 @@ class DocumentationPageTest extends SapphireTest {
);
$this->assertEquals('Sort - Doctest', $page->getBreadcrumbTitle());
}
}

View File

@ -4,17 +4,19 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationParserTest extends SapphireTest {
class DocumentationParserTest extends SapphireTest
{
protected $entity, $entityAlt, $page, $subPage, $subSubPage, $filePage, $metaDataPage, $indexPage;
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
public function setUp() {
public function setUp()
{
parent::setUp();
Config::nest();
@ -73,7 +75,8 @@ class DocumentationParserTest extends SapphireTest {
$manifest = new DocumentationManifest(true);
}
public function testRewriteCodeBlocks() {
public function testRewriteCodeBlocks()
{
$codePage = new DocumentationPage(
$this->entityAlt,
'CodeSnippets.md',
@ -161,7 +164,8 @@ HTML;
$this->assertContains($expected, $result, 'Backtick with newlines');
}
public function testRelativeLinks() {
public function testRelativeLinks()
{
// index.md
$result = DocumentationParser::rewrite_relative_links(
$this->indexPage->getMarkdown(),
@ -266,7 +270,8 @@ HTML;
);
}
public function testGenerateHtmlId() {
public function testGenerateHtmlId()
{
$this->assertEquals('title-one', DocumentationParser::generate_html_id('title one'));
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title one'));
$this->assertEquals('title-and-one', DocumentationParser::generate_html_id('Title &amp; One'));
@ -277,8 +282,8 @@ HTML;
public function testImageRewrites() {
public function testImageRewrites()
{
$result = DocumentationParser::rewrite_image_links(
$this->subPage->getMarkdown(),
$this->subPage
@ -310,7 +315,8 @@ HTML;
);
}
public function testApiLinks() {
public function testApiLinks()
{
$result = DocumentationParser::rewrite_api_links(
$this->page->getMarkdown(),
$this->page
@ -326,7 +332,8 @@ HTML;
);
}
public function testHeadlineAnchors() {
public function testHeadlineAnchors()
{
$result = DocumentationParser::rewrite_heading_anchors(
$this->page->getMarkdown(),
$this->page
@ -357,18 +364,19 @@ HTML;
$this->assertContains('## Heading duplicate {#heading-duplicate}', $result);
$this->assertContains('## Heading duplicate {#heading-duplicate-2}', $result);
$this->assertContains('## Heading duplicate {#heading-duplicate-3}', $result);
}
public function testRetrieveMetaData() {
public function testRetrieveMetaData()
{
DocumentationParser::retrieve_meta_data($this->metaDataPage);
$this->assertEquals('Dr. Foo Bar.', $this->metaDataPage->author);
$this->assertEquals("Foo Bar's Test page.", $this->metaDataPage->getTitle());
}
public function testRewritingRelativeLinksToFiles() {
public function testRewritingRelativeLinksToFiles()
{
$parsed = DocumentationParser::parse($this->filePage);
$this->assertContains(

View File

@ -4,9 +4,10 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationPermalinksTest extends FunctionalTest {
public function testSavingAndAccessingMapping() {
class DocumentationPermalinksTest extends FunctionalTest
{
public function testSavingAndAccessingMapping()
{
// basic test
DocumentationPermalinks::add(array(
'foo' => 'en/framework/subfolder/foo',
@ -26,7 +27,8 @@ class DocumentationPermalinksTest extends FunctionalTest {
* Tests to make sure short codes get translated to full paths.
*
*/
public function testRedirectingMapping() {
public function testRedirectingMapping()
{
DocumentationPermalinks::add(array(
'foo' => 'en/framework/subfolder/foo',
'bar' => 'en/cms/bar'

View File

@ -5,9 +5,10 @@
* @subpackage tests
*/
class DocumentationSearchTest extends FunctionalTest {
public function setUp() {
class DocumentationSearchTest extends FunctionalTest
{
public function setUp()
{
parent::setUp();
Config::nest();
@ -35,13 +36,15 @@ class DocumentationSearchTest extends FunctionalTest {
$this->manifest = new DocumentationManifest(true);
}
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
public function testOpenSearchControllerAccessible() {
public function testOpenSearchControllerAccessible()
{
$c = new DocumentationOpenSearchController();
$response = $c->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
$this->assertEquals(404, $response->getStatusCode());

View File

@ -8,13 +8,14 @@
* @subpackage tests
*/
class DocumentationViewerTest extends FunctionalTest {
class DocumentationViewerTest extends FunctionalTest
{
protected $autoFollowRedirection = false;
protected $manifest;
public function setUp() {
public function setUp()
{
parent::setUp();
Config::nest();
@ -65,7 +66,8 @@ class DocumentationViewerTest extends FunctionalTest {
$this->manifest = new DocumentationManifest(true);
}
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
@ -74,7 +76,8 @@ class DocumentationViewerTest extends FunctionalTest {
/**
* This tests that all the locations will exist if we access it via the urls.
*/
public function testLocationsExists() {
public function testLocationsExists()
{
$this->autoFollowRedirection = false;
$response = $this->get('dev/docs/en/doc_test/2.3/subfolder/');
@ -141,7 +144,8 @@ class DocumentationViewerTest extends FunctionalTest {
}
public function testGetMenu() {
public function testGetMenu()
{
$v = new DocumentationViewer();
// check with children
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
@ -174,7 +178,8 @@ class DocumentationViewerTest extends FunctionalTest {
public function testGetLanguage() {
public function testGetLanguage()
{
$v = new DocumentationViewer();
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
@ -185,7 +190,8 @@ class DocumentationViewerTest extends FunctionalTest {
}
public function testAccessingAll() {
public function testAccessingAll()
{
$response = $this->get('dev/docs/en/all/');
// should response with the documentation index
@ -210,6 +216,5 @@ class DocumentationViewerTest extends FunctionalTest {
// accessing all without a language should fail
$response = $this->get('dev/docs/all/');
$this->assertEquals(404, $response->getStatusCode());
}
}

View File

@ -4,13 +4,14 @@
* @package docsviewer
* @subpackage tests
*/
class DocumentationViewerVersionWarningTest extends SapphireTest {
class DocumentationViewerVersionWarningTest extends SapphireTest
{
protected $autoFollowRedirection = false;
private $manifest;
public function setUp() {
public function setUp()
{
parent::setUp();
Config::nest();
@ -54,14 +55,15 @@ class DocumentationViewerVersionWarningTest extends SapphireTest {
$this->manifest = new DocumentationManifest(true);
}
public function tearDown() {
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
public function testVersionWarning() {
public function testVersionWarning()
{
$v = new DocumentationViewer();
// the current version is set to 2.4, no notice should be shown on that page