2010-08-01 06:46:26 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphiredocs
|
|
|
|
*/
|
|
|
|
class DocumentationParserTest extends SapphireTest {
|
2010-08-01 06:46:37 +02:00
|
|
|
|
2011-01-10 10:18:44 +01:00
|
|
|
function testRewriteCodeBlocks() {
|
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('test.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
$page->setLang('en');
|
|
|
|
$page->setVersion('2.4');
|
|
|
|
$result = DocumentationParser::rewrite_code_blocks($page->getMarkdown());
|
|
|
|
$expected = <<<HTML
|
|
|
|
<pre class="brush: php">
|
|
|
|
code block
|
|
|
|
with multiple
|
|
|
|
lines
|
|
|
|
and tab indent
|
2011-01-10 11:59:22 +01:00
|
|
|
and escaped < brackets
|
2011-01-10 10:18:44 +01:00
|
|
|
</pre>
|
2011-01-10 11:59:22 +01:00
|
|
|
|
|
|
|
Normal text after code block
|
2011-01-10 10:18:44 +01:00
|
|
|
HTML;
|
|
|
|
|
2011-01-10 11:59:22 +01:00
|
|
|
$this->assertContains($expected, $result, 'Custom code blocks with ::: prefix');
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
<pre>
|
|
|
|
code block
|
|
|
|
without formatting prefix
|
|
|
|
</pre>
|
|
|
|
HTML;
|
|
|
|
$this->assertContains($expected, $result, 'Traditional markdown code blocks');
|
2011-01-10 10:18:44 +01:00
|
|
|
}
|
2010-08-01 23:13:40 +02:00
|
|
|
|
2010-08-01 10:25:00 +02:00
|
|
|
function testImageRewrites() {
|
|
|
|
// Page on toplevel
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('subfolder/subpage.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
$page->setLang('en');
|
|
|
|
$page->setVersion('2.4');
|
|
|
|
|
2010-08-01 10:25:00 +02:00
|
|
|
$result = DocumentationParser::rewrite_image_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
2010-12-22 09:21:49 +01:00
|
|
|
|
2010-08-01 10:25:00 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'[relative image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/subfolder/_images/image.png)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[parent image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/_images/image.png)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
// TODO Fix absolute image references
|
|
|
|
// $this->assertContains(
|
|
|
|
// '[absolute image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/_images/image.png)',
|
|
|
|
// $result
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:37 +02:00
|
|
|
function testApiLinks() {
|
|
|
|
// Page on toplevel
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('test.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
$page->setLang('en');
|
|
|
|
$page->setVersion('2.4');
|
|
|
|
|
|
|
|
|
2010-08-01 06:46:37 +02:00
|
|
|
$result = DocumentationParser::rewrite_api_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: api](http://api.silverstripe.org/search/lookup/?q=DataObject&version=2.4&module=mymodule)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains( '[DataObject::$has_one](http://api.silverstripe.org/search/lookup/?q=DataObject::$has_one&version=2.4&module=mymodule)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
2010-09-03 07:29:15 +02:00
|
|
|
|
|
|
|
function testHeadlineAnchors() {
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('test.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
$page->setLang('en');
|
|
|
|
$page->setVersion('2.4');
|
2010-09-03 07:29:15 +02:00
|
|
|
|
|
|
|
$result = DocumentationParser::rewrite_heading_anchors($page->getMarkdown(), $page);
|
|
|
|
|
|
|
|
/*
|
|
|
|
# Heading one {#Heading-one}
|
|
|
|
|
|
|
|
# Heading with custom anchor {#custom-anchor} {#Heading-with-custom-anchor-custom-anchor}
|
|
|
|
|
|
|
|
## Heading two {#Heading-two}
|
|
|
|
|
|
|
|
### Heading three {#Heading-three}
|
|
|
|
|
|
|
|
## Heading duplicate {#Heading-duplicate}
|
|
|
|
|
|
|
|
## Heading duplicate {#Heading-duplicate-2}
|
|
|
|
|
|
|
|
## Heading duplicate {#Heading-duplicate-3}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$this->assertContains('# Heading one {#Heading-one}', $result);
|
|
|
|
$this->assertContains('# Heading with custom anchor {#custom-anchor}', $result);
|
|
|
|
$this->assertNotContains('# Heading with custom anchor {#custom-anchor} {#Heading', $result);
|
|
|
|
$this->assertContains('# Heading two {#Heading-two}', $result);
|
|
|
|
$this->assertContains('# Heading three {#Heading-three}', $result);
|
|
|
|
$this->assertContains('## Heading duplicate {#Heading-duplicate}', $result);
|
|
|
|
$this->assertContains('## Heading duplicate {#Heading-duplicate-2}', $result);
|
|
|
|
$this->assertContains('## Heading duplicate {#Heading-duplicate-3}', $result);
|
|
|
|
|
|
|
|
}
|
2010-08-01 06:46:26 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function testRelativeLinks() {
|
|
|
|
// Page on toplevel
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('test.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
2010-10-21 22:27:23 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'[link: subfolder index](mycontroller/cms/2.4/en/subfolder/)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: subfolder page](mycontroller/cms/2.4/en/subfolder/subpage)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: http](http://silverstripe.org)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: api](api:DataObject)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
|
|
|
|
// Page in subfolder
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('subfolder/subpage.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
2010-10-21 22:27:23 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'[link: absolute index](mycontroller/cms/2.4/en/)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: absolute index with name](mycontroller/cms/2.4/en/index)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: relative index](mycontroller/cms/2.4/en/)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: relative parent page](mycontroller/cms/2.4/en/test)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: absolute parent page](mycontroller/cms/2.4/en/test)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
|
|
|
|
// Page in nested subfolder
|
2010-10-21 22:27:23 +02:00
|
|
|
$page = new DocumentationPage();
|
|
|
|
$page->setRelativePath('subfolder/subsubfolder/subsubpage.md');
|
|
|
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
2010-10-21 22:27:23 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'[link: absolute index](mycontroller/cms/2.4/en/)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: relative index](mycontroller/cms/2.4/en/subfolder/)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: relative parent page](mycontroller/cms/2.4/en/subfolder/subpage)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: relative grandparent page](mycontroller/cms/2.4/en/test)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'[link: absolute page](mycontroller/cms/2.4/en/test)',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
2010-08-01 06:46:26 +02:00
|
|
|
}
|