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/GetLinksTest.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/GetLinksTest.php')
-rw-r--r-- | tests/api/controllers/links/GetLinksTest.php | 23 |
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 |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use Shaarli\Bookmark\Bookmark; | ||
5 | use Shaarli\Bookmark\BookmarkFileService; | ||
4 | use Shaarli\Bookmark\LinkDB; | 6 | use Shaarli\Bookmark\LinkDB; |
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 GetLinksTest extends \PHPUnit\Framework\TestCase | 23 | class 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 | } |