diff options
Diffstat (limited to 'tests/api/controllers/tags/PutTagTest.php')
-rw-r--r-- | tests/api/controllers/tags/PutTagTest.php | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 86106fc7..2a3cc15a 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Api\Exceptions\ApiBadParametersException; | 5 | use Shaarli\Api\Exceptions\ApiBadParametersException; |
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; |
@@ -44,9 +45,9 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
44 | protected $container; | 45 | protected $container; |
45 | 46 | ||
46 | /** | 47 | /** |
47 | * @var LinkDB instance. | 48 | * @var BookmarkFileService instance. |
48 | */ | 49 | */ |
49 | protected $linkDB; | 50 | protected $bookmarkService; |
50 | 51 | ||
51 | /** | 52 | /** |
52 | * @var Tags controller instance. | 53 | * @var Tags controller instance. |
@@ -59,22 +60,22 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
59 | const NB_FIELDS_TAG = 2; | 60 | const NB_FIELDS_TAG = 2; |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * Before every test, instantiate a new Api with its config, plugins and links. | 63 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
63 | */ | 64 | */ |
64 | public function setUp() | 65 | public function setUp() |
65 | { | 66 | { |
66 | $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); | 67 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
68 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
67 | $this->refDB = new \ReferenceLinkDB(); | 69 | $this->refDB = new \ReferenceLinkDB(); |
68 | $this->refDB->write(self::$testDatastore); | 70 | $this->refDB->write(self::$testDatastore); |
69 | |||
70 | $refHistory = new \ReferenceHistory(); | 71 | $refHistory = new \ReferenceHistory(); |
71 | $refHistory->write(self::$testHistory); | 72 | $refHistory->write(self::$testHistory); |
72 | $this->history = new History(self::$testHistory); | 73 | $this->history = new History(self::$testHistory); |
74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
73 | 75 | ||
74 | $this->container = new Container(); | 76 | $this->container = new Container(); |
75 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
76 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); | 78 | $this->container['db'] = $this->bookmarkService; |
77 | $this->container['db'] = $this->linkDB; | ||
78 | $this->container['history'] = $this->history; | 79 | $this->container['history'] = $this->history; |
79 | 80 | ||
80 | $this->controller = new Tags($this->container); | 81 | $this->controller = new Tags($this->container); |
@@ -109,7 +110,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
109 | $this->assertEquals($newName, $data['name']); | 110 | $this->assertEquals($newName, $data['name']); |
110 | $this->assertEquals(2, $data['occurrences']); | 111 | $this->assertEquals(2, $data['occurrences']); |
111 | 112 | ||
112 | $tags = $this->linkDB->linksCountPerTag(); | 113 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
113 | $this->assertNotTrue(isset($tags[$tagName])); | 114 | $this->assertNotTrue(isset($tags[$tagName])); |
114 | $this->assertEquals(2, $tags[$newName]); | 115 | $this->assertEquals(2, $tags[$newName]); |
115 | 116 | ||
@@ -133,7 +134,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
133 | $tagName = 'gnu'; | 134 | $tagName = 'gnu'; |
134 | $newName = 'w3c'; | 135 | $newName = 'w3c'; |
135 | 136 | ||
136 | $tags = $this->linkDB->linksCountPerTag(); | 137 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
137 | $this->assertEquals(1, $tags[$newName]); | 138 | $this->assertEquals(1, $tags[$newName]); |
138 | $this->assertEquals(2, $tags[$tagName]); | 139 | $this->assertEquals(2, $tags[$tagName]); |
139 | 140 | ||
@@ -151,7 +152,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
151 | $this->assertEquals($newName, $data['name']); | 152 | $this->assertEquals($newName, $data['name']); |
152 | $this->assertEquals(3, $data['occurrences']); | 153 | $this->assertEquals(3, $data['occurrences']); |
153 | 154 | ||
154 | $tags = $this->linkDB->linksCountPerTag(); | 155 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
155 | $this->assertNotTrue(isset($tags[$tagName])); | 156 | $this->assertNotTrue(isset($tags[$tagName])); |
156 | $this->assertEquals(3, $tags[$newName]); | 157 | $this->assertEquals(3, $tags[$newName]); |
157 | } | 158 | } |
@@ -167,7 +168,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
167 | $tagName = 'gnu'; | 168 | $tagName = 'gnu'; |
168 | $newName = ''; | 169 | $newName = ''; |
169 | 170 | ||
170 | $tags = $this->linkDB->linksCountPerTag(); | 171 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
171 | $this->assertEquals(2, $tags[$tagName]); | 172 | $this->assertEquals(2, $tags[$tagName]); |
172 | 173 | ||
173 | $env = Environment::mock([ | 174 | $env = Environment::mock([ |
@@ -185,7 +186,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
185 | try { | 186 | try { |
186 | $this->controller->putTag($request, new Response(), ['tagName' => $tagName]); | 187 | $this->controller->putTag($request, new Response(), ['tagName' => $tagName]); |
187 | } catch (ApiBadParametersException $e) { | 188 | } catch (ApiBadParametersException $e) { |
188 | $tags = $this->linkDB->linksCountPerTag(); | 189 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
189 | $this->assertEquals(2, $tags[$tagName]); | 190 | $this->assertEquals(2, $tags[$tagName]); |
190 | throw $e; | 191 | throw $e; |
191 | } | 192 | } |