Skip to content

Commit 5eab709

Browse files
committed
test: Test export structure
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent ba31fd8 commit 5eab709

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

tests/HtmlImportExportTest.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testExport(...$bookmarks): void {
131131
// Set up database
132132
for ($i = 0; $i < 4; $i++) {
133133
$f = new Db\Folder();
134-
$f->setTitle($i);
134+
$f->setTitle(md5($i));
135135
$f->setUserId($this->userId);
136136
$f = $this->folderMapper->insert($f);
137137
$this->treeMapper->move(Db\TreeMapper::TYPE_FOLDER, $f->getId(), $rootFolder->getId());
@@ -143,13 +143,32 @@ public function testExport(...$bookmarks): void {
143143

144144
$exported = $this->htmlExporter->exportFolder($this->userId, $rootFolder->getId());
145145

146-
$rootFolders = $this->treeMapper->findChildren(Db\TreeMapper::TYPE_FOLDER, $rootFolder->getId());
147-
$this->assertCount(4, $rootFolders);
148-
foreach ($rootFolders as $rootFolder) {
146+
$exportedRootFolders = $this->treeMapper->findChildren(Db\TreeMapper::TYPE_FOLDER, $rootFolder->getId());
147+
$this->assertCount(4, $exportedRootFolders);
148+
foreach ($exportedRootFolders as $rootFolder) {
149149
foreach ($this->treeMapper->findChildren(Db\TreeMapper::TYPE_BOOKMARK, $rootFolder->getId()) as $bookmark) {
150+
$this->assertStringContainsString($rootFolder->getTitle(), $exported);
150151
$this->assertStringContainsString($bookmark->getUrl(), $exported);
151152
}
152153
}
154+
155+
$f = new Db\Folder();
156+
$f->setTitle('Testimport');
157+
$f->setUserId($this->userId);
158+
$f = $this->folderMapper->insert($f);
159+
$this->htmlImporter->import($this->userId, $exported, $f->getId());
160+
$importedRootFolders = $this->treeMapper->findChildren(Db\TreeMapper::TYPE_FOLDER, $f->getId());
161+
foreach ($importedRootFolders as $i => $importedRootFolder) {
162+
$exportedRootFolder = $exportedRootFolders[$i];
163+
$this->assertEquals($exportedRootFolder->getTitle(), $importedRootFolder->getTitle());
164+
$exportedBookmarks = $this->treeMapper->findChildren(Db\TreeMapper::TYPE_BOOKMARK, $exportedRootFolder->getId());
165+
foreach ($this->treeMapper->findChildren(Db\TreeMapper::TYPE_BOOKMARK, $importedRootFolder->getId()) as $j => $bookmark) {
166+
$this->assertEquals($bookmark->getUrl(), $exportedBookmarks[$i]->getUrl());
167+
$this->assertEquals($bookmark->getTitle(), $exportedBookmarks[$i]->getTitle());
168+
$this->assertEquals($bookmark->getDescription(), $exportedBookmarks[$i]->getDescription());
169+
$this->assertEquals($this->tagMapper->findByBookmark($bookmark->getId()), $this->tagMapper->findByBookmark($exportedBookmarks[$i]->getId()));
170+
}
171+
}
153172
}
154173

155174
public function importProvider(): array {
@@ -166,10 +185,10 @@ public function exportProvider(): array {
166185
return Db\Bookmark::fromArray($props);
167186
}, [
168187
['url' => 'https://google.com/', 'title' => 'Google', 'description' => 'Search engine'],
169-
['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud', 'description' => ''],
188+
['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud', 'description' => 'cloud cloud cloud'],
170189
['url' => 'https://php.net/', 'title' => '', 'description' => ''],
171-
['url' => 'https://de.wikipedia.org/wiki/%C3%9C', 'title' => '', 'description' => ''],
172-
['url' => 'https://github.com/nextcloud/bookmarks/projects/1', 'title' => '', 'description' => ''],
190+
['url' => 'https://de.wikipedia.org/wiki/%C3%9C', 'title' => '', 'description' => '<H1>Hello</H1>'],
191+
['url' => 'https://github.com/nextcloud/bookmarks/projects/1', 'title' => '', 'description' => '</DL>'],
173192
]),
174193
];
175194
}

0 commit comments

Comments
 (0)