-
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathBookmarkMapperTest.php
More file actions
141 lines (126 loc) Β· 4.07 KB
/
Copy pathBookmarkMapperTest.php
File metadata and controls
141 lines (126 loc) Β· 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace OCA\Bookmarks\Tests;
use OC;
use OCA\Bookmarks\Db;
use OCA\Bookmarks\Exception\AlreadyExistsError;
use OCA\Bookmarks\Exception\UrlParseError;
use OCA\Bookmarks\Exception\UserLimitExceededError;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IUserManager;
class BookmarkMapperTest extends TestCase {
/**
* @var mixed|Db\BookmarkMapper
*/
private $bookmarkMapper;
/**
* @var Db\TreeMapper
*/
private $treeMapper;
/**
* @var Db\FolderMapper
*/
private $folderMapper;
/**
* @var string
*/
private $userId;
/**
* @var \OC\User\Manager
*/
private $userManager;
/**
* @var string
*/
private $user;
/**
* @throws \OCP\AppFramework\QueryException
*/
protected function setUp(): void {
parent::setUp();
$this->cleanUp();
/**
* @var Db\BookmarkMapper
*/
$this->bookmarkMapper = OC::$server->get(Db\BookmarkMapper::class);
$this->treeMapper = OC::$server->get(Db\TreeMapper::class);
$this->folderMapper = OC::$server->get(Db\FolderMapper::class);
$this->userManager = OC::$server->get(IUserManager::class);
$this->user = 'test';
if (!$this->userManager->userExists($this->user)) {
$this->userManager->createUser($this->user, 'password');
}
$this->userId = $this->userManager->get($this->user)->getUID();
}
/**
* @dataProvider singleBookmarksProvider
* @param Entity $bookmark
* @return void
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws AlreadyExistsError
* @throws UrlParseError
* @throws UserLimitExceededError
*/
public function testInsertAndFind(Entity $bookmark) {
$bookmark->setUserId($this->userId);
$bookmark = $this->bookmarkMapper->insert($bookmark);
$foundEntity = $this->bookmarkMapper->find($bookmark->getId());
$this->assertSame($bookmark->getUrl(), $foundEntity->getUrl());
$this->assertSame((string)$bookmark->getTitle(), (string)$foundEntity->getTitle());
$this->assertSame((string)$bookmark->getDescription(), (string)$foundEntity->getDescription());
}
/**
* @depends testInsertAndFind
* @dataProvider singleBookmarksProvider
* @param Entity $bookmark
* @return void
* @throws AlreadyExistsError
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws UrlParseError
* @throws UserLimitExceededError
*/
public function testUpdate(Entity $bookmark) {
$bookmark->setUserId($this->userId);
$bookmark = $this->bookmarkMapper->insert($bookmark);
$entity = $this->bookmarkMapper->find($bookmark->getId());
$entity->setTitle('foobar');
$this->bookmarkMapper->update($entity);
$foundEntity = $this->bookmarkMapper->find($entity->getId());
$this->assertSame((string)$entity->getTitle(), (string)$foundEntity->getTitle());
}
/**
* @depends testInsertAndFind
* @dataProvider singleBookmarksProvider
* @param Entity $bookmark
* @return void
* @throws AlreadyExistsError
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws UrlParseError
* @throws UserLimitExceededError
*/
public function testDelete(Entity $bookmark) {
$bookmark->setUserId($this->userId);
$bookmark = $this->bookmarkMapper->insert($bookmark);
$foundEntity = $this->bookmarkMapper->find($bookmark->getId());
$this->bookmarkMapper->delete($foundEntity);
$this->expectException(DoesNotExistException::class);
$this->bookmarkMapper->find($foundEntity->getId());
}
/**
* @return array
*/
public function singleBookmarksProvider(): array {
return array_map(function ($props) {
return [Db\Bookmark::fromArray($props)];
}, [
'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', 'description' => ''],
'Simple URL' => ['url' => 'https://php.net/', 'title' => '', 'description' => ''],
'URL with unicode' => ['url' => 'https://de.wikipedia.org/wiki/%C3%9C', 'title' => '', 'description' => ''],
]);
}
}