silverstripe-docsviewer/tests/DocumentationHelperTests.php

113 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* @package docsviewer
* @subpackage tests
*/
2015-11-21 07:25:41 +01:00
class DocumentationHelperTests extends SapphireTest
{
public function testCleanName()
{
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'File path',
DocumentationHelper::clean_page_name(
2016-12-02 03:31:18 +01:00
'00_file-path.md'
)
);
2015-11-21 07:25:41 +01:00
}
2015-11-21 07:25:41 +01:00
public function testCleanUrl()
{
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'some_path',
DocumentationHelper::clean_page_url(
2016-12-02 03:31:18 +01:00
'Some Path'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'somefilepath',
DocumentationHelper::clean_page_url(
2016-12-02 03:31:18 +01:00
'00_SomeFilePath.md'
)
);
2015-11-21 07:25:41 +01:00
}
2015-11-21 07:25:41 +01:00
public function testTrimSortNumber()
{
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'file',
DocumentationHelper::trim_sort_number(
2016-12-02 03:31:18 +01:00
'0_file'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'2.1',
DocumentationHelper::trim_sort_number(
2016-12-02 03:31:18 +01:00
'2.1'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'dev/tasks/2.1',
DocumentationHelper::trim_sort_number(
2016-12-02 03:31:18 +01:00
'dev/tasks/2.1'
)
);
2015-11-21 07:25:41 +01:00
}
2015-11-21 07:25:41 +01:00
public function testTrimExtension()
{
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'file',
DocumentationHelper::trim_extension_off(
2016-12-02 03:31:18 +01:00
'file.md'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'dev/path/file',
DocumentationHelper::trim_extension_off(
2016-12-02 03:31:18 +01:00
'dev/path/file.md'
)
);
2015-11-21 07:25:41 +01:00
}
2015-11-21 07:25:41 +01:00
public function testGetExtension()
{
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'md',
DocumentationHelper::get_extension(
2016-12-02 03:31:18 +01:00
'file.md'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'md',
DocumentationHelper::get_extension(
2016-12-02 03:31:18 +01:00
'dev/tasks/file.md'
)
);
2016-12-02 03:31:18 +01:00
$this->assertEquals(
'txt',
DocumentationHelper::get_extension(
2016-12-02 03:31:18 +01:00
'dev/tasks/file.txt'
)
);
2016-12-02 03:31:18 +01:00
$this->assertNull(
DocumentationHelper::get_extension(
'doc_test/2.3'
)
);
2016-12-02 03:31:18 +01:00
$this->assertNull(
DocumentationHelper::get_extension(
'dev/docs/en/doc_test/2.3/subfolder'
)
);
2015-11-21 07:25:41 +01:00
}
}