wiki.techinc.nl/tests/phpunit/mocks/content/DummySerializeErrorContentHandler.php
Aryeh Gregor 0b9edb467b Get ~100% test coverage for ApiEditPage.php and fix a couple of bugs
Bugs fixed:

* The major one was that appendtext and prependtext seemingly didn't
  work at all on empty pages in the MediaWiki namespace, because
  $this->getTitle() was being used in place of $titleObj.
* Negative undo/undoafter were not rejected in a correct fashion.
* If a logged-in user who was not allowed to upload images tried to
  create an image redirect, the error message used a nonexistent key.

I also replaced assertEquals with assertSame.

I also removed a bit of clearly dead code.  This includes a "break"
following dieStatus().  If we actually want this break so that nobody
adds a case after the default and then removes the dieStatus() so the
switch incorrectly falls through, it could be re-added with
@codeCoverageIgnore.

I put the fixes in the same commit as the test changes because I like to
keep fixes together with the tests for those fixes.

All code now shows up as covered locally, except for one line that seems
to be a PHPUnit bug.

Change-Id: I9375bc5f40268fd681a2d447c66a03f40b23390a
2018-03-28 15:33:24 +03:00

51 lines
1.5 KiB
PHP

<?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;
}
}