summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/api/format/ApiFormatTestBase.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /tests/phpunit/includes/api/format/ApiFormatTestBase.php
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'tests/phpunit/includes/api/format/ApiFormatTestBase.php')
-rw-r--r--tests/phpunit/includes/api/format/ApiFormatTestBase.php70
1 files changed, 51 insertions, 19 deletions
diff --git a/tests/phpunit/includes/api/format/ApiFormatTestBase.php b/tests/phpunit/includes/api/format/ApiFormatTestBase.php
index 5f6d53ce..cabf62b1 100644
--- a/tests/phpunit/includes/api/format/ApiFormatTestBase.php
+++ b/tests/phpunit/includes/api/format/ApiFormatTestBase.php
@@ -1,32 +1,64 @@
<?php
-abstract class ApiFormatTestBase extends ApiTestCase {
+abstract class ApiFormatTestBase extends MediaWikiTestCase {
/**
- * @param string $format
- * @param array $params
- * @param array $data
- *
- * @return string
+ * Name of the formatter being tested
+ * @var string
*/
- protected function apiRequest( $format, $params, $data = null ) {
- $data = parent::doApiRequest( $params, $data, true );
-
- /** @var ApiMain $module */
- $module = $data[3];
+ protected $printerName;
- $printer = $module->createPrinterByName( $format );
- $printer->setUnescapeAmps( false );
+ /**
+ * Return general data to be encoded for testing
+ * @return array See self::testGeneralEncoding
+ * @throws Exception
+ */
+ public static function provideGeneralEncoding() {
+ throw new Exception( 'Subclass must implement ' . __METHOD__ );
+ }
- $printer->initPrinter( false );
+ /**
+ * Get the formatter output for the given input data
+ * @param array $params Query parameters
+ * @param array $data Data to encode
+ * @param string $class Printer class to use instead of the normal one
+ * @return string
+ * @throws Exception
+ */
+ protected function encodeData( array $params, array $data, $class = null ) {
+ $context = new RequestContext;
+ $context->setRequest( new FauxRequest( $params, true ) );
+ $main = new ApiMain( $context );
+ if ( $class !== null ) {
+ $main->getModuleManager()->addModule( $this->printerName, 'format', $class );
+ }
+ $result = $main->getResult();
+ $result->addArrayType( null, 'default' );
+ foreach ( $data as $k => $v ) {
+ $result->addValue( null, $k, $v );
+ }
- ob_start();
+ $printer = $main->createPrinterByName( $this->printerName );
+ $printer->initPrinter();
$printer->execute();
- $out = ob_get_clean();
-
- $printer->closePrinter();
+ ob_start();
+ try {
+ $printer->closePrinter();
+ return ob_get_clean();
+ } catch ( Exception $ex ) {
+ ob_end_clean();
+ throw $ex;
+ }
+ }
- return $out;
+ /**
+ * @dataProvider provideGeneralEncoding
+ */
+ public function testGeneralEncoding( array $data, $expect, array $params = array() ) {
+ if ( isset( $params['SKIP'] ) ) {
+ $this->markTestSkipped( $expect );
+ }
+ $this->assertSame( $expect, $this->encodeData( $params, $data ) );
}
}