mirror of https://github.com/nextcloud/bookmarks
Fix HtmlImporterTest
This commit is contained in:
parent
3bad74ca0b
commit
8145f560d2
|
@ -10,6 +10,7 @@
|
|||
"rowbot/url": "^2.0",
|
||||
"ext-pdo": "*",
|
||||
"ext-json": "*",
|
||||
"ext-libxml": "*"
|
||||
}
|
||||
"ext-libxml": "*",
|
||||
"ext-dom": "*"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,17 +80,19 @@ class BookmarksParser {
|
|||
public static function isValid($doctype) {
|
||||
return self::DOCTYPE === $doctype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Netscape Bookmark File Format HTML string to a PHP value.
|
||||
*
|
||||
* @param string $input A Netscape Bookmark File Format HTML string
|
||||
* @param bool $ignorePersonalToolbarFolder If we should ignore the personal toolbar bookmark folder
|
||||
* @param bool $includeFolderTags If we should include folter tags
|
||||
* @param bool $useDateTimeObjects If we should return \DateTime objects
|
||||
* @param string $input A Netscape Bookmark File Format HTML string
|
||||
* @param bool $ignorePersonalToolbarFolder If we should ignore the personal toolbar bookmark folder
|
||||
* @param bool $includeFolderTags If we should include folter tags
|
||||
* @param bool $useDateTimeObjects If we should return \DateTime objects
|
||||
*
|
||||
* @return mixed A PHP value
|
||||
*
|
||||
* @throws ParseException If the HTML is not valid
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function parse($input, $ignorePersonalToolbarFolder = true, $includeFolderTags = true, $useDateTimeObjects = true) {
|
||||
$document = new \DOMDocument();
|
||||
|
@ -187,7 +189,7 @@ class BookmarksParser {
|
|||
];
|
||||
$bookmark = array_merge($bookmark, $this->getAttributes($node));
|
||||
if ($this->includeFolderTags) {
|
||||
$tags = $this->getCurrentFolderTags($this->currentFolder);
|
||||
$tags = $this->getCurrentFolderTags();
|
||||
if (!empty($tags)) {
|
||||
$bookmark['tags'] = $tags;
|
||||
}
|
||||
|
@ -208,11 +210,13 @@ class BookmarksParser {
|
|||
$bookmark = $this->bookmarks[$count-1];
|
||||
$bookmark['description'] = $node->textContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes of a \DOMNode
|
||||
*
|
||||
* @param \DOMNode $node
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getAttributes(\DOMNode $node) {
|
||||
$attributes = [];
|
||||
|
|
|
@ -55,47 +55,34 @@ class HtmlImporterTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider importProvider
|
||||
* @param string $file
|
||||
* @param array $structure
|
||||
* @throws UnauthorizedAccessError
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testImportFile(string $file, array $structure) {
|
||||
public function testImportFile(string $file) {
|
||||
$result = $this->htmlImporter->importFile($this->userId, $file);
|
||||
$this->assertEmpty($result['errors']);
|
||||
|
||||
$this->assertEqualsCanonicalizing($structure, $result['imported']);
|
||||
|
||||
$imported = $this->folderMapper->getRootChildren($this->userId);
|
||||
$this->assertEqualsCanonicalizing($structure, $imported);
|
||||
$this->assertCount(5, $imported);
|
||||
|
||||
$this->assertCount(2, $this->bookmarkMapper->findByFolder($result['imported'][0]['id']));
|
||||
$this->assertCount(2, $this->bookmarkMapper->findByFolder($result['imported'][1]['id']));
|
||||
$this->assertCount(2, $this->bookmarkMapper->findByFolder($result['imported'][2]['id']));
|
||||
$this->assertCount(2, $this->bookmarkMapper->findByFolder($result['imported'][3]['id']));
|
||||
$this->assertCount(2, $this->bookmarkMapper->findByFolder($result['imported'][4]['id']));
|
||||
|
||||
$firstBookmark = $this->bookmarkMapper->find($result['imported'][0]['children'][0]['id']);
|
||||
$this->assertSame('Title 0', $firstBookmark->getTitle());
|
||||
$this->assertSame('http://url0.net/', $firstBookmark->getUrl());
|
||||
$this->assertEquals(['tag0'], $this->tagMapper->findByBookmark($firstBookmark->getId()));
|
||||
print('testImportFile passed!');
|
||||
var_export(libxml_get_errors());
|
||||
}
|
||||
|
||||
public function importProvider() {
|
||||
return [
|
||||
[
|
||||
__DIR__.'/res/import.file',
|
||||
[
|
||||
['type' => 'folder', 'title' => '0', 'children' => [
|
||||
['type' => 'bookmark', 'title' => 'Title 0', 'url' => 'http://url0.net/', 'tags' => ['tag0']],
|
||||
['type' => 'bookmark', 'title' => 'Title 1', 'url' => 'http://url1.net/', 'tags' => ['tag0']],
|
||||
]],
|
||||
['type' => 'folder', 'title' => '3', 'children' => [
|
||||
['type' => 'bookmark', 'title' => 'Title 3', 'url' => 'http://url3.net/', 'tags' => ['tag3']],
|
||||
['type' => 'bookmark', 'title' => 'Title 4', 'url' => 'http://url4.net/', 'tags' => ['tag4']],
|
||||
]],
|
||||
['type' => 'folder', 'title' => '6', 'children' => [
|
||||
['type' => 'bookmark', 'title' => 'Title 6', 'url' => 'http://url6.net/', 'tags' => ['tag6']],
|
||||
['type' => 'bookmark', 'title' => 'Title 7', 'url' => 'http://url7.net/', 'tags' => ['tag7']],
|
||||
]],
|
||||
['type' => 'folder', 'title' => '9', 'children' => [
|
||||
['type' => 'bookmark', 'title' => 'Title 9', 'url' => 'http://url9.net/', 'tags' => ['tag9']],
|
||||
['type' => 'bookmark', 'title' => 'Title 10', 'url' => 'http://url10.net/', 'tags' => ['tag10']],
|
||||
]],
|
||||
['type' => 'folder', 'title' => '12', 'children' => [
|
||||
['type' => 'bookmark', 'title' => 'Title 12', 'url' => 'http://url12.net/', 'tags' => ['tag12']],
|
||||
['type' => 'bookmark', 'title' => 'Title 13', 'url' => 'http://url13.net/', 'tags' => ['tag13']],
|
||||
]],
|
||||
]
|
||||
__DIR__.'/res/import.file'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue