-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This could really use some more tests but this has to suffice for now.
- Loading branch information
1 parent
28af4b6
commit 1eeb87d
Showing
6 changed files
with
321 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace dokuwiki\plugin\filelist\test; | ||
|
||
use dokuwiki\plugin\filelist\Path; | ||
use DokuWikiTest; | ||
|
||
/** | ||
* Path related tests for the filelist plugin | ||
* | ||
* @group plugin_filelist | ||
* @group plugins | ||
*/ | ||
class PathTest extends DokuWikiTest | ||
{ | ||
|
||
protected $path; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->path = new Path( | ||
<<<EOT | ||
C:\\xampp\\htdocs\\wiki\\ | ||
\\\\server\\share\\path\\ | ||
/linux/file/path/ | ||
/linux/another/path/../..//another/blargh/../path | ||
A> alias | ||
W> webfoo | ||
EOT | ||
); | ||
} | ||
|
||
/** | ||
* Test the configuration parsing for paths and aliases | ||
*/ | ||
public function testGetPaths() | ||
{ | ||
$expect = [ | ||
'C:/xampp/htdocs/wiki/' => [ | ||
'root' => 'C:/xampp/htdocs/wiki/', | ||
'web' => '/lib/plugins/filelist/file.php?root=C%3A%2Fxampp%2Fhtdocs%2Fwiki%2F&file=', | ||
], | ||
'\\\\server/share/path/' => [ | ||
'root' => '\\\\server/share/path/', | ||
'web' => '/lib/plugins/filelist/file.php?root=%5C%5Cserver%2Fshare%2Fpath%2F&file=', | ||
], | ||
'/linux/file/path/' => [ | ||
'root' => '/linux/file/path/', | ||
'web' => '/lib/plugins/filelist/file.php?root=%2Flinux%2Ffile%2Fpath%2F&file=', | ||
], | ||
'/linux/another/path/' => [ | ||
'root' => '/linux/another/path/', | ||
'alias' => 'alias/', | ||
'web' => 'webfoo', | ||
], | ||
'alias/' => [ | ||
'root' => '/linux/another/path/', | ||
'alias' => 'alias/', | ||
'web' => 'webfoo', | ||
], | ||
]; | ||
|
||
$this->assertEquals($expect, $this->path->getPaths()); | ||
} | ||
|
||
/** | ||
* Data provider for testGetPathInfoSuccess | ||
*/ | ||
public function providePathInfoSuccess() | ||
{ | ||
return [ | ||
['/linux/another/path', '/linux/another/path/'], | ||
['/linux/another/path/foo', '/linux/another/path/foo/'], | ||
['alias', '/linux/another/path/'], | ||
['alias/foo', '/linux/another/path/foo/'], | ||
['C:\\xampp\\htdocs\\wiki', 'C:/xampp/htdocs/wiki/'], | ||
['C:\\xampp\\htdocs\\wiki\\foo', 'C:/xampp/htdocs/wiki/foo/'], | ||
['\\\\server\\share\\path\\', '\\\\server/share/path/'], | ||
['\\\\server\\share\\path\\foo', '\\\\server/share/path/foo/'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providePathInfoSuccess | ||
*/ | ||
public function testGetPathInfoSuccess($path, $expect) | ||
{ | ||
$pathInfo = $this->path->getPathInfo($path); | ||
$this->assertEquals($expect, $pathInfo['path']); | ||
} | ||
|
||
public function providePathInfoFailure() | ||
{ | ||
return [ | ||
['/linux/file/path/../../../etc/'], | ||
['W:\\xampp\\htdocs\\wiki\\foo\\bar'], | ||
['/'], | ||
['./'], | ||
['../'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providePathInfoFailure | ||
*/ | ||
public function testGetPathInfoFailure($path) | ||
{ | ||
$this->expectExceptionMessageMatches('/Path not allowed/'); | ||
$this->path->getPathInfo($path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
<?php | ||
|
||
namespace dokuwiki\plugin\filelist\test; | ||
|
||
use DokuWikiTest; | ||
use DOMWrap\Document; | ||
|
||
|
||
/** | ||
* Tests for the filelist plugin. | ||
* | ||
* These test assume that the directory filelist has the following content: | ||
* - exampledir (directory) | ||
* - example2.txt (text file) | ||
* - example.txt (text file) | ||
* - exampleimage.png (image file) | ||
* | ||
* @group plugin_filelist | ||
* @group plugins | ||
*/ | ||
class plugin_filelist_test extends DokuWikiTest | ||
{ | ||
|
||
public function setUp(): void | ||
{ | ||
global $conf; | ||
|
||
$this->pluginsEnabled[] = 'filelist'; | ||
parent::setUp(); | ||
|
||
// Setup config so that access to the TMP directory will be allowed | ||
$conf ['plugin']['filelist']['paths'] = TMP_DIR . '/filelistdata/' . "\n" . 'W> http://localhost/'; | ||
|
||
} | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
// copy test files to test directory | ||
\TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/filelistdata'); | ||
} | ||
|
||
/** | ||
* Run a list of checks on the given document | ||
* | ||
* @param Document $doc | ||
* @param array $structure Array of selectors and expected count or content | ||
* @return void | ||
*/ | ||
protected function structureCheck(Document $doc, $structure) | ||
{ | ||
foreach ($structure as $selector => $expected) { | ||
if (is_numeric($expected)) { | ||
$this->assertEquals( | ||
$expected, | ||
$doc->find($selector)->count(), | ||
'Selector ' . $selector . ' not found' | ||
); | ||
} else { | ||
$this->assertStringContainsString( | ||
$expected, | ||
$doc->find($selector)->text(), | ||
'Selector ' . $selector . ' not found' | ||
); | ||
}; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This function checks that all files are listed in not recursive mode. | ||
*/ | ||
public function test_not_recursive() | ||
{ | ||
global $conf; | ||
|
||
// Render filelist | ||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1}}'); | ||
$xhtml = p_render('xhtml', $instructions, $info); | ||
|
||
// We should find: | ||
// - example.txt | ||
// - exampleimage.png | ||
$result = strpos($xhtml, 'example.txt'); | ||
$this->assertFalse($result === false, '"example.txt" not listed'); | ||
$result = strpos($xhtml, 'exampleimage.png'); | ||
$this->assertFalse($result === false, '"exampleimage.png" not listed'); | ||
} | ||
|
||
/** | ||
* This function checks that all files are listed in recursive mode. | ||
*/ | ||
public function test_recursive() | ||
{ | ||
// Render filelist | ||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1&recursive=1}}'); | ||
$xhtml = p_render('xhtml', $instructions, $info); | ||
|
||
// We should find: | ||
// - exampledir | ||
// - example2.txt | ||
// - example.txt | ||
// - exampleimage.png | ||
$result = strpos($xhtml, 'exampledir'); | ||
$this->assertFalse($result === false, '"exampledir" not listed'); | ||
$result = strpos($xhtml, 'example2.txt'); | ||
$this->assertFalse($result === false, '"example2.txt" not listed'); | ||
$result = strpos($xhtml, 'example.txt'); | ||
$this->assertFalse($result === false, '"example.txt" not listed'); | ||
$result = strpos($xhtml, 'exampleimage.png'); | ||
$this->assertFalse($result === false, '"exampleimage.png" not listed'); | ||
} | ||
|
||
/** | ||
* This function checks that the unordered list mode | ||
* generates the expected XHTML structure. | ||
*/ | ||
public function testUnorderedList() | ||
{ | ||
// Render filelist | ||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1&recursive=1}}'); | ||
$xhtml = p_render('xhtml', $instructions, $info); | ||
|
||
$doc = new Document(); | ||
$doc->html($xhtml); | ||
|
||
$structure = [ | ||
'div.filelist-plugin' => 1, | ||
'div.filelist-plugin > ul' => 1, | ||
'div.filelist-plugin > ul > li' => 3, | ||
'div.filelist-plugin > ul > li:nth-child(1)' => 1, | ||
'div.filelist-plugin > ul > li:nth-child(1) a' => 'example.txt', | ||
'div.filelist-plugin > ul > li:nth-child(2) ul' => 1, | ||
'div.filelist-plugin > ul > li:nth-child(2) ul > li' => 1, | ||
'div.filelist-plugin > ul > li:nth-child(2) ul > li a' => 'example2.txt', | ||
]; | ||
|
||
$this->structureCheck($doc, $structure); | ||
} | ||
|
||
/** | ||
* This function checks that the ordered list mode | ||
* generates the expected XHTML structure. | ||
*/ | ||
public function testOrderedList() | ||
{ | ||
// Render filelist | ||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=olist&direct=1&recursive=1}}'); | ||
$xhtml = p_render('xhtml', $instructions, $info); | ||
|
||
$doc = new Document(); | ||
$doc->html($xhtml); | ||
|
||
$structure = [ | ||
'div.filelist-plugin' => 1, | ||
'div.filelist-plugin > ol' => 1, | ||
'div.filelist-plugin > ol > li' => 3, | ||
'div.filelist-plugin > ol > li:nth-child(1)' => 1, | ||
'div.filelist-plugin > ol > li:nth-child(1) a' => 'example.txt', | ||
'div.filelist-plugin > ol > li:nth-child(2) ol' => 1, | ||
'div.filelist-plugin > ol > li:nth-child(2) ol > li' => 1, | ||
'div.filelist-plugin > ol > li:nth-child(2) ol > li a' => 'example2.txt', | ||
]; | ||
|
||
$this->structureCheck($doc, $structure); | ||
} | ||
|
||
/** | ||
* This function checks that the table mode | ||
* generates the expected XHTML structure. | ||
*/ | ||
public function test_table() | ||
{ | ||
global $conf; | ||
|
||
// Render filelist | ||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=table&direct=1&recursive=1}}'); | ||
$xhtml = p_render('xhtml', $instructions, $info); | ||
|
||
$doc = new Document(); | ||
$doc->html($xhtml); | ||
|
||
$structure = [ | ||
'div.filelist-plugin' => 1, | ||
'div.filelist-plugin table' => 1, | ||
'div.filelist-plugin table > tbody > tr' => 3, | ||
'div.filelist-plugin table > tbody > tr:nth-child(1) a' => 'example.txt', | ||
'div.filelist-plugin table > tbody > tr:nth-child(2) a' => 'exampledir/example2.txt', | ||
'div.filelist-plugin table > tbody > tr:nth-child(3) a' => 'exampleimage.png', | ||
]; | ||
|
||
$this->structureCheck($doc, $structure); | ||
} | ||
} |
Oops, something went wrong.