mirror of https://github.com/nextcloud/bookmarks
Fix findByUrl tests
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
0e8dee2777
commit
22f07bb4a3
|
@ -8,6 +8,7 @@
|
|||
"psr/http-factory": "^1.0",
|
||||
"psr/http-client": "^0.2.0",
|
||||
"rowbot/url": "^2.0",
|
||||
"ext-pdo": "*"
|
||||
"ext-pdo": "*",
|
||||
"ext-json": "*"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class BookmarkMapper extends QBMapper {
|
|||
$normalized = $this->urlNormalizer->normalize($url);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb
|
||||
->select('id')
|
||||
->select('*')
|
||||
->from('bookmarks')
|
||||
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
|
||||
->andWhere($qb->expr()->eq('url', $qb->createNamedParameter($normalized)));
|
||||
|
@ -197,9 +197,7 @@ class BookmarkMapper extends QBMapper {
|
|||
*/
|
||||
public function findByFolder(int $folderId) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*');
|
||||
|
||||
$qb
|
||||
$qb->select('id', 'url', 'title', 'description', 'lastmodified', 'added', 'clickcount')
|
||||
->from('bookmarks', 'b')
|
||||
->leftJoin('b', 'bookmarks_folders_bookmarks', 'f', $qb->expr()->eq('f.bookmark_id', 'b.id'))
|
||||
->where($qb->expr()->eq('f.folder_id', $qb->createPositionalParameter($folderId)));
|
||||
|
@ -212,7 +210,7 @@ class BookmarkMapper extends QBMapper {
|
|||
*/
|
||||
public function findByRootFolder(int $userId) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
$qb->select('id', 'url', 'title', 'description', 'lastmodified', 'added', 'clickcount')
|
||||
->from('bookmarks', 'b')
|
||||
->leftJoin('b', 'bookmarks_folders_bookmarks', 'f', $qb->expr()->eq('f.bookmark_id', 'b.id'))
|
||||
->where($qb->expr()->eq('f.folder_id', $qb->createPositionalParameter(-1)))
|
||||
|
|
|
@ -158,8 +158,8 @@ class FolderMapper extends QBMapper {
|
|||
|
||||
$qb
|
||||
->from('bookmarks_folders', 'f')
|
||||
->leftJoin('b', 'bookmarks_folders_bookmarks', 'f', $qb->expr()->eq('b.bookmark_id', 'f.id'))
|
||||
->where($qb->expr()->eq('b.bookmark_id', $qb->createPositionalParamter($bookmarkId)));
|
||||
->leftJoin('f', 'bookmarks_folders_bookmarks', 'b', $qb->expr()->eq('b.bookmark_id', 'f.id'))
|
||||
->where($qb->expr()->eq('b.bookmark_id', $qb->createPositionalParameter($bookmarkId)));
|
||||
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ class BookmarkMapperTest extends TestCase {
|
|||
$bookmark = $this->bookmarkMapper->insert($bookmark);
|
||||
$foundEntity = $this->bookmarkMapper->find($bookmark->getId());
|
||||
$this->assertSame($bookmark->getUrl(), $foundEntity->getUrl());
|
||||
$this->assertSame($bookmark->getTitle(), $foundEntity->getTitle());
|
||||
$this->assertSame($bookmark->getDescription(), $foundEntity->getDescription());
|
||||
$this->assertSame((string) $bookmark->getTitle(), (string) $foundEntity->getTitle());
|
||||
$this->assertSame((string) $bookmark->getDescription(), (string) $foundEntity->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ class BookmarkMapperTest extends TestCase {
|
|||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testFindByUrl(Entity $bookmark) {
|
||||
$foundEntity = $this->bookmarkMapper->findByUrl($bookmark->getUserId(), $bookmark->getUrl());
|
||||
$foundEntity = $this->bookmarkMapper->findByUrl($this->userId, $bookmark->getUrl());
|
||||
$this->assertSame($bookmark->getUrl(), $foundEntity->getUrl());
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,11 @@ class BookmarkMapperTest extends TestCase {
|
|||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testUpdate(Entity $bookmark) {
|
||||
$entity = $this->bookmarkMapper->findByUrl($bookmark->getUserId(), $bookmark->getUrl());
|
||||
$entity = $this->bookmarkMapper->findByUrl($this->userId, $bookmark->getUrl());
|
||||
$entity->setTitle('foobar');
|
||||
$this->bookmarkMapper->update($entity);
|
||||
$foundEntity = $this->bookmarkMapper->find($entity->getId());
|
||||
$this->assertSame($entity->title, $foundEntity->title);
|
||||
$this->assertSame((string) $entity->getTitle(), (string) $foundEntity->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +85,7 @@ class BookmarkMapperTest extends TestCase {
|
|||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testDelete(Entity $bookmark) {
|
||||
$foundEntity = $this->bookmarkMapper->findByUrl($bookmark->getUserId(), $bookmark->getUrl());
|
||||
$foundEntity = $this->bookmarkMapper->findByUrl($this->userId, $bookmark->getUrl());
|
||||
$this->bookmarkMapper->delete($foundEntity);
|
||||
$this->expectException(DoesNotExistException::class);
|
||||
$this->bookmarkMapper->find($foundEntity->getId());
|
||||
|
@ -101,7 +101,7 @@ class BookmarkMapperTest extends TestCase {
|
|||
'Simple URL with title and description' => ['url' => 'https://google.com/', 'title' => 'Google', 'description' => 'Search engine'],
|
||||
'Simple URL with title' => ['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud'],
|
||||
'Simple URL' => ['url' => 'https://php.net/'],
|
||||
'URL with unicode' => ['url' => 'https://de.wikipedia.org/wiki/Ü'],
|
||||
'URL with unicode' => ['url' => 'https://de.wikipedia.org/wiki/%C3%9C'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,19 +67,6 @@ class FolderMapperTest extends TestCase {
|
|||
$this->assertSame($folder->getTitle(), $foundEntity->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsertAndFind
|
||||
* @param Entity $folder
|
||||
* @return void
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testDelete(Entity $folder) {
|
||||
$this->folderMapper->delete($folder);
|
||||
$this->expectException(DoesNotExistException::class);
|
||||
$this->folderMapper->find($folder->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsertAndFind
|
||||
* @dataProvider singleBookmarksProvider
|
||||
|
@ -116,6 +103,19 @@ class FolderMapperTest extends TestCase {
|
|||
}, $bookmarks));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsertAndFind
|
||||
* @param Entity $folder
|
||||
* @return void
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function testDelete(Entity $folder) {
|
||||
$this->folderMapper->delete($folder);
|
||||
$this->expectException(DoesNotExistException::class);
|
||||
$this->folderMapper->find($folder->getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@ -127,7 +127,7 @@ class FolderMapperTest extends TestCase {
|
|||
'Simple URL with title and description' => ['url' => 'https://google.com/', 'title' => 'Google', 'description' => 'Search engine'],
|
||||
'Simple URL with title' => ['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud'],
|
||||
'Simple URL' => ['url' => 'https://php.net/'],
|
||||
'URL with unicode' => ['url' => 'https://de.wikipedia.org/wiki/Ü'],
|
||||
'URL with unicode' => ['url' => 'https://de.wikipedia.org/wiki/%C3%9C'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,10 +109,10 @@ class TagMapperTest extends TestCase {
|
|||
array_map(function ($data) {
|
||||
return [$data[0], Db\Bookmark::fromArray($data[1])];
|
||||
}, [
|
||||
[['one'],['url' => 'https://google.com/', 'title' => 'Google', 'description' => 'Search engine']],
|
||||
[['two'],['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud']],
|
||||
[['three', 'one'],['url' => 'https://php.net/']],
|
||||
[['two', 'four', 'one'],['url' => 'https://de.wikipedia.org/wiki/Ü']],
|
||||
[['one'], ['url' => 'https://google.com/', 'title' => 'Google', 'description' => 'Search engine']],
|
||||
[['two'], ['url' => 'https://nextcloud.com/', 'title' => 'Nextcloud']],
|
||||
[['three', 'one'], ['url' => 'https://php.net/']],
|
||||
[['two', 'four', 'one'], ['url' => 'https://de.wikipedia.org/wiki/%C3%9C']],
|
||||
])
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue