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/GetLinkIdTest.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/GetLinkIdTest.php')
-rw-r--r-- | tests/api/controllers/links/GetLinkIdTest.php | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index cb9b7f6a..99dc606f 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php | |||
@@ -2,7 +2,10 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Bookmark\Bookmark; | ||
6 | use Shaarli\Bookmark\BookmarkFileService; | ||
5 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
6 | use Slim\Container; | 9 | use Slim\Container; |
7 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
@@ -17,7 +20,7 @@ use Slim\Http\Response; | |||
17 | * | 20 | * |
18 | * @package Shaarli\Api\Controllers | 21 | * @package Shaarli\Api\Controllers |
19 | */ | 22 | */ |
20 | class GetLinkIdTest extends \PHPUnit\Framework\TestCase | 23 | class GetLinkIdTest extends \Shaarli\TestCase |
21 | { | 24 | { |
22 | /** | 25 | /** |
23 | * @var string datastore to test write operations | 26 | * @var string datastore to test write operations |
@@ -50,17 +53,19 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
50 | const NB_FIELDS_LINK = 9; | 53 | const NB_FIELDS_LINK = 9; |
51 | 54 | ||
52 | /** | 55 | /** |
53 | * Before each test, instantiate a new Api with its config, plugins and links. | 56 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
54 | */ | 57 | */ |
55 | public function setUp() | 58 | protected function setUp(): void |
56 | { | 59 | { |
57 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 60 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
61 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
58 | $this->refDB = new \ReferenceLinkDB(); | 62 | $this->refDB = new \ReferenceLinkDB(); |
59 | $this->refDB->write(self::$testDatastore); | 63 | $this->refDB->write(self::$testDatastore); |
64 | $history = new History('sandbox/history.php'); | ||
60 | 65 | ||
61 | $this->container = new Container(); | 66 | $this->container = new Container(); |
62 | $this->container['conf'] = $this->conf; | 67 | $this->container['conf'] = $this->conf; |
63 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); | 68 | $this->container['db'] = new BookmarkFileService($this->conf, $history, true); |
64 | $this->container['history'] = null; | 69 | $this->container['history'] = null; |
65 | 70 | ||
66 | $this->controller = new Links($this->container); | 71 | $this->controller = new Links($this->container); |
@@ -69,7 +74,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
69 | /** | 74 | /** |
70 | * After each test, remove the test datastore. | 75 | * After each test, remove the test datastore. |
71 | */ | 76 | */ |
72 | public function tearDown() | 77 | protected function tearDown(): void |
73 | { | 78 | { |
74 | @unlink(self::$testDatastore); | 79 | @unlink(self::$testDatastore); |
75 | } | 80 | } |
@@ -97,7 +102,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
97 | $this->assertEquals($id, $data['id']); | 102 | $this->assertEquals($id, $data['id']); |
98 | 103 | ||
99 | // Check link elements | 104 | // Check link elements |
100 | $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); | 105 | $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); |
101 | $this->assertEquals('WDWyig', $data['shorturl']); | 106 | $this->assertEquals('WDWyig', $data['shorturl']); |
102 | $this->assertEquals('Link title: @website', $data['title']); | 107 | $this->assertEquals('Link title: @website', $data['title']); |
103 | $this->assertEquals( | 108 | $this->assertEquals( |
@@ -107,7 +112,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
107 | $this->assertEquals('sTuff', $data['tags'][0]); | 112 | $this->assertEquals('sTuff', $data['tags'][0]); |
108 | $this->assertEquals(false, $data['private']); | 113 | $this->assertEquals(false, $data['private']); |
109 | $this->assertEquals( | 114 | $this->assertEquals( |
110 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), | 115 | \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), |
111 | $data['created'] | 116 | $data['created'] |
112 | ); | 117 | ); |
113 | $this->assertEmpty($data['updated']); | 118 | $this->assertEmpty($data['updated']); |
@@ -115,12 +120,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
115 | 120 | ||
116 | /** | 121 | /** |
117 | * Test basic getLink service: get non existent link => ApiLinkNotFoundException. | 122 | * Test basic getLink service: get non existent link => ApiLinkNotFoundException. |
118 | * | ||
119 | * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException | ||
120 | * @expectedExceptionMessage Link not found | ||
121 | */ | 123 | */ |
122 | public function testGetLink404() | 124 | public function testGetLink404() |
123 | { | 125 | { |
126 | $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); | ||
127 | $this->expectExceptionMessage('Link not found'); | ||
128 | |||
124 | $env = Environment::mock([ | 129 | $env = Environment::mock([ |
125 | 'REQUEST_METHOD' => 'GET', | 130 | 'REQUEST_METHOD' => 'GET', |
126 | ]); | 131 | ]); |