Improve test coverage for ApiStashEdit
[lhc/web/wiklou.git] / includes / api / ApiStashEdit.php
index bf956dc..ab9ae8e 100644 (file)
@@ -151,14 +151,13 @@ class ApiStashEdit extends ApiBase {
                $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $stats->increment( "editstash.cache_stores.$status" );
 
-               $this->getResult()->addValue(
-                       null,
-                       $this->getModuleName(),
-                       [
-                               'status' => $status,
-                               'texthash' => $textHash
-                       ]
-               );
+               $ret = [ 'status' => $status ];
+               // If we were rate-limited, we still return the pre-existing valid hash if one was passed
+               if ( $status !== 'ratelimited' || $params['stashedtexthash'] !== null ) {
+                       $ret['texthash'] = $textHash;
+               }
+
+               $this->getResult()->addValue( null, $this->getModuleName(), $ret );
        }
 
        /**
@@ -235,6 +234,7 @@ class ApiStashEdit extends ApiBase {
                                        return self::ERROR_CACHE;
                                }
                        } else {
+                               // @todo Doesn't seem reachable, see @todo in buildStashValue
                                $logger->info( "Uncacheable parser output for key '{cachekey}' ('{title}') [{code}].",
                                        [ 'cachekey' => $key, 'title' => $titleStr, 'code' => $code ] );
                                return self::ERROR_UNCACHEABLE;
@@ -402,7 +402,7 @@ class ApiStashEdit extends ApiBase {
        ) {
                // If an item is renewed, mind the cache TTL determined by config and parser functions.
                // Put an upper limit on the TTL for sanity to avoid extreme template/file staleness.
-               $since = time() - wfTimestamp( TS_UNIX, $parserOutput->getTimestamp() );
+               $since = time() - wfTimestamp( TS_UNIX, $parserOutput->getCacheTime() );
                $ttl = min( $parserOutput->getCacheExpiry() - $since, self::MAX_CACHE_TTL );
 
                // Avoid extremely stale user signature timestamps (T84843)
@@ -411,6 +411,9 @@ class ApiStashEdit extends ApiBase {
                }
 
                if ( $ttl <= 0 ) {
+                       // @todo It doesn't seem like this can occur, because it would mean an entry older than
+                       // getCacheExpiry() seconds, which is much longer than PRESUME_FRESH_TTL_SEC, and
+                       // anything older than PRESUME_FRESH_TTL_SEC will have been thrown out already.
                        return [ null, 0, 'no_ttl' ];
                }