From b06fc28aa32f477e1785cd998385fdb490bc5ebf Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 29 Aug 2020 11:45:08 +0200 Subject: REST API: allow override of creation and update dates Note that if they're not provided, default behaviour will apply: creation and update dates will be autogenerated, and not empty. Fixes #1223 --- tests/api/controllers/links/PostLinkTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/api/controllers/links/PostLinkTest.php') diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 4e791a04..f969fe1c 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -160,6 +160,8 @@ class PostLinkTest extends TestCase 'description' => 'shaare description', 'tags' => ['one', 'two'], 'private' => true, + 'created' => '2015-05-05T12:30:00+03:00', + 'updated' => '2016-06-05T14:32:10+03:00', ]; $env = Environment::mock([ 'REQUEST_METHOD' => 'POST', @@ -181,10 +183,8 @@ class PostLinkTest extends TestCase $this->assertEquals($link['description'], $data['description']); $this->assertEquals($link['tags'], $data['tags']); $this->assertEquals(true, $data['private']); - $this->assertTrue( - new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) - ); - $this->assertEquals('', $data['updated']); + $this->assertSame($link['created'], $data['created']); + $this->assertSame($link['updated'], $data['updated']); } /** -- cgit v1.2.3 From fd1ddad98df45bc3c18be7980c1cbe68ce6b219c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Sep 2020 14:18:01 +0200 Subject: Add mutex on datastore I/O operations To make sure that there is no concurrent operation on the datastore file. Fixes #1132 --- tests/api/controllers/links/PostLinkTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/api/controllers/links/PostLinkTest.php') diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 20694571..7ff92f5c 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -2,6 +2,7 @@ namespace Shaarli\Api\Controllers; +use malkusch\lock\mutex\NoMutex; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; @@ -72,6 +73,7 @@ class PostLinkTest extends TestCase */ protected function setUp(): void { + $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); @@ -79,7 +81,7 @@ class PostLinkTest extends TestCase $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); $this->container = new Container(); $this->container['conf'] = $this->conf; -- cgit v1.2.3 From b37ca790729125fa0df956220a4062f1d34c57e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Carr?= Date: Wed, 28 Oct 2020 19:57:40 -0700 Subject: postLink: change relative path to absolute path --- tests/api/controllers/links/PostLinkTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/api/controllers/links/PostLinkTest.php') diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index b2dd09eb..969b9fd9 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -90,8 +90,8 @@ class PostLinkTest extends TestCase $mock = $this->createMock(Router::class); $mock->expects($this->any()) - ->method('relativePathFor') - ->willReturn('api/v1/bookmarks/1'); + ->method('pathFor') + ->willReturn('/api/v1/bookmarks/1'); // affect @property-read... seems to work $this->controller->getCi()->router = $mock; @@ -126,7 +126,7 @@ class PostLinkTest extends TestCase $response = $this->controller->postLink($request, new Response()); $this->assertEquals(201, $response->getStatusCode()); - $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); + $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(43, $data['id']); @@ -171,7 +171,7 @@ class PostLinkTest extends TestCase $response = $this->controller->postLink($request, new Response()); $this->assertEquals(201, $response->getStatusCode()); - $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); + $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(43, $data['id']); -- cgit v1.2.3