aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/GetLinksTest.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/GetLinksTest.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/GetLinksTest.php')
-rw-r--r--tests/api/controllers/links/GetLinksTest.php23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index 711a3152..ca1bfc63 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -1,8 +1,11 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\Bookmark;
5use Shaarli\Bookmark\BookmarkFileService;
4use Shaarli\Bookmark\LinkDB; 6use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
6use Slim\Container; 9use Slim\Container;
7use Slim\Http\Environment; 10use Slim\Http\Environment;
8use Slim\Http\Request; 11use 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 */
20class GetLinksTest extends \PHPUnit\Framework\TestCase 23class GetLinksTest 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 GetLinksTest extends \PHPUnit\Framework\TestCase
50 const NB_FIELDS_LINK = 9; 53 const NB_FIELDS_LINK = 9;
51 54
52 /** 55 /**
53 * Before every test, instantiate a new Api with its config, plugins and links. 56 * Before every 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 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,13 +74,13 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
69 /** 74 /**
70 * After every test, remove the test datastore. 75 * After every 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 }
76 81
77 /** 82 /**
78 * Test basic getLinks service: returns all links. 83 * Test basic getLinks service: returns all bookmarks.
79 */ 84 */
80 public function testGetLinks() 85 public function testGetLinks()
81 { 86 {
@@ -104,7 +109,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
104 109
105 // Check first element fields 110 // Check first element fields
106 $first = $data[2]; 111 $first = $data[2];
107 $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); 112 $this->assertEquals('http://domain.tld/shaare/WDWyig', $first['url']);
108 $this->assertEquals('WDWyig', $first['shorturl']); 113 $this->assertEquals('WDWyig', $first['shorturl']);
109 $this->assertEquals('Link title: @website', $first['title']); 114 $this->assertEquals('Link title: @website', $first['title']);
110 $this->assertEquals( 115 $this->assertEquals(
@@ -114,7 +119,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
114 $this->assertEquals('sTuff', $first['tags'][0]); 119 $this->assertEquals('sTuff', $first['tags'][0]);
115 $this->assertEquals(false, $first['private']); 120 $this->assertEquals(false, $first['private']);
116 $this->assertEquals( 121 $this->assertEquals(
117 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 122 \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
118 $first['created'] 123 $first['created']
119 ); 124 );
120 $this->assertEmpty($first['updated']); 125 $this->assertEmpty($first['updated']);
@@ -125,7 +130,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
125 130
126 // Update date 131 // Update date
127 $this->assertEquals( 132 $this->assertEquals(
128 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), 133 \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
129 $link['updated'] 134 $link['updated']
130 ); 135 );
131 } 136 }