silverstripe-docsviewer/tests/DocumentationPageTest.php

94 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* @package docsviewer
* @subpackage tests
*/
2015-11-21 07:25:41 +01:00
class DocumentationPageTest extends SapphireTest
{
protected $entity;
2015-11-21 07:25:41 +01:00
public function setUp()
{
parent::setUp();
2015-11-21 07:25:41 +01:00
$this->entity = new DocumentationEntity('doctest');
$this->entity->setPath(DOCSVIEWER_PATH . '/tests/docs/en/');
$this->entity->setVersion('2.4');
$this->entity->setLanguage('en');
2015-11-21 07:25:41 +01:00
Config::nest();
2015-11-21 07:25:41 +01:00
// explicitly use dev/docs. Custom paths should be tested separately
Config::inst()->update(
'DocumentationViewer', 'link_base', 'dev/docs/'
);
2015-11-21 07:25:41 +01:00
$manifest = new DocumentationManifest(true);
}
2015-11-21 07:25:41 +01:00
public function tearDown()
{
parent::tearDown();
2015-11-21 07:25:41 +01:00
Config::unnest();
}
2015-11-21 07:25:41 +01:00
public function testGetLink()
{
$page = new DocumentationPage(
$this->entity,
'test.md',
DOCSVIEWER_PATH . '/tests/docs/en/test.md'
);
// single layer
$this->assertEquals('dev/docs/en/doctest/2.4/test/', $page->Link(),
'The page link should have no extension and have a language'
);
2015-11-21 07:25:41 +01:00
$page = new DocumentationFolder(
$this->entity,
'sort',
DOCSVIEWER_PATH . '/tests/docs/en/sort/'
);
$this->assertEquals('dev/docs/en/doctest/2.4/sort/', $page->Link());
$page = new DocumentationFolder(
$this->entity,
'1-basic.md',
DOCSVIEWER_PATH . '/tests/docs/en/sort/1-basic.md'
);
$this->assertEquals('dev/docs/en/doctest/2.4/sort/basic/', $page->Link());
}
public function testGetBreadcrumbTitle()
{
$page = new DocumentationPage(
$this->entity,
'test.md',
DOCSVIEWER_PATH . '/tests/docs/en/test.md'
);
2015-11-21 07:25:41 +01:00
$this->assertEquals("Test - Doctest", $page->getBreadcrumbTitle());
$page = new DocumentationFolder(
$this->entity,
'1-basic.md',
DOCSVIEWER_PATH . '/tests/docs/en/sort/1-basic.md'
);
$this->assertEquals('Basic - Sort - Doctest', $page->getBreadcrumbTitle());
2015-11-21 07:25:41 +01:00
$page = new DocumentationFolder(
$this->entity,
'',
DOCSVIEWER_PATH . '/tests/docs/en/sort/'
);
2015-11-21 07:25:41 +01:00
$this->assertEquals('Sort - Doctest', $page->getBreadcrumbTitle());
}
}