aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/DeleteLinkTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-13 12:05:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 12:05:08 +0200
commitb6f678a5a1d15acf284ebcec16c905e976671ce1 (patch)
tree33c7da831482ed79c44896ef19c73c72ada84f2e /tests/api/controllers/links/DeleteLinkTest.php
parentb14687036b9b800681197f51fdc47e62f0c88e2e (diff)
parent1c1520b6b98ab20201bfe15577782a52320339df (diff)
downloadShaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.gz
Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.zst
Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.zip
Merge branch 'v0.12' into latest
Diffstat (limited to 'tests/api/controllers/links/DeleteLinkTest.php')
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php32
1 files changed, 17 insertions, 15 deletions
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 90193e28..cf9464f0 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -3,7 +3,7 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB; 6use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History; 8use Shaarli\History;
9use Slim\Container; 9use Slim\Container;
@@ -11,7 +11,7 @@ use Slim\Http\Environment;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
14class DeleteLinkTest extends \PHPUnit\Framework\TestCase 14class DeleteLinkTest extends \Shaarli\TestCase
15{ 15{
16 /** 16 /**
17 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -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 protected function setUp(): void
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);
@@ -76,7 +78,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
76 /** 78 /**
77 * After each test, remove the test datastore. 79 * After each test, remove the test datastore.
78 */ 80 */
79 public function tearDown() 81 protected function tearDown(): void
80 { 82 {
81 @unlink(self::$testDatastore); 83 @unlink(self::$testDatastore);
82 @unlink(self::$testHistory); 84 @unlink(self::$testHistory);
@@ -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']);
@@ -111,13 +113,13 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
111 113
112 /** 114 /**
113 * Test DELETE link endpoint: reach not existing ID. 115 * Test DELETE link endpoint: reach not existing ID.
114 *
115 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
116 */ 116 */
117 public function testDeleteLink404() 117 public function testDeleteLink404()
118 { 118 {
119 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
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 ]);