diff options
Diffstat (limited to 'www/wiki/tests/phpunit/mocks')
18 files changed, 910 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/mocks/MockChangesListFilter.php b/www/wiki/tests/phpunit/mocks/MockChangesListFilter.php new file mode 100644 index 00000000..79232ad1 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/MockChangesListFilter.php @@ -0,0 +1,15 @@ +<?php + +class MockChangesListFilter extends ChangesListFilter { + public function displaysOnUnstructuredUi() { + throw new MWException( + 'Not implemented: If the test relies on this, put it one of the ' . + 'subclasses\' tests (e.g. ChangesListBooleanFilterTest) ' . + 'instead of testing the abstract class' + ); + } + + public function isSelected( FormOptions $opts ) { + return false; + } +} diff --git a/www/wiki/tests/phpunit/mocks/MockChangesListFilterGroup.php b/www/wiki/tests/phpunit/mocks/MockChangesListFilterGroup.php new file mode 100644 index 00000000..e50b9b4e --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/MockChangesListFilterGroup.php @@ -0,0 +1,21 @@ +<?php + +use Wikimedia\Rdbms\IDatabase; + +class MockChangesListFilterGroup extends ChangesListFilterGroup { + public function createFilter( array $filterDefinition ) { + return new MockChangesListFilter( $filterDefinition ); + } + + public function registerFilter( MockChangesListFilter $filter ) { + $this->filters[$filter->getName()] = $filter; + } + + public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage, + &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, + $isStructuredFiltersEnabled ) { + } + + public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) { + } +} diff --git a/www/wiki/tests/phpunit/mocks/MockMessageLocalizer.php b/www/wiki/tests/phpunit/mocks/MockMessageLocalizer.php new file mode 100644 index 00000000..143a419f --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/MockMessageLocalizer.php @@ -0,0 +1,49 @@ +<?php + +/** + * A simple {@link MessageLocalizer} implementation for use in tests. + * By default, it sets the message language to 'qqx', + * to make the tests independent of the wiki configuration. + * + * @author Lucas Werkmeister + * @license GPL-2.0-or-later + */ +class MockMessageLocalizer implements MessageLocalizer { + + /** + * @var string|null + */ + private $languageCode; + + /** + * @param string|null $languageCode The language code to use for messages by default. + * You can specify null to use the user language, + * but this is not recommended as it may make your tests depend on the wiki configuration. + */ + public function __construct( $languageCode = 'qqx' ) { + $this->languageCode = $languageCode; + } + + /** + * Get a Message object. + * Parameters are the same as {@link wfMessage()}. + * + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. + * @param mixed $args,... + * @return Message + */ + public function msg( $key ) { + $args = func_get_args(); + + /** @var Message $message */ + $message = call_user_func_array( 'wfMessage', $args ); + + if ( $this->languageCode !== null ) { + $message->inLanguage( $this->languageCode ); + } + + return $message; + } + +} diff --git a/www/wiki/tests/phpunit/mocks/MockWebRequest.php b/www/wiki/tests/phpunit/mocks/MockWebRequest.php new file mode 100644 index 00000000..90475c38 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/MockWebRequest.php @@ -0,0 +1,25 @@ +<?php + +/** + * A mock WebRequest. + * + * If the code under test accesses the response via the request (see + * WebRequest#response), then you might be able to use this mock to simplify + * your tests. + */ +class MockWebRequest extends WebRequest { + /** + * @var WebResponse + */ + protected $response; + + public function __construct( WebResponse $response ) { + parent::__construct(); + + $this->response = $response; + } + + public function response() { + return $this->response; + } +} diff --git a/www/wiki/tests/phpunit/mocks/content/DummyContentForTesting.php b/www/wiki/tests/phpunit/mocks/content/DummyContentForTesting.php new file mode 100644 index 00000000..e8259d3a --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/content/DummyContentForTesting.php @@ -0,0 +1,123 @@ +<?php + +class DummyContentForTesting extends AbstractContent { + + const MODEL_ID = "testing"; + + public function __construct( $data ) { + parent::__construct( self::MODEL_ID ); + + $this->data = $data; + } + + public function serialize( $format = null ) { + return serialize( $this->data ); + } + + /** + * @return string A string representing the content in a way useful for + * building a full text search index. If no useful representation exists, + * this method returns an empty string. + */ + public function getTextForSearchIndex() { + return ''; + } + + /** + * @return string|bool The wikitext to include when another page includes this content, + * or false if the content is not includable in a wikitext page. + */ + public function getWikitextForTransclusion() { + return false; + } + + /** + * Returns a textual representation of the content suitable for use in edit + * summaries and log messages. + * + * @param int $maxlength Maximum length of the summary text. + * @return string The summary text. + */ + public function getTextForSummary( $maxlength = 250 ) { + return ''; + } + + /** + * Returns native represenation of the data. Interpretation depends on the data model used, + * as given by getDataModel(). + * + * @return mixed The native representation of the content. Could be a string, a nested array + * structure, an object, a binary blob... anything, really. + */ + public function getNativeData() { + return $this->data; + } + + /** + * returns the content's nominal size in bogo-bytes. + * + * @return int + */ + public function getSize() { + return strlen( $this->data ); + } + + /** + * Return a copy of this Content object. The following must be true for the object returned + * if $copy = $original->copy() + * + * * get_class($original) === get_class($copy) + * * $original->getModel() === $copy->getModel() + * * $original->equals( $copy ) + * + * If and only if the Content object is imutable, the copy() method can and should + * return $this. That is, $copy === $original may be true, but only for imutable content + * objects. + * + * @return Content A copy of this object + */ + public function copy() { + return $this; + } + + /** + * Returns true if this content is countable as a "real" wiki page, provided + * that it's also in a countable location (e.g. a current revision in the main namespace). + * + * @param bool|null $hasLinks If it is known whether this content contains links, + * provide this information here, to avoid redundant parsing to find out. + * @return bool + */ + public function isCountable( $hasLinks = null ) { + return false; + } + + /** + * @param Title $title + * @param int $revId Unused. + * @param null|ParserOptions $options + * @param bool $generateHtml Whether to generate Html (default: true). If false, the result + * of calling getText() on the ParserOutput object returned by this method is undefined. + * + * @return ParserOutput + */ + public function getParserOutput( Title $title, $revId = null, + ParserOptions $options = null, $generateHtml = true + ) { + return new ParserOutput( $this->getNativeData() ); + } + + /** + * @see AbstractContent::fillParserOutput() + * + * @param Title $title Context title for parsing + * @param int|null $revId Revision ID (for {{REVISIONID}}) + * @param ParserOptions $options + * @param bool $generateHtml Whether or not to generate HTML + * @param ParserOutput &$output The output object to fill (reference). + */ + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output ) { + $output = new ParserOutput( $this->getNativeData() ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/content/DummyContentHandlerForTesting.php b/www/wiki/tests/phpunit/mocks/content/DummyContentHandlerForTesting.php new file mode 100644 index 00000000..b71577c7 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/content/DummyContentHandlerForTesting.php @@ -0,0 +1,42 @@ +<?php + +class DummyContentHandlerForTesting extends ContentHandler { + + public function __construct( $dataModel, $formats = [ DummyContentForTesting::MODEL_ID ] ) { + parent::__construct( $dataModel, $formats ); + } + + /** + * @see ContentHandler::serializeContent + * + * @param Content $content + * @param string $format + * + * @return string + */ + public function serializeContent( Content $content, $format = null ) { + return $content->serialize(); + } + + /** + * @see ContentHandler::unserializeContent + * + * @param string $blob + * @param string $format Unused. + * + * @return Content + */ + public function unserializeContent( $blob, $format = null ) { + $d = unserialize( $blob ); + + return new DummyContentForTesting( $d ); + } + + /** + * Creates an empty Content object of the type supported by this ContentHandler. + * @return DummyContentForTesting + */ + public function makeEmptyContent() { + return new DummyContentForTesting( '' ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/content/DummyNonTextContent.php b/www/wiki/tests/phpunit/mocks/content/DummyNonTextContent.php new file mode 100644 index 00000000..91bb1866 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/content/DummyNonTextContent.php @@ -0,0 +1,121 @@ +<?php + +class DummyNonTextContent extends AbstractContent { + + public function __construct( $data ) { + parent::__construct( "testing-nontext" ); + + $this->data = $data; + } + + public function serialize( $format = null ) { + return serialize( $this->data ); + } + + /** + * @return string A string representing the content in a way useful for + * building a full text search index. If no useful representation exists, + * this method returns an empty string. + */ + public function getTextForSearchIndex() { + return ''; + } + + /** + * @return string|bool The wikitext to include when another page includes this content, + * or false if the content is not includable in a wikitext page. + */ + public function getWikitextForTransclusion() { + return false; + } + + /** + * Returns a textual representation of the content suitable for use in edit + * summaries and log messages. + * + * @param int $maxlength Maximum length of the summary text. + * @return string The summary text. + */ + public function getTextForSummary( $maxlength = 250 ) { + return ''; + } + + /** + * Returns native represenation of the data. Interpretation depends on the data model used, + * as given by getDataModel(). + * + * @return mixed The native representation of the content. Could be a string, a nested array + * structure, an object, a binary blob... anything, really. + */ + public function getNativeData() { + return $this->data; + } + + /** + * returns the content's nominal size in bogo-bytes. + * + * @return int + */ + public function getSize() { + return strlen( $this->data ); + } + + /** + * Return a copy of this Content object. The following must be true for the object returned + * if $copy = $original->copy() + * + * * get_class($original) === get_class($copy) + * * $original->getModel() === $copy->getModel() + * * $original->equals( $copy ) + * + * If and only if the Content object is imutable, the copy() method can and should + * return $this. That is, $copy === $original may be true, but only for imutable content + * objects. + * + * @return Content A copy of this object + */ + public function copy() { + return $this; + } + + /** + * Returns true if this content is countable as a "real" wiki page, provided + * that it's also in a countable location (e.g. a current revision in the main namespace). + * + * @param bool|null $hasLinks If it is known whether this content contains links, + * provide this information here, to avoid redundant parsing to find out. + * @return bool + */ + public function isCountable( $hasLinks = null ) { + return false; + } + + /** + * @param Title $title + * @param int $revId Unused. + * @param null|ParserOptions $options + * @param bool $generateHtml Whether to generate Html (default: true). If false, the result + * of calling getText() on the ParserOutput object returned by this method is undefined. + * + * @return ParserOutput + */ + public function getParserOutput( Title $title, $revId = null, + ParserOptions $options = null, $generateHtml = true + ) { + return new ParserOutput( $this->getNativeData() ); + } + + /** + * @see AbstractContent::fillParserOutput() + * + * @param Title $title Context title for parsing + * @param int|null $revId Revision ID (for {{REVISIONID}}) + * @param ParserOptions $options + * @param bool $generateHtml Whether or not to generate HTML + * @param ParserOutput &$output The output object to fill (reference). + */ + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output ) { + $output = new ParserOutput( $this->getNativeData() ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/content/DummyNonTextContentHandler.php b/www/wiki/tests/phpunit/mocks/content/DummyNonTextContentHandler.php new file mode 100644 index 00000000..9d91d4a1 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/content/DummyNonTextContentHandler.php @@ -0,0 +1,47 @@ +<?php + +class DummyNonTextContentHandler extends DummyContentHandlerForTesting { + + public function __construct( $dataModel ) { + parent::__construct( $dataModel, [ "testing-nontext" ] ); + } + + /** + * @see ContentHandler::serializeContent + * + * @param Content $content + * @param string $format + * + * @return string + */ + public function serializeContent( Content $content, $format = null ) { + return $content->serialize(); + } + + /** + * @see ContentHandler::unserializeContent + * + * @param string $blob + * @param string $format Unused. + * + * @return Content + */ + public function unserializeContent( $blob, $format = null ) { + $d = unserialize( $blob ); + + return new DummyNonTextContent( $d ); + } + + /** + * Creates an empty Content object of the type supported by this ContentHandler. + * @return DummyNonTextContent + */ + public function makeEmptyContent() { + return new DummyNonTextContent( '' ); + } + + public function supportsDirectApiEditing() { + return true; + } + +} diff --git a/www/wiki/tests/phpunit/mocks/content/DummySerializeErrorContentHandler.php b/www/wiki/tests/phpunit/mocks/content/DummySerializeErrorContentHandler.php new file mode 100644 index 00000000..720547a5 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/content/DummySerializeErrorContentHandler.php @@ -0,0 +1,51 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +/** + * A dummy content handler that will throw on an attempt to serialize content. + */ +class DummySerializeErrorContentHandler extends DummyContentHandlerForTesting { + + public function __construct( $dataModel ) { + parent::__construct( $dataModel, [ "testing-serialize-error" ] ); + } + + /** + * @see ContentHandler::unserializeContent + * + * @param string $blob + * @param string $format + * + * @return Content + */ + public function unserializeContent( $blob, $format = null ) { + throw new MWContentSerializationException( 'Could not unserialize content' ); + } + + /** + * @see ContentHandler::supportsDirectEditing + * + * @return bool + * + * @todo Should this be in the parent class? + */ + public function supportsDirectApiEditing() { + return true; + } + +} diff --git a/www/wiki/tests/phpunit/mocks/filebackend/MockFSFile.php b/www/wiki/tests/phpunit/mocks/filebackend/MockFSFile.php new file mode 100644 index 00000000..ef1caa5d --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/filebackend/MockFSFile.php @@ -0,0 +1,66 @@ +<?php +/** + * Mock of a filesystem file. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup FileBackend + */ + +/** + * Class representing an in-memory fake file. + * This is intended for unit testing / development when you do not want + * to hit the filesystem. + * + * It reimplements abstract methods with some hardcoded values. Might + * not be suitable for all tests but is good enough for the parser tests. + * + * @ingroup FileBackend + */ +class MockFSFile extends FSFile { + protected $sha1Base36 = null; // File Sha1Base36 + + public function exists() { + return true; + } + + /** + * August 22 – The theft of the Mona Lisa is discovered in the Louvre." + * T22281 + * @return int + */ + public function getSize() { + return 1911; + } + + public function getTimestamp() { + return wfTimestamp( TS_MW ); + } + + public function getProps( $ext = true ) { + return [ + 'fileExists' => $this->exists(), + 'size' => $this->getSize(), + 'file-mime' => 'text/mock', + 'sha1' => $this->getSha1Base36(), + ]; + } + + public function getSha1Base36( $recache = false ) { + return '1234567890123456789012345678901'; + } +} diff --git a/www/wiki/tests/phpunit/mocks/filebackend/MockFileBackend.php b/www/wiki/tests/phpunit/mocks/filebackend/MockFileBackend.php new file mode 100644 index 00000000..0a049930 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/filebackend/MockFileBackend.php @@ -0,0 +1,39 @@ +<?php +/** + * Simulation (mock) of a backend storage. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup FileBackend + * @author Antoine Musso <hashar@free.fr> + */ + +/** + * Class simulating a backend store. + * + * @ingroup FileBackend + * @since 1.22 + */ +class MockFileBackend extends MemoryFileBackend { + protected function doGetLocalCopyMulti( array $params ) { + $tmpFiles = []; // (path => MockFSFile) + foreach ( $params['srcs'] as $src ) { + $tmpFiles[$src] = new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) ); + } + return $tmpFiles; + } +} diff --git a/www/wiki/tests/phpunit/mocks/filerepo/MockLocalRepo.php b/www/wiki/tests/phpunit/mocks/filerepo/MockLocalRepo.php new file mode 100644 index 00000000..eeaf05a0 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/filerepo/MockLocalRepo.php @@ -0,0 +1,23 @@ +<?php + +/** + * Class simulating a local file repo. + * + * @ingroup FileRepo + * @since 1.28 + */ +class MockLocalRepo extends LocalRepo { + function getLocalCopy( $virtualUrl ) { + return new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) ); + } + + function getLocalReference( $virtualUrl ) { + return new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) ); + } + + function getFileProps( $virtualUrl ) { + $fsFile = $this->getLocalReference( $virtualUrl ); + + return $fsFile->getProps(); + } +} diff --git a/www/wiki/tests/phpunit/mocks/media/MockBitmapHandler.php b/www/wiki/tests/phpunit/mocks/media/MockBitmapHandler.php new file mode 100644 index 00000000..38cacf9f --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/media/MockBitmapHandler.php @@ -0,0 +1,32 @@ +<?php +/** + * Fake handler for Bitmap images. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Media + */ + +class MockBitmapHandler extends BitmapHandler { + function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { + return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags ); + } + + function doClientImage( $image, $scalerParams ) { + return $this->getClientScalingThumbnailImage( $image, $scalerParams ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/media/MockDjVuHandler.php b/www/wiki/tests/phpunit/mocks/media/MockDjVuHandler.php new file mode 100644 index 00000000..0e0b9435 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/media/MockDjVuHandler.php @@ -0,0 +1,53 @@ +<?php +/** + * Fake handler for DjVu images. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Media + */ + +class MockDjVuHandler extends DjVuHandler { + function isEnabled() { + return true; + } + + function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { + if ( !$this->normaliseParams( $image, $params ) ) { + return new TransformParameterError( $params ); + } + $width = $params['width']; + $height = $params['height']; + $page = $params['page']; + if ( $page > $this->pageCount( $image ) ) { + return new MediaTransformError( + 'thumbnail_error', + $width, + $height, + wfMessage( 'djvu_page_error' )->text() + ); + } + + $params = [ + 'width' => $width, + 'height' => $height, + 'page' => $page + ]; + + return new ThumbnailImage( $image, $dstUrl, $dstPath, $params ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/media/MockImageHandler.php b/www/wiki/tests/phpunit/mocks/media/MockImageHandler.php new file mode 100644 index 00000000..e0082919 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/media/MockImageHandler.php @@ -0,0 +1,86 @@ +<?php +/** + * Fake handler for images. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Media + */ + +/** + * Mock handler for images. + * + * This is really intended for unit testing. + * + * @ingroup Media + */ +class MockImageHandler { + + /** + * Override BitmapHandler::doTransform() making sure we do not generate + * a thumbnail at all. That is merely returning a ThumbnailImage that + * will be consumed by the unit test. There is no need to create a real + * thumbnail on the filesystem. + * @param ImageHandler $that + * @param File $image + * @param string $dstPath + * @param string $dstUrl + * @param array $params + * @param int $flags + * @return ThumbnailImage + */ + static function doFakeTransform( $that, $image, $dstPath, $dstUrl, $params, $flags = 0 ) { + # Example of what we receive: + # $image: LocalFile + # $dstPath: /tmp/transform_7d0a7a2f1a09-1.jpg + # $dstUrl : http://example.com/images/thumb/0/09/Bad.jpg/320px-Bad.jpg + # $params: width: 320, descriptionUrl http://trunk.dev/wiki/File:Bad.jpg + + $that->normaliseParams( $image, $params ); + + $scalerParams = [ + # The size to which the image will be resized + 'physicalWidth' => $params['physicalWidth'], + 'physicalHeight' => $params['physicalHeight'], + 'physicalDimensions' => "{$params['physicalWidth']}x{$params['physicalHeight']}", + # The size of the image on the page + 'clientWidth' => $params['width'], + 'clientHeight' => $params['height'], + # Comment as will be added to the EXIF of the thumbnail + 'comment' => isset( $params['descriptionUrl'] ) ? + "File source: {$params['descriptionUrl']}" : '', + # Properties of the original image + 'srcWidth' => $image->getWidth(), + 'srcHeight' => $image->getHeight(), + 'mimeType' => $image->getMimeType(), + 'dstPath' => $dstPath, + 'dstUrl' => $dstUrl, + ]; + + # In some cases, we do not bother generating a thumbnail. + if ( !$image->mustRender() && + $scalerParams['physicalWidth'] == $scalerParams['srcWidth'] + && $scalerParams['physicalHeight'] == $scalerParams['srcHeight'] + ) { + wfDebug( __METHOD__ . ": returning unscaled image\n" ); + // getClientScalingThumbnailImage is protected + return $that->doClientImage( $image, $scalerParams ); + } + + return new ThumbnailImage( $image, $dstUrl, false, $params ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/media/MockSvgHandler.php b/www/wiki/tests/phpunit/mocks/media/MockSvgHandler.php new file mode 100644 index 00000000..21520c44 --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/media/MockSvgHandler.php @@ -0,0 +1,28 @@ +<?php +/** + * Fake handler for SVG images. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Media + */ + +class MockSvgHandler extends SvgHandler { + function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { + return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags ); + } +} diff --git a/www/wiki/tests/phpunit/mocks/session/DummySessionBackend.php b/www/wiki/tests/phpunit/mocks/session/DummySessionBackend.php new file mode 100644 index 00000000..d5d771bd --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/session/DummySessionBackend.php @@ -0,0 +1,29 @@ +<?php + +namespace MediaWiki\Session; + +/** + * Dummy session backend + * + * This isn't a real backend, but implements some methods that SessionBackend + * does so tests can run. + */ +class DummySessionBackend { + public $data = [ + 'foo' => 1, + 'bar' => 2, + 0 => 'zero', + ]; + public $dirty = false; + + public function &getData() { + return $this->data; + } + + public function dirty() { + $this->dirty = true; + } + + public function deregisterSession( $index ) { + } +} diff --git a/www/wiki/tests/phpunit/mocks/session/DummySessionProvider.php b/www/wiki/tests/phpunit/mocks/session/DummySessionProvider.php new file mode 100644 index 00000000..dcbb101a --- /dev/null +++ b/www/wiki/tests/phpunit/mocks/session/DummySessionProvider.php @@ -0,0 +1,60 @@ +<?php +use MediaWiki\Session\SessionProvider; +use MediaWiki\Session\SessionInfo; +use MediaWiki\Session\SessionBackend; +use MediaWiki\Session\UserInfo; + +/** + * Dummy session provider + * + * An implementation of a session provider that doesn't actually do anything. + */ +class DummySessionProvider extends SessionProvider { + + const ID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + + public function provideSessionInfo( WebRequest $request ) { + return new SessionInfo( SessionInfo::MIN_PRIORITY, [ + 'provider' => $this, + 'id' => self::ID, + 'persisted' => true, + 'userInfo' => UserInfo::newAnonymous(), + ] ); + } + + public function newSessionInfo( $id = null ) { + return new SessionInfo( SessionInfo::MIN_PRIORITY, [ + 'id' => $id, + 'idIsSafe' => true, + 'provider' => $this, + 'persisted' => false, + 'userInfo' => UserInfo::newAnonymous(), + ] ); + } + + public function persistsSessionId() { + return true; + } + + public function canChangeUser() { + return $this->persistsSessionId(); + } + + public function persistSession( SessionBackend $session, WebRequest $request ) { + } + + public function unpersistSession( WebRequest $request ) { + } + + public function immutableSessionCouldExistForUser( $user ) { + return false; + } + + public function preventImmutableSessionsForUser( $user ) { + } + + public function suggestLoginUsername( WebRequest $request ) { + return $request->getCookie( 'UserName' ); + } + +} |