aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/ReferenceLinkDB.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index f09eebc1..e887aa78 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -141,6 +141,7 @@ class ReferenceLinkDB
141 */ 141 */
142 public function write($filename) 142 public function write($filename)
143 { 143 {
144 $this->reorder();
144 file_put_contents( 145 file_put_contents(
145 $filename, 146 $filename,
146 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>' 147 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>'
@@ -148,6 +149,27 @@ class ReferenceLinkDB
148 } 149 }
149 150
150 /** 151 /**
152 * Reorder links by creation date (newest first).
153 *
154 * Also update the urls and ids mapping arrays.
155 *
156 * @param string $order ASC|DESC
157 */
158 public function reorder($order = 'DESC')
159 {
160 // backward compatibility: ignore reorder if the the `created` field doesn't exist
161 if (! isset(array_values($this->_links)[0]['created'])) {
162 return;
163 }
164
165 $order = $order === 'ASC' ? -1 : 1;
166 // Reorder array by dates.
167 usort($this->_links, function($a, $b) use ($order) {
168 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
169 });
170 }
171
172 /**
151 * Returns the number of links in the reference data 173 * Returns the number of links in the reference data
152 */ 174 */
153 public function countLinks() 175 public function countLinks()
@@ -187,6 +209,7 @@ class ReferenceLinkDB
187 209
188 public function getLinks() 210 public function getLinks()
189 { 211 {
212 $this->reorder();
190 return $this->_links; 213 return $this->_links;
191 } 214 }
192 215