diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 10:01:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-18 10:01:06 +0100 |
commit | 3fb29fdda04ca86e04422d49b86cf646d53c4f9d (patch) | |
tree | adf8512f93f5559ba87d0c9931969ae4ebea7133 /tests/api/controllers/links/PostLinkTest.php | |
parent | 796c4c57d085ae4589b53dfe8369ae9ba30ffdaf (diff) | |
parent | e26e2060f5470ce8bf4c5973284bae07b8af170a (diff) | |
download | Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.gz Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.zst Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.zip |
Store bookmarks as PHP objects and add a service layer to retriā¦ (#1307)
Store bookmarks as PHP objects and add a service layer to retrieve them
Diffstat (limited to 'tests/api/controllers/links/PostLinkTest.php')
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index d683a984..b2dd09eb 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -3,6 +3,8 @@ | |||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use Shaarli\Bookmark\Bookmark; | ||
7 | use Shaarli\Bookmark\BookmarkFileService; | ||
6 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | 9 | use Shaarli\History; |
8 | use Slim\Container; | 10 | use Slim\Container; |
@@ -41,6 +43,11 @@ class PostLinkTest extends TestCase | |||
41 | protected $refDB = null; | 43 | protected $refDB = null; |
42 | 44 | ||
43 | /** | 45 | /** |
46 | * @var BookmarkFileService instance. | ||
47 | */ | ||
48 | protected $bookmarkService; | ||
49 | |||
50 | /** | ||
44 | * @var HistoryController instance. | 51 | * @var HistoryController instance. |
45 | */ | 52 | */ |
46 | protected $history; | 53 | protected $history; |
@@ -61,29 +68,30 @@ class PostLinkTest extends TestCase | |||
61 | const NB_FIELDS_LINK = 9; | 68 | const NB_FIELDS_LINK = 9; |
62 | 69 | ||
63 | /** | 70 | /** |
64 | * Before every test, instantiate a new Api with its config, plugins and links. | 71 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
65 | */ | 72 | */ |
66 | public function setUp() | 73 | public function setUp() |
67 | { | 74 | { |
68 | $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); | 75 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
76 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
69 | $this->refDB = new \ReferenceLinkDB(); | 77 | $this->refDB = new \ReferenceLinkDB(); |
70 | $this->refDB->write(self::$testDatastore); | 78 | $this->refDB->write(self::$testDatastore); |
71 | |||
72 | $refHistory = new \ReferenceHistory(); | 79 | $refHistory = new \ReferenceHistory(); |
73 | $refHistory->write(self::$testHistory); | 80 | $refHistory->write(self::$testHistory); |
74 | $this->history = new History(self::$testHistory); | 81 | $this->history = new History(self::$testHistory); |
82 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
75 | 83 | ||
76 | $this->container = new Container(); | 84 | $this->container = new Container(); |
77 | $this->container['conf'] = $this->conf; | 85 | $this->container['conf'] = $this->conf; |
78 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); | 86 | $this->container['db'] = $this->bookmarkService; |
79 | $this->container['history'] = new History(self::$testHistory); | 87 | $this->container['history'] = $this->history; |
80 | 88 | ||
81 | $this->controller = new Links($this->container); | 89 | $this->controller = new Links($this->container); |
82 | 90 | ||
83 | $mock = $this->createMock(Router::class); | 91 | $mock = $this->createMock(Router::class); |
84 | $mock->expects($this->any()) | 92 | $mock->expects($this->any()) |
85 | ->method('relativePathFor') | 93 | ->method('relativePathFor') |
86 | ->willReturn('api/v1/links/1'); | 94 | ->willReturn('api/v1/bookmarks/1'); |
87 | 95 | ||
88 | // affect @property-read... seems to work | 96 | // affect @property-read... seems to work |
89 | $this->controller->getCi()->router = $mock; | 97 | $this->controller->getCi()->router = $mock; |
@@ -118,7 +126,7 @@ class PostLinkTest extends TestCase | |||
118 | 126 | ||
119 | $response = $this->controller->postLink($request, new Response()); | 127 | $response = $this->controller->postLink($request, new Response()); |
120 | $this->assertEquals(201, $response->getStatusCode()); | 128 | $this->assertEquals(201, $response->getStatusCode()); |
121 | $this->assertEquals('api/v1/links/1', $response->getHeader('Location')[0]); | 129 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
122 | $data = json_decode((string) $response->getBody(), true); | 130 | $data = json_decode((string) $response->getBody(), true); |
123 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 131 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
124 | $this->assertEquals(43, $data['id']); | 132 | $this->assertEquals(43, $data['id']); |
@@ -127,7 +135,7 @@ class PostLinkTest extends TestCase | |||
127 | $this->assertEquals('?' . $data['shorturl'], $data['title']); | 135 | $this->assertEquals('?' . $data['shorturl'], $data['title']); |
128 | $this->assertEquals('', $data['description']); | 136 | $this->assertEquals('', $data['description']); |
129 | $this->assertEquals([], $data['tags']); | 137 | $this->assertEquals([], $data['tags']); |
130 | $this->assertEquals(false, $data['private']); | 138 | $this->assertEquals(true, $data['private']); |
131 | $this->assertTrue( | 139 | $this->assertTrue( |
132 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 140 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
133 | ); | 141 | ); |
@@ -163,7 +171,7 @@ class PostLinkTest extends TestCase | |||
163 | $response = $this->controller->postLink($request, new Response()); | 171 | $response = $this->controller->postLink($request, new Response()); |
164 | 172 | ||
165 | $this->assertEquals(201, $response->getStatusCode()); | 173 | $this->assertEquals(201, $response->getStatusCode()); |
166 | $this->assertEquals('api/v1/links/1', $response->getHeader('Location')[0]); | 174 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
167 | $data = json_decode((string) $response->getBody(), true); | 175 | $data = json_decode((string) $response->getBody(), true); |
168 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 176 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
169 | $this->assertEquals(43, $data['id']); | 177 | $this->assertEquals(43, $data['id']); |
@@ -211,11 +219,11 @@ class PostLinkTest extends TestCase | |||
211 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 219 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
212 | $this->assertEquals(false, $data['private']); | 220 | $this->assertEquals(false, $data['private']); |
213 | $this->assertEquals( | 221 | $this->assertEquals( |
214 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 222 | \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130614_184135'), |
215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 223 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
216 | ); | 224 | ); |
217 | $this->assertEquals( | 225 | $this->assertEquals( |
218 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 226 | \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130615_184230'), |
219 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 227 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
220 | ); | 228 | ); |
221 | } | 229 | } |