diff options
Diffstat (limited to 'tests/api/controllers/links')
-rw-r--r-- | tests/api/controllers/links/DeleteLinkTest.php | 18 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinkIdTest.php | 7 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinksTest.php | 31 | ||||
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 28 | ||||
-rw-r--r-- | tests/api/controllers/links/PutLinkTest.php | 26 |
5 files changed, 61 insertions, 49 deletions
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 7d797137..90193e28 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php | |||
@@ -3,13 +3,15 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Bookmark\LinkDB; | ||
6 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
7 | use Slim\Container; | 9 | use Slim\Container; |
8 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
10 | use Slim\Http\Response; | 12 | use Slim\Http\Response; |
11 | 13 | ||
12 | class DeleteLinkTest extends \PHPUnit_Framework_TestCase | 14 | class DeleteLinkTest extends \PHPUnit\Framework\TestCase |
13 | { | 15 | { |
14 | /** | 16 | /** |
15 | * @var string datastore to test write operations | 17 | * @var string datastore to test write operations |
@@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase | |||
32 | protected $refDB = null; | 34 | protected $refDB = null; |
33 | 35 | ||
34 | /** | 36 | /** |
35 | * @var \LinkDB instance. | 37 | * @var LinkDB instance. |
36 | */ | 38 | */ |
37 | protected $linkDB; | 39 | protected $linkDB; |
38 | 40 | ||
39 | /** | 41 | /** |
40 | * @var \History instance. | 42 | * @var HistoryController instance. |
41 | */ | 43 | */ |
42 | protected $history; | 44 | protected $history; |
43 | 45 | ||
@@ -59,10 +61,10 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase | |||
59 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 61 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
60 | $this->refDB = new \ReferenceLinkDB(); | 62 | $this->refDB = new \ReferenceLinkDB(); |
61 | $this->refDB->write(self::$testDatastore); | 63 | $this->refDB->write(self::$testDatastore); |
62 | $this->linkDB = new \LinkDB(self::$testDatastore, true, false); | 64 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); |
63 | $refHistory = new \ReferenceHistory(); | 65 | $refHistory = new \ReferenceHistory(); |
64 | $refHistory->write(self::$testHistory); | 66 | $refHistory->write(self::$testHistory); |
65 | $this->history = new \History(self::$testHistory); | 67 | $this->history = new History(self::$testHistory); |
66 | $this->container = new Container(); | 68 | $this->container = new Container(); |
67 | $this->container['conf'] = $this->conf; | 69 | $this->container['conf'] = $this->conf; |
68 | $this->container['db'] = $this->linkDB; | 70 | $this->container['db'] = $this->linkDB; |
@@ -96,11 +98,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase | |||
96 | $this->assertEquals(204, $response->getStatusCode()); | 98 | $this->assertEquals(204, $response->getStatusCode()); |
97 | $this->assertEmpty((string) $response->getBody()); | 99 | $this->assertEmpty((string) $response->getBody()); |
98 | 100 | ||
99 | $this->linkDB = new \LinkDB(self::$testDatastore, true, false); | 101 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); |
100 | $this->assertFalse(isset($this->linkDB[$id])); | 102 | $this->assertFalse(isset($this->linkDB[$id])); |
101 | 103 | ||
102 | $historyEntry = $this->history->getHistory()[0]; | 104 | $historyEntry = $this->history->getHistory()[0]; |
103 | $this->assertEquals(\History::DELETED, $historyEntry['event']); | 105 | $this->assertEquals(History::DELETED, $historyEntry['event']); |
104 | $this->assertTrue( | 106 | $this->assertTrue( |
105 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 107 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
106 | ); | 108 | ); |
@@ -110,7 +112,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase | |||
110 | /** | 112 | /** |
111 | * Test DELETE link endpoint: reach not existing ID. | 113 | * Test DELETE link endpoint: reach not existing ID. |
112 | * | 114 | * |
113 | * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException | 115 | * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException |
114 | */ | 116 | */ |
115 | public function testDeleteLink404() | 117 | public function testDeleteLink404() |
116 | { | 118 | { |
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index 57528d5a..cb9b7f6a 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php | |||
@@ -3,7 +3,6 @@ | |||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
6 | |||
7 | use Slim\Container; | 6 | use Slim\Container; |
8 | use Slim\Http\Environment; | 7 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 8 | use Slim\Http\Request; |
@@ -18,7 +17,7 @@ use Slim\Http\Response; | |||
18 | * | 17 | * |
19 | * @package Shaarli\Api\Controllers | 18 | * @package Shaarli\Api\Controllers |
20 | */ | 19 | */ |
21 | class GetLinkIdTest extends \PHPUnit_Framework_TestCase | 20 | class GetLinkIdTest extends \PHPUnit\Framework\TestCase |
22 | { | 21 | { |
23 | /** | 22 | /** |
24 | * @var string datastore to test write operations | 23 | * @var string datastore to test write operations |
@@ -61,7 +60,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase | |||
61 | 60 | ||
62 | $this->container = new Container(); | 61 | $this->container = new Container(); |
63 | $this->container['conf'] = $this->conf; | 62 | $this->container['conf'] = $this->conf; |
64 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 63 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); |
65 | $this->container['history'] = null; | 64 | $this->container['history'] = null; |
66 | 65 | ||
67 | $this->controller = new Links($this->container); | 66 | $this->controller = new Links($this->container); |
@@ -108,7 +107,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase | |||
108 | $this->assertEquals('sTuff', $data['tags'][0]); | 107 | $this->assertEquals('sTuff', $data['tags'][0]); |
109 | $this->assertEquals(false, $data['private']); | 108 | $this->assertEquals(false, $data['private']); |
110 | $this->assertEquals( | 109 | $this->assertEquals( |
111 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), | 110 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), |
112 | $data['created'] | 111 | $data['created'] |
113 | ); | 112 | ); |
114 | $this->assertEmpty($data['updated']); | 113 | $this->assertEmpty($data['updated']); |
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index d22ed3bf..711a3152 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php | |||
@@ -1,8 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use Shaarli\Bookmark\LinkDB; | ||
4 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
5 | |||
6 | use Slim\Container; | 6 | use Slim\Container; |
7 | use Slim\Http\Environment; | 7 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 8 | use Slim\Http\Request; |
@@ -17,7 +17,7 @@ use Slim\Http\Response; | |||
17 | * | 17 | * |
18 | * @package Shaarli\Api\Controllers | 18 | * @package Shaarli\Api\Controllers |
19 | */ | 19 | */ |
20 | class GetLinksTest extends \PHPUnit_Framework_TestCase | 20 | class GetLinksTest extends \PHPUnit\Framework\TestCase |
21 | { | 21 | { |
22 | /** | 22 | /** |
23 | * @var string datastore to test write operations | 23 | * @var string datastore to test write operations |
@@ -60,7 +60,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
60 | 60 | ||
61 | $this->container = new Container(); | 61 | $this->container = new Container(); |
62 | $this->container['conf'] = $this->conf; | 62 | $this->container['conf'] = $this->conf; |
63 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 63 | $this->container['db'] = new LinkDB(self::$testDatastore, true, false); |
64 | $this->container['history'] = null; | 64 | $this->container['history'] = null; |
65 | 65 | ||
66 | $this->controller = new Links($this->container); | 66 | $this->controller = new Links($this->container); |
@@ -95,7 +95,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
95 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 95 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
96 | 96 | ||
97 | // Check order | 97 | // Check order |
98 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; | 98 | $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42]; |
99 | $cpt = 0; | 99 | $cpt = 0; |
100 | foreach ($data as $link) { | 100 | foreach ($data as $link) { |
101 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 101 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
@@ -103,7 +103,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
103 | } | 103 | } |
104 | 104 | ||
105 | // Check first element fields | 105 | // Check first element fields |
106 | $first = $data[0]; | 106 | $first = $data[2]; |
107 | $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); | 107 | $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); |
108 | $this->assertEquals('WDWyig', $first['shorturl']); | 108 | $this->assertEquals('WDWyig', $first['shorturl']); |
109 | $this->assertEquals('Link title: @website', $first['title']); | 109 | $this->assertEquals('Link title: @website', $first['title']); |
@@ -114,18 +114,18 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
114 | $this->assertEquals('sTuff', $first['tags'][0]); | 114 | $this->assertEquals('sTuff', $first['tags'][0]); |
115 | $this->assertEquals(false, $first['private']); | 115 | $this->assertEquals(false, $first['private']); |
116 | $this->assertEquals( | 116 | $this->assertEquals( |
117 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), | 117 | \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), |
118 | $first['created'] | 118 | $first['created'] |
119 | ); | 119 | ); |
120 | $this->assertEmpty($first['updated']); | 120 | $this->assertEmpty($first['updated']); |
121 | 121 | ||
122 | // Multi tags | 122 | // Multi tags |
123 | $link = $data[1]; | 123 | $link = $data[3]; |
124 | $this->assertEquals(7, count($link['tags'])); | 124 | $this->assertEquals(7, count($link['tags'])); |
125 | 125 | ||
126 | // Update date | 126 | // Update date |
127 | $this->assertEquals( | 127 | $this->assertEquals( |
128 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), | 128 | \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), |
129 | $link['updated'] | 129 | $link['updated'] |
130 | ); | 130 | ); |
131 | } | 131 | } |
@@ -138,7 +138,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
138 | { | 138 | { |
139 | $env = Environment::mock([ | 139 | $env = Environment::mock([ |
140 | 'REQUEST_METHOD' => 'GET', | 140 | 'REQUEST_METHOD' => 'GET', |
141 | 'QUERY_STRING' => 'offset=1&limit=1' | 141 | 'QUERY_STRING' => 'offset=3&limit=1' |
142 | ]); | 142 | ]); |
143 | $request = Request::createFromEnvironment($env); | 143 | $request = Request::createFromEnvironment($env); |
144 | $response = $this->controller->getLinks($request, new Response()); | 144 | $response = $this->controller->getLinks($request, new Response()); |
@@ -164,7 +164,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
164 | $data = json_decode((string) $response->getBody(), true); | 164 | $data = json_decode((string) $response->getBody(), true); |
165 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 165 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
166 | // Check order | 166 | // Check order |
167 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; | 167 | $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42]; |
168 | $cpt = 0; | 168 | $cpt = 0; |
169 | foreach ($data as $link) { | 169 | foreach ($data as $link) { |
170 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 170 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
@@ -205,7 +205,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
205 | $this->assertEquals(200, $response->getStatusCode()); | 205 | $this->assertEquals(200, $response->getStatusCode()); |
206 | $data = json_decode((string)$response->getBody(), true); | 206 | $data = json_decode((string)$response->getBody(), true); |
207 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 207 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
208 | $this->assertEquals(41, $data[0]['id']); | 208 | $this->assertEquals(10, $data[0]['id']); |
209 | $this->assertEquals(41, $data[2]['id']); | ||
209 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); | 210 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); |
210 | } | 211 | } |
211 | 212 | ||
@@ -243,7 +244,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
243 | $this->assertEquals(200, $response->getStatusCode()); | 244 | $this->assertEquals(200, $response->getStatusCode()); |
244 | $data = json_decode((string)$response->getBody(), true); | 245 | $data = json_decode((string)$response->getBody(), true); |
245 | $this->assertEquals($this->refDB->countPublicLinks(), count($data)); | 246 | $this->assertEquals($this->refDB->countPublicLinks(), count($data)); |
246 | $this->assertEquals(41, $data[0]['id']); | 247 | $this->assertEquals(10, $data[0]['id']); |
248 | $this->assertEquals(41, $data[2]['id']); | ||
247 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); | 249 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); |
248 | } | 250 | } |
249 | 251 | ||
@@ -413,8 +415,9 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
413 | $response = $this->controller->getLinks($request, new Response()); | 415 | $response = $this->controller->getLinks($request, new Response()); |
414 | $this->assertEquals(200, $response->getStatusCode()); | 416 | $this->assertEquals(200, $response->getStatusCode()); |
415 | $data = json_decode((string) $response->getBody(), true); | 417 | $data = json_decode((string) $response->getBody(), true); |
416 | $this->assertEquals(9, count($data)); | 418 | $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, count($data)); |
417 | $this->assertEquals(41, $data[0]['id']); | 419 | $this->assertEquals(10, $data[0]['id']); |
420 | $this->assertEquals(41, $data[2]['id']); | ||
418 | 421 | ||
419 | // wildcard: optional ('*' does not need to expand) | 422 | // wildcard: optional ('*' does not need to expand) |
420 | $env = Environment::mock([ | 423 | $env = Environment::mock([ |
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 100a9170..d683a984 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | |||
6 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
7 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
8 | use Slim\Container; | 8 | use Slim\Container; |
9 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
@@ -41,7 +41,7 @@ class PostLinkTest extends TestCase | |||
41 | protected $refDB = null; | 41 | protected $refDB = null; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * @var \History instance. | 44 | * @var HistoryController instance. |
45 | */ | 45 | */ |
46 | protected $history; | 46 | protected $history; |
47 | 47 | ||
@@ -71,12 +71,12 @@ class PostLinkTest extends TestCase | |||
71 | 71 | ||
72 | $refHistory = new \ReferenceHistory(); | 72 | $refHistory = new \ReferenceHistory(); |
73 | $refHistory->write(self::$testHistory); | 73 | $refHistory->write(self::$testHistory); |
74 | $this->history = new \History(self::$testHistory); | 74 | $this->history = new History(self::$testHistory); |
75 | 75 | ||
76 | $this->container = new Container(); | 76 | $this->container = new Container(); |
77 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
78 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 78 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); |
79 | $this->container['history'] = new \History(self::$testHistory); | 79 | $this->container['history'] = new History(self::$testHistory); |
80 | 80 | ||
81 | $this->controller = new Links($this->container); | 81 | $this->controller = new Links($this->container); |
82 | 82 | ||
@@ -122,17 +122,19 @@ class PostLinkTest extends TestCase | |||
122 | $data = json_decode((string) $response->getBody(), true); | 122 | $data = json_decode((string) $response->getBody(), true); |
123 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 123 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
124 | $this->assertEquals(43, $data['id']); | 124 | $this->assertEquals(43, $data['id']); |
125 | $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); | 125 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); |
126 | $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); | 126 | $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); |
127 | $this->assertEquals('?' . $data['shorturl'], $data['title']); | 127 | $this->assertEquals('?' . $data['shorturl'], $data['title']); |
128 | $this->assertEquals('', $data['description']); | 128 | $this->assertEquals('', $data['description']); |
129 | $this->assertEquals([], $data['tags']); | 129 | $this->assertEquals([], $data['tags']); |
130 | $this->assertEquals(false, $data['private']); | 130 | $this->assertEquals(false, $data['private']); |
131 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); | 131 | $this->assertTrue( |
132 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | ||
133 | ); | ||
132 | $this->assertEquals('', $data['updated']); | 134 | $this->assertEquals('', $data['updated']); |
133 | 135 | ||
134 | $historyEntry = $this->history->getHistory()[0]; | 136 | $historyEntry = $this->history->getHistory()[0]; |
135 | $this->assertEquals(\History::CREATED, $historyEntry['event']); | 137 | $this->assertEquals(History::CREATED, $historyEntry['event']); |
136 | $this->assertTrue( | 138 | $this->assertTrue( |
137 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 139 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
138 | ); | 140 | ); |
@@ -165,13 +167,15 @@ class PostLinkTest extends TestCase | |||
165 | $data = json_decode((string) $response->getBody(), true); | 167 | $data = json_decode((string) $response->getBody(), true); |
166 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 168 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
167 | $this->assertEquals(43, $data['id']); | 169 | $this->assertEquals(43, $data['id']); |
168 | $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); | 170 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); |
169 | $this->assertEquals('http://' . $link['url'], $data['url']); | 171 | $this->assertEquals('http://' . $link['url'], $data['url']); |
170 | $this->assertEquals($link['title'], $data['title']); | 172 | $this->assertEquals($link['title'], $data['title']); |
171 | $this->assertEquals($link['description'], $data['description']); | 173 | $this->assertEquals($link['description'], $data['description']); |
172 | $this->assertEquals($link['tags'], $data['tags']); | 174 | $this->assertEquals($link['tags'], $data['tags']); |
173 | $this->assertEquals(true, $data['private']); | 175 | $this->assertEquals(true, $data['private']); |
174 | $this->assertTrue(new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); | 176 | $this->assertTrue( |
177 | new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | ||
178 | ); | ||
175 | $this->assertEquals('', $data['updated']); | 179 | $this->assertEquals('', $data['updated']); |
176 | } | 180 | } |
177 | 181 | ||
@@ -207,11 +211,11 @@ class PostLinkTest extends TestCase | |||
207 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 211 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
208 | $this->assertEquals(false, $data['private']); | 212 | $this->assertEquals(false, $data['private']); |
209 | $this->assertEquals( | 213 | $this->assertEquals( |
210 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 214 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), |
211 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
212 | ); | 216 | ); |
213 | $this->assertEquals( | 217 | $this->assertEquals( |
214 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 218 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), |
215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 219 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
216 | ); | 220 | ); |
217 | } | 221 | } |
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 8a562571..cd815b66 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php | |||
@@ -3,14 +3,14 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | |||
7 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
8 | use Slim\Container; | 8 | use Slim\Container; |
9 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
11 | use Slim\Http\Response; | 11 | use Slim\Http\Response; |
12 | 12 | ||
13 | class PutLinkTest extends \PHPUnit_Framework_TestCase | 13 | class PutLinkTest extends \PHPUnit\Framework\TestCase |
14 | { | 14 | { |
15 | /** | 15 | /** |
16 | * @var string datastore to test write operations | 16 | * @var string datastore to test write operations |
@@ -33,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
33 | protected $refDB = null; | 33 | protected $refDB = null; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * @var \History instance. | 36 | * @var HistoryController instance. |
37 | */ | 37 | */ |
38 | protected $history; | 38 | protected $history; |
39 | 39 | ||
@@ -63,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
63 | 63 | ||
64 | $refHistory = new \ReferenceHistory(); | 64 | $refHistory = new \ReferenceHistory(); |
65 | $refHistory->write(self::$testHistory); | 65 | $refHistory->write(self::$testHistory); |
66 | $this->history = new \History(self::$testHistory); | 66 | $this->history = new History(self::$testHistory); |
67 | 67 | ||
68 | $this->container = new Container(); | 68 | $this->container = new Container(); |
69 | $this->container['conf'] = $this->conf; | 69 | $this->container['conf'] = $this->conf; |
70 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 70 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); |
71 | $this->container['history'] = new \History(self::$testHistory); | 71 | $this->container['history'] = new History(self::$testHistory); |
72 | 72 | ||
73 | $this->controller = new Links($this->container); | 73 | $this->controller = new Links($this->container); |
74 | 74 | ||
@@ -115,10 +115,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
115 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), | 115 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), |
116 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 116 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
117 | ); | 117 | ); |
118 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); | 118 | $this->assertTrue( |
119 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | ||
120 | ); | ||
119 | 121 | ||
120 | $historyEntry = $this->history->getHistory()[0]; | 122 | $historyEntry = $this->history->getHistory()[0]; |
121 | $this->assertEquals(\History::UPDATED, $historyEntry['event']); | 123 | $this->assertEquals(History::UPDATED, $historyEntry['event']); |
122 | $this->assertTrue( | 124 | $this->assertTrue( |
123 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 125 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
124 | ); | 126 | ); |
@@ -160,7 +162,9 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
160 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), | 162 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), |
161 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 163 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
162 | ); | 164 | ); |
163 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); | 165 | $this->assertTrue( |
166 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | ||
167 | ); | ||
164 | } | 168 | } |
165 | 169 | ||
166 | /** | 170 | /** |
@@ -195,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
195 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 199 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
196 | $this->assertEquals(false, $data['private']); | 200 | $this->assertEquals(false, $data['private']); |
197 | $this->assertEquals( | 201 | $this->assertEquals( |
198 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 202 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), |
199 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 203 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
200 | ); | 204 | ); |
201 | $this->assertEquals( | 205 | $this->assertEquals( |
202 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 206 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), |
203 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 207 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
204 | ); | 208 | ); |
205 | } | 209 | } |