diff options
Diffstat (limited to 'tests/api/controllers/tags/DeleteTagTest.php')
-rw-r--r-- | tests/api/controllers/tags/DeleteTagTest.php | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index 84e1d56e..c6748872 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Bookmark\BookmarkFileService; | ||
6 | use Shaarli\Bookmark\LinkDB; | 7 | use Shaarli\Bookmark\LinkDB; |
7 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | 9 | use Shaarli\History; |
@@ -34,9 +35,9 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
34 | protected $refDB = null; | 35 | protected $refDB = null; |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * @var LinkDB instance. | 38 | * @var BookmarkFileService instance. |
38 | */ | 39 | */ |
39 | protected $linkDB; | 40 | protected $bookmarkService; |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * @var HistoryController instance. | 43 | * @var HistoryController instance. |
@@ -54,20 +55,22 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
54 | protected $controller; | 55 | protected $controller; |
55 | 56 | ||
56 | /** | 57 | /** |
57 | * Before each test, instantiate a new Api with its config, plugins and links. | 58 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
58 | */ | 59 | */ |
59 | public function setUp() | 60 | public function setUp() |
60 | { | 61 | { |
61 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
63 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
62 | $this->refDB = new \ReferenceLinkDB(); | 64 | $this->refDB = new \ReferenceLinkDB(); |
63 | $this->refDB->write(self::$testDatastore); | 65 | $this->refDB->write(self::$testDatastore); |
64 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | ||
65 | $refHistory = new \ReferenceHistory(); | 66 | $refHistory = new \ReferenceHistory(); |
66 | $refHistory->write(self::$testHistory); | 67 | $refHistory->write(self::$testHistory); |
67 | $this->history = new History(self::$testHistory); | 68 | $this->history = new History(self::$testHistory); |
69 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
70 | |||
68 | $this->container = new Container(); | 71 | $this->container = new Container(); |
69 | $this->container['conf'] = $this->conf; | 72 | $this->container['conf'] = $this->conf; |
70 | $this->container['db'] = $this->linkDB; | 73 | $this->container['db'] = $this->bookmarkService; |
71 | $this->container['history'] = $this->history; | 74 | $this->container['history'] = $this->history; |
72 | 75 | ||
73 | $this->controller = new Tags($this->container); | 76 | $this->controller = new Tags($this->container); |
@@ -88,7 +91,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
88 | public function testDeleteTagValid() | 91 | public function testDeleteTagValid() |
89 | { | 92 | { |
90 | $tagName = 'gnu'; | 93 | $tagName = 'gnu'; |
91 | $tags = $this->linkDB->linksCountPerTag(); | 94 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
92 | $this->assertTrue($tags[$tagName] > 0); | 95 | $this->assertTrue($tags[$tagName] > 0); |
93 | $env = Environment::mock([ | 96 | $env = Environment::mock([ |
94 | 'REQUEST_METHOD' => 'DELETE', | 97 | 'REQUEST_METHOD' => 'DELETE', |
@@ -99,11 +102,11 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
99 | $this->assertEquals(204, $response->getStatusCode()); | 102 | $this->assertEquals(204, $response->getStatusCode()); |
100 | $this->assertEmpty((string) $response->getBody()); | 103 | $this->assertEmpty((string) $response->getBody()); |
101 | 104 | ||
102 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | 105 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
103 | $tags = $this->linkDB->linksCountPerTag(); | 106 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
104 | $this->assertFalse(isset($tags[$tagName])); | 107 | $this->assertFalse(isset($tags[$tagName])); |
105 | 108 | ||
106 | // 2 links affected | 109 | // 2 bookmarks affected |
107 | $historyEntry = $this->history->getHistory()[0]; | 110 | $historyEntry = $this->history->getHistory()[0]; |
108 | $this->assertEquals(History::UPDATED, $historyEntry['event']); | 111 | $this->assertEquals(History::UPDATED, $historyEntry['event']); |
109 | $this->assertTrue( | 112 | $this->assertTrue( |
@@ -122,7 +125,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
122 | public function testDeleteTagCaseSensitivity() | 125 | public function testDeleteTagCaseSensitivity() |
123 | { | 126 | { |
124 | $tagName = 'sTuff'; | 127 | $tagName = 'sTuff'; |
125 | $tags = $this->linkDB->linksCountPerTag(); | 128 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
126 | $this->assertTrue($tags[$tagName] > 0); | 129 | $this->assertTrue($tags[$tagName] > 0); |
127 | $env = Environment::mock([ | 130 | $env = Environment::mock([ |
128 | 'REQUEST_METHOD' => 'DELETE', | 131 | 'REQUEST_METHOD' => 'DELETE', |
@@ -133,8 +136,8 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
133 | $this->assertEquals(204, $response->getStatusCode()); | 136 | $this->assertEquals(204, $response->getStatusCode()); |
134 | $this->assertEmpty((string) $response->getBody()); | 137 | $this->assertEmpty((string) $response->getBody()); |
135 | 138 | ||
136 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | 139 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
137 | $tags = $this->linkDB->linksCountPerTag(); | 140 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
138 | $this->assertFalse(isset($tags[$tagName])); | 141 | $this->assertFalse(isset($tags[$tagName])); |
139 | $this->assertTrue($tags[strtolower($tagName)] > 0); | 142 | $this->assertTrue($tags[strtolower($tagName)] > 0); |
140 | 143 | ||
@@ -154,7 +157,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
154 | public function testDeleteLink404() | 157 | public function testDeleteLink404() |
155 | { | 158 | { |
156 | $tagName = 'nopenope'; | 159 | $tagName = 'nopenope'; |
157 | $tags = $this->linkDB->linksCountPerTag(); | 160 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
158 | $this->assertFalse(isset($tags[$tagName])); | 161 | $this->assertFalse(isset($tags[$tagName])); |
159 | $env = Environment::mock([ | 162 | $env = Environment::mock([ |
160 | 'REQUEST_METHOD' => 'DELETE', | 163 | 'REQUEST_METHOD' => 'DELETE', |