diff --git a/tests/phpunit/EventCalendarTest.php b/tests/phpunit/EventCalendarTest.php index 5fef76e..8e840d9 100644 --- a/tests/phpunit/EventCalendarTest.php +++ b/tests/phpunit/EventCalendarTest.php @@ -21,6 +21,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Integration test of tag. * @@ -599,7 +601,6 @@ public function dataProvider() { ] ]; - // TODO: test removal of thumbnails. yield 'calendar with snippets (symbols=50)' => [ [ 'January 1: New Year' => @@ -771,6 +772,35 @@ public function testSnippetForCompressedRevision() { $this->assertSame( $expectedSnippet, $actualData[0]['title'] ); } + /** + * Verify that unwanted parts of HTML (such as images) are removed from the snippet. + */ + public function testSnippetSanitizer() { + $filename = 'Testimage.png'; + $pageText = "Expected snippet [[File:$filename]]"; + $expectedSnippet = '

Expected snippet ' . + "

"; + + // Upload a test file, so that [[File:]] syntax would create an actual thumbnail, not a redlink. + $user = $this->getTestUser()->getUser(); + $stash = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->getUploadStash( $user ); + $key = $stash->stashFile( __DIR__ . '/../resources/image100x100.png' )->getFileKey(); + + $upload = new UploadFromStash( $user ); + $upload->initialize( $key, $filename ); + + $status = $upload->performUpload( '', false, false, $user ); + $this->assertTrue( $status->isOK(), 'Failed to upload test file: ' . $status->getMessage()->plain() ); + + $this->insertPage( 'January 1: New Year', $pageText ); + + // Render the calendar. + $wikitext = "titleRegex = ^([A-Za-z]+_[0-9][0-9]?).*\ndateFormat = F_j\nsymbols = 500"; + $actualData = $this->parseCalendarEvents( $wikitext ); + + $this->assertSame( $expectedSnippet, $actualData[0]['title'] ); + } + /** * Verify that parameters like height=300 and aspectratio=1.5 are provided to JavaScript library. * @dataProvider dataProviderOptionalAttributes diff --git a/tests/resources/image100x100.png b/tests/resources/image100x100.png new file mode 100644 index 0000000..62b590c Binary files /dev/null and b/tests/resources/image100x100.png differ