diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-17 21:34:12 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 09:56:32 +0100 |
commit | e26e2060f5470ce8bf4c5973284bae07b8af170a (patch) | |
tree | adf8512f93f5559ba87d0c9931969ae4ebea7133 /tests/api/controllers/links/DeleteLinkTest.php | |
parent | cf92b4dd1521241eefc58eaf6dcd202cd83969d8 (diff) | |
download | Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.gz Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.zst Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.zip |
Add and update unit test for the new system (Bookmark + Service)
See #1307
Diffstat (limited to 'tests/api/controllers/links/DeleteLinkTest.php')
-rw-r--r-- | tests/api/controllers/links/DeleteLinkTest.php | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 90193e28..6c2b3698 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Bookmark\LinkDB; | 6 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | 8 | use Shaarli\History; |
9 | use Slim\Container; | 9 | use Slim\Container; |
@@ -34,9 +34,9 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
34 | protected $refDB = null; | 34 | protected $refDB = null; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * @var LinkDB instance. | 37 | * @var BookmarkFileService instance. |
38 | */ | 38 | */ |
39 | protected $linkDB; | 39 | protected $bookmarkService; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * @var HistoryController instance. | 42 | * @var HistoryController instance. |
@@ -54,20 +54,22 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
54 | protected $controller; | 54 | protected $controller; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Before each test, instantiate a new Api with its config, plugins and links. | 57 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
58 | */ | 58 | */ |
59 | public function setUp() | 59 | public function setUp() |
60 | { | 60 | { |
61 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 61 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
62 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
62 | $this->refDB = new \ReferenceLinkDB(); | 63 | $this->refDB = new \ReferenceLinkDB(); |
63 | $this->refDB->write(self::$testDatastore); | 64 | $this->refDB->write(self::$testDatastore); |
64 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | ||
65 | $refHistory = new \ReferenceHistory(); | 65 | $refHistory = new \ReferenceHistory(); |
66 | $refHistory->write(self::$testHistory); | 66 | $refHistory->write(self::$testHistory); |
67 | $this->history = new History(self::$testHistory); | 67 | $this->history = new History(self::$testHistory); |
68 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
69 | |||
68 | $this->container = new Container(); | 70 | $this->container = new Container(); |
69 | $this->container['conf'] = $this->conf; | 71 | $this->container['conf'] = $this->conf; |
70 | $this->container['db'] = $this->linkDB; | 72 | $this->container['db'] = $this->bookmarkService; |
71 | $this->container['history'] = $this->history; | 73 | $this->container['history'] = $this->history; |
72 | 74 | ||
73 | $this->controller = new Links($this->container); | 75 | $this->controller = new Links($this->container); |
@@ -88,7 +90,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
88 | public function testDeleteLinkValid() | 90 | public function testDeleteLinkValid() |
89 | { | 91 | { |
90 | $id = '41'; | 92 | $id = '41'; |
91 | $this->assertTrue(isset($this->linkDB[$id])); | 93 | $this->assertTrue($this->bookmarkService->exists($id)); |
92 | $env = Environment::mock([ | 94 | $env = Environment::mock([ |
93 | 'REQUEST_METHOD' => 'DELETE', | 95 | 'REQUEST_METHOD' => 'DELETE', |
94 | ]); | 96 | ]); |
@@ -98,8 +100,8 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
98 | $this->assertEquals(204, $response->getStatusCode()); | 100 | $this->assertEquals(204, $response->getStatusCode()); |
99 | $this->assertEmpty((string) $response->getBody()); | 101 | $this->assertEmpty((string) $response->getBody()); |
100 | 102 | ||
101 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | 103 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
102 | $this->assertFalse(isset($this->linkDB[$id])); | 104 | $this->assertFalse($this->bookmarkService->exists($id)); |
103 | 105 | ||
104 | $historyEntry = $this->history->getHistory()[0]; | 106 | $historyEntry = $this->history->getHistory()[0]; |
105 | $this->assertEquals(History::DELETED, $historyEntry['event']); | 107 | $this->assertEquals(History::DELETED, $historyEntry['event']); |
@@ -117,7 +119,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
117 | public function testDeleteLink404() | 119 | public function testDeleteLink404() |
118 | { | 120 | { |
119 | $id = -1; | 121 | $id = -1; |
120 | $this->assertFalse(isset($this->linkDB[$id])); | 122 | $this->assertFalse($this->bookmarkService->exists($id)); |
121 | $env = Environment::mock([ | 123 | $env = Environment::mock([ |
122 | 'REQUEST_METHOD' => 'DELETE', | 124 | 'REQUEST_METHOD' => 'DELETE', |
123 | ]); | 125 | ]); |