From e26e2060f5470ce8bf4c5973284bae07b8af170a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 17 Jan 2020 21:34:12 +0100 Subject: Add and update unit test for the new system (Bookmark + Service) See #1307 --- tests/api/controllers/links/PutLinkTest.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'tests/api/controllers/links/PutLinkTest.php') diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index cd815b66..cb63742e 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -3,6 +3,8 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\Bookmark; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Slim\Container; @@ -32,6 +34,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase */ protected $refDB = null; + /** + * @var BookmarkFileService instance. + */ + protected $bookmarkService; + /** * @var HistoryController instance. */ @@ -53,22 +60,23 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase const NB_FIELDS_LINK = 9; /** - * Before every test, instantiate a new Api with its config, plugins and links. + * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { - $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); - $this->container['history'] = new History(self::$testHistory); + $this->container['db'] = $this->bookmarkService; + $this->container['history'] = $this->history; $this->controller = new Links($this->container); @@ -110,7 +118,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals('?WDWyig', $data['title']); $this->assertEquals('', $data['description']); $this->assertEquals([], $data['tags']); - $this->assertEquals(false, $data['private']); + $this->assertEquals(true, $data['private']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20150310_114651'), \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) @@ -199,11 +207,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(false, $data['private']); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130614_184135'), \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) ); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130615_184230'), \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) ); } -- cgit v1.2.3 From 301c7ab1a079d937ab41c6f52b8804e5731008e6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 28 Jul 2020 20:46:11 +0200 Subject: Better support for notes permalink --- tests/api/controllers/links/PutLinkTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/api/controllers/links/PutLinkTest.php') diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index cb63742e..302cac0f 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -114,8 +114,8 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals($id, $data['id']); $this->assertEquals('WDWyig', $data['shorturl']); - $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); - $this->assertEquals('?WDWyig', $data['title']); + $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); + $this->assertEquals('/shaare/WDWyig', $data['title']); $this->assertEquals('', $data['description']); $this->assertEquals([], $data['tags']); $this->assertEquals(true, $data['private']); -- cgit v1.2.3 From 8f60e1206e45e67c96a7630d4ff94e72fe875f09 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Sep 2020 15:08:39 +0200 Subject: Comply with PHPUnit V8: setup/teardown functions must return void --- tests/api/controllers/links/PutLinkTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/api/controllers/links/PutLinkTest.php') diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 302cac0f..f582a2b5 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -62,7 +62,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -91,7 +91,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); -- cgit v1.2.3 From b1baca99f280570d0336b4d71ad1f9dca213a35b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 27 Sep 2020 14:07:08 +0200 Subject: Convert legacy PHPUnit @expected* to new ->expect* Converted automatically using https://github.com/ArthurHoaro/convert-legacy-phpunit-expect --- tests/api/controllers/links/PutLinkTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/api/controllers/links/PutLinkTest.php') diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index f582a2b5..3d62a1b1 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -218,12 +218,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * Test link update on non existent link => ApiLinkNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException - * @expectedExceptionMessage Link not found */ public function testGetLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $this->expectExceptionMessage('Link not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]); -- cgit v1.2.3 From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/api/controllers/links/PutLinkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/api/controllers/links/PutLinkTest.php') diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 3d62a1b1..a2e87c59 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -12,7 +12,7 @@ use Slim\Http\Environment; use Slim\Http\Request; use Slim\Http\Response; -class PutLinkTest extends \PHPUnit\Framework\TestCase +class PutLinkTest extends \Shaarli\TestCase { /** * @var string datastore to test write operations -- cgit v1.2.3