From 9f9627059a0b17de45a90e3c5fad9c1a49318151 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 7 Aug 2019 13:18:02 +0200 Subject: Make sure that bookmark sort is consistent, even with equal timestamps Fixes #1348 --- tests/bookmark/LinkDBTest.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/bookmark') diff --git a/tests/bookmark/LinkDBTest.php b/tests/bookmark/LinkDBTest.php index 2990a6b5..5bbdcea1 100644 --- a/tests/bookmark/LinkDBTest.php +++ b/tests/bookmark/LinkDBTest.php @@ -619,4 +619,39 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase $this->assertEquals($expected, $tags, var_export($tags, true)); } + + /** + * Make sure that bookmarks with the same timestamp have a consistent order: + * if their creation date is equal, bookmarks are sorted by ID DESC. + */ + public function testConsistentOrder() + { + $nextId = 42; + $creation = DateTime::createFromFormat('Ymd_His', '20190807_130444'); + $linkDB = new LinkDB(self::$testDatastore, true, false); + for ($i = 0; $i < 4; ++$i) { + $linkDB[$nextId + $i] = [ + 'id' => $nextId + $i, + 'url' => 'http://'. $i, + 'created' => $creation, + 'title' => true, + 'description' => true, + 'tags' => true, + ]; + } + + // Check 4 new links 4 times + for ($i = 0; $i < 4; ++$i) { + $linkDB->save('tests'); + $linkDB = new LinkDB(self::$testDatastore, true, false); + $count = 3; + foreach ($linkDB as $link) { + $this->assertEquals($nextId + $count, $link['id']); + $this->assertEquals('http://'. $count, $link['url']); + if (--$count < 0) { + break; + } + } + } + } } -- cgit v1.2.3