aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/parser/ParserCacheTest.php
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2020-10-14 07:54:56 -0700
committerPetr Pchelko <ppchelko@wikimedia.org>2020-10-15 13:15:30 -0700
commit09c14b9dd0cc57594d7f4f5aebacb9151c69eb8c (patch)
treecf2a441eee893c4392ff47ea02ab68418dad2d01 /tests/phpunit/includes/parser/ParserCacheTest.php
parent7702eafcd8c9e8d4f6a07ed52c985e299ac9f162 (diff)
downloadmediawikicore-09c14b9dd0cc57594d7f4f5aebacb9151c69eb8c.tar.gz
mediawikicore-09c14b9dd0cc57594d7f4f5aebacb9151c69eb8c.zip
Move serializability validation from ParserOutput to ParserCache
Bug: T263579 Change-Id: Iac2dbc817c2e7af4a6d112f01bd380a04354db22
Diffstat (limited to 'tests/phpunit/includes/parser/ParserCacheTest.php')
-rw-r--r--tests/phpunit/includes/parser/ParserCacheTest.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/phpunit/includes/parser/ParserCacheTest.php b/tests/phpunit/includes/parser/ParserCacheTest.php
index f5191817b608..698dc3e46d71 100644
--- a/tests/phpunit/includes/parser/ParserCacheTest.php
+++ b/tests/phpunit/includes/parser/ParserCacheTest.php
@@ -12,8 +12,12 @@ use NullStatsdDataFactory;
use ParserCache;
use ParserOptions;
use ParserOutput;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
use Psr\Log\NullLogger;
+use TestLogger;
use Title;
+use User;
use Wikimedia\TestingAccessWrapper;
use WikiPage;
@@ -62,11 +66,13 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
/**
* @param HookContainer|null $hookContainer
* @param BagOStuff|null $storage
+ * @param LoggerInterface|null $logger
* @return ParserCache
*/
private function createParserCache(
HookContainer $hookContainer = null,
- BagOStuff $storage = null
+ BagOStuff $storage = null,
+ LoggerInterface $logger = null
): ParserCache {
return new ParserCache(
'test',
@@ -74,7 +80,7 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
'19900220000000',
$hookContainer ?: $this->createHookContainer( [] ),
new NullStatsdDataFactory(),
- new NullLogger()
+ $logger ?: new NullLogger()
);
}
@@ -622,4 +628,39 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
$this->assertEquals( $parserOutput2, $cachedOutput );
}
+ /**
+ * @covers ParserCache::encodeAsJson
+ */
+ public function testNonSerializableJsonIsReported() {
+ $testLogger = new TestLogger( true );
+ $cache = $this->createParserCache( null, null, $testLogger );
+ $cache->setJsonSupport( true, true );
+
+ $parserOutput = $this->createDummyParserOutput();
+ $parserOutput->setExtensionData( 'test', new User() );
+ $cache->save( $parserOutput, $this->page, ParserOptions::newFromAnon() );
+ $this->assertArrayEquals(
+ [ [ LogLevel::ERROR, 'Non-serializable ParserOutput property set' ] ],
+ $testLogger->getBuffer()
+ );
+ }
+
+ /**
+ * @covers ParserCache::encodeAsJson
+ */
+ public function testCyclicStructuresDoNotBlowUpInJson() {
+ $testLogger = new TestLogger( true );
+ $cache = $this->createParserCache( null, null, $testLogger );
+ $cache->setJsonSupport( true, true );
+
+ $parserOutput = $this->createDummyParserOutput();
+ $cyclicArray = [ 'a' => 'b' ];
+ $cyclicArray['c'] = &$cyclicArray;
+ $parserOutput->setExtensionData( 'test', $cyclicArray );
+ $cache->save( $parserOutput, $this->page, ParserOptions::newFromAnon() );
+ $this->assertArrayEquals(
+ [ [ LogLevel::ERROR, 'JSON encoding failed' ] ],
+ $testLogger->getBuffer()
+ );
+ }
}