diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
commit | b6f678a5a1d15acf284ebcec16c905e976671ce1 (patch) | |
tree | 33c7da831482ed79c44896ef19c73c72ada84f2e /tests/api/controllers/links/PutLinkTest.php | |
parent | b14687036b9b800681197f51fdc47e62f0c88e2e (diff) | |
parent | 1c1520b6b98ab20201bfe15577782a52320339df (diff) | |
download | Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.gz Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.zst Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.zip |
Merge branch 'v0.12' into latest
Diffstat (limited to 'tests/api/controllers/links/PutLinkTest.php')
-rw-r--r-- | tests/api/controllers/links/PutLinkTest.php | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index cd815b66..a2e87c59 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
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; |
@@ -10,7 +12,7 @@ use Slim\Http\Environment; | |||
10 | use Slim\Http\Request; | 12 | use Slim\Http\Request; |
11 | use Slim\Http\Response; | 13 | use Slim\Http\Response; |
12 | 14 | ||
13 | class PutLinkTest extends \PHPUnit\Framework\TestCase | 15 | class PutLinkTest extends \Shaarli\TestCase |
14 | { | 16 | { |
15 | /** | 17 | /** |
16 | * @var string datastore to test write operations | 18 | * @var string datastore to test write operations |
@@ -33,6 +35,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
33 | protected $refDB = null; | 35 | protected $refDB = null; |
34 | 36 | ||
35 | /** | 37 | /** |
38 | * @var BookmarkFileService instance. | ||
39 | */ | ||
40 | protected $bookmarkService; | ||
41 | |||
42 | /** | ||
36 | * @var HistoryController instance. | 43 | * @var HistoryController instance. |
37 | */ | 44 | */ |
38 | protected $history; | 45 | protected $history; |
@@ -53,22 +60,23 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
53 | const NB_FIELDS_LINK = 9; | 60 | const NB_FIELDS_LINK = 9; |
54 | 61 | ||
55 | /** | 62 | /** |
56 | * 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. |
57 | */ | 64 | */ |
58 | public function setUp() | 65 | protected function setUp(): void |
59 | { | 66 | { |
60 | $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); | ||
61 | $this->refDB = new \ReferenceLinkDB(); | 69 | $this->refDB = new \ReferenceLinkDB(); |
62 | $this->refDB->write(self::$testDatastore); | 70 | $this->refDB->write(self::$testDatastore); |
63 | |||
64 | $refHistory = new \ReferenceHistory(); | 71 | $refHistory = new \ReferenceHistory(); |
65 | $refHistory->write(self::$testHistory); | 72 | $refHistory->write(self::$testHistory); |
66 | $this->history = new History(self::$testHistory); | 73 | $this->history = new History(self::$testHistory); |
74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
67 | 75 | ||
68 | $this->container = new Container(); | 76 | $this->container = new Container(); |
69 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
70 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); | 78 | $this->container['db'] = $this->bookmarkService; |
71 | $this->container['history'] = new History(self::$testHistory); | 79 | $this->container['history'] = $this->history; |
72 | 80 | ||
73 | $this->controller = new Links($this->container); | 81 | $this->controller = new Links($this->container); |
74 | 82 | ||
@@ -83,7 +91,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
83 | /** | 91 | /** |
84 | * After every test, remove the test datastore. | 92 | * After every test, remove the test datastore. |
85 | */ | 93 | */ |
86 | public function tearDown() | 94 | protected function tearDown(): void |
87 | { | 95 | { |
88 | @unlink(self::$testDatastore); | 96 | @unlink(self::$testDatastore); |
89 | @unlink(self::$testHistory); | 97 | @unlink(self::$testHistory); |
@@ -106,11 +114,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
106 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 114 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
107 | $this->assertEquals($id, $data['id']); | 115 | $this->assertEquals($id, $data['id']); |
108 | $this->assertEquals('WDWyig', $data['shorturl']); | 116 | $this->assertEquals('WDWyig', $data['shorturl']); |
109 | $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); | 117 | $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); |
110 | $this->assertEquals('?WDWyig', $data['title']); | 118 | $this->assertEquals('/shaare/WDWyig', $data['title']); |
111 | $this->assertEquals('', $data['description']); | 119 | $this->assertEquals('', $data['description']); |
112 | $this->assertEquals([], $data['tags']); | 120 | $this->assertEquals([], $data['tags']); |
113 | $this->assertEquals(false, $data['private']); | 121 | $this->assertEquals(true, $data['private']); |
114 | $this->assertEquals( | 122 | $this->assertEquals( |
115 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), | 123 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), |
116 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 124 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
@@ -199,23 +207,23 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
199 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 207 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
200 | $this->assertEquals(false, $data['private']); | 208 | $this->assertEquals(false, $data['private']); |
201 | $this->assertEquals( | 209 | $this->assertEquals( |
202 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 210 | \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130614_184135'), |
203 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 211 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
204 | ); | 212 | ); |
205 | $this->assertEquals( | 213 | $this->assertEquals( |
206 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 214 | \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130615_184230'), |
207 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
208 | ); | 216 | ); |
209 | } | 217 | } |
210 | 218 | ||
211 | /** | 219 | /** |
212 | * Test link update on non existent link => ApiLinkNotFoundException. | 220 | * Test link update on non existent link => ApiLinkNotFoundException. |
213 | * | ||
214 | * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException | ||
215 | * @expectedExceptionMessage Link not found | ||
216 | */ | 221 | */ |
217 | public function testGetLink404() | 222 | public function testGetLink404() |
218 | { | 223 | { |
224 | $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); | ||
225 | $this->expectExceptionMessage('Link not found'); | ||
226 | |||
219 | $env = Environment::mock([ | 227 | $env = Environment::mock([ |
220 | 'REQUEST_METHOD' => 'PUT', | 228 | 'REQUEST_METHOD' => 'PUT', |
221 | ]); | 229 | ]); |