diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-08-07 13:18:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-08-07 13:18:02 +0200 |
commit | 9f9627059a0b17de45a90e3c5fad9c1a49318151 (patch) | |
tree | 7d977b55db34ff63d3148d885805a1859f0dba09 /tests/bookmark | |
parent | 1a6d61766a80369579041e5a80831f9f6754fe48 (diff) | |
download | Shaarli-9f9627059a0b17de45a90e3c5fad9c1a49318151.tar.gz Shaarli-9f9627059a0b17de45a90e3c5fad9c1a49318151.tar.zst Shaarli-9f9627059a0b17de45a90e3c5fad9c1a49318151.zip |
Make sure that bookmark sort is consistent, even with equal timestamps
Fixes #1348
Diffstat (limited to 'tests/bookmark')
-rw-r--r-- | tests/bookmark/LinkDBTest.php | 35 |
1 files changed, 35 insertions, 0 deletions
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 | |||
619 | 619 | ||
620 | $this->assertEquals($expected, $tags, var_export($tags, true)); | 620 | $this->assertEquals($expected, $tags, var_export($tags, true)); |
621 | } | 621 | } |
622 | |||
623 | /** | ||
624 | * Make sure that bookmarks with the same timestamp have a consistent order: | ||
625 | * if their creation date is equal, bookmarks are sorted by ID DESC. | ||
626 | */ | ||
627 | public function testConsistentOrder() | ||
628 | { | ||
629 | $nextId = 42; | ||
630 | $creation = DateTime::createFromFormat('Ymd_His', '20190807_130444'); | ||
631 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
632 | for ($i = 0; $i < 4; ++$i) { | ||
633 | $linkDB[$nextId + $i] = [ | ||
634 | 'id' => $nextId + $i, | ||
635 | 'url' => 'http://'. $i, | ||
636 | 'created' => $creation, | ||
637 | 'title' => true, | ||
638 | 'description' => true, | ||
639 | 'tags' => true, | ||
640 | ]; | ||
641 | } | ||
642 | |||
643 | // Check 4 new links 4 times | ||
644 | for ($i = 0; $i < 4; ++$i) { | ||
645 | $linkDB->save('tests'); | ||
646 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
647 | $count = 3; | ||
648 | foreach ($linkDB as $link) { | ||
649 | $this->assertEquals($nextId + $count, $link['id']); | ||
650 | $this->assertEquals('http://'. $count, $link['url']); | ||
651 | if (--$count < 0) { | ||
652 | break; | ||
653 | } | ||
654 | } | ||
655 | } | ||
656 | } | ||
622 | } | 657 | } |