Phantom42 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/401405 )
Change subject: Add tests for ApiFormatRaw
......................................................................
Add tests for ApiFormatRaw
Bug: T183767
Change-Id: I63ce42dd61f6e47f7278c436cad1e4f05e287b04
---
A tests/phpunit/includes/api/format/ApiFormatRawTest.php
1 file changed, 110 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/05/401405/1
diff --git a/tests/phpunit/includes/api/format/ApiFormatRawTest.php
b/tests/phpunit/includes/api/format/ApiFormatRawTest.php
new file mode 100644
index 0000000..9017926
--- /dev/null
+++ b/tests/phpunit/includes/api/format/ApiFormatRawTest.php
@@ -0,0 +1,110 @@
+<?php
+
+/**
+ * @group API
+ * @covers ApiFormatRaw
+ */
+class ApiFormatRawTest extends ApiFormatTestBase {
+
+ protected $printerName = 'raw';
+
+ /**
+ * Only basic types are tested here as ApiFormatRaw does not work with
+ * arrays or objects
+ * @return array datasets
+ */
+ public static function provideGeneralEncoding() {
+ return [
+ [ [ true ], '1' ],
+ [ [ false ], '' ],
+ [ [ 42 ], '42' ],
+ [ [ 42.5 ], '42.5' ],
+ [ [ 1e42 ], '1.0E+42' ],
+ [ [ 'foo' ], 'foo' ],
+ [ [ 'fóo' ], 'fóo' ],
+ ];
+ }
+
+ /**
+ * Get the ApiFormatRaw formatter output for the given input data
+ * @param array $params Query parameters
+ * @param array $data Data to encode
+ * @param string $class This argument is ignored
+ * @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 );
+
+ $result = $main->getResult();
+ $result->addValue( null, 'mime', 'text/plain' );
+ $result->addArrayType( null, 'default' );
+ $result->addValue( null, 'text', $data[0] );
+
+ $printer = new ApiFormatRaw( $main );
+ $printer->initPrinter();
+ $printer->execute();
+ ob_start();
+ try {
+ $printer->closePrinter();
+ return ob_get_clean();
+ } catch ( Exception $ex ) {
+ ob_end_clean();
+ throw $ex;
+ }
+ }
+
+ /**
+ * Check that ApiFormatRaw throws exception if mime type is not set
+ * @expectedException MWException
+ */
+ public function testMissingMimeError() {
+ $context = new RequestContext;
+ $context->setRequest( new FauxRequest( [], true ) );
+ $main = new ApiMain( $context );
+
+ $result = $main->getResult();
+ $result->addArrayType( null, 'default' );
+ $result->addValue( null, 'text', 'some text' );
+
+ $printer = new ApiFormatRaw( $main );
+ $printer->initPrinter();
+ $printer->execute();
+ ob_start();
+ try {
+ $printer->closePrinter();
+ } catch ( Exception $ex ) {
+ throw $ex;
+ }
+ ob_end_clean();
+ }
+
+ /**
+ * Check that ApiFormatRaw throws exception if no text is given
+ * @expectedException MWException
+ */
+ public function testNoTextError() {
+ $context = new RequestContext;
+ $context->setRequest( new FauxRequest( [], true ) );
+ $main = new ApiMain( $context );
+
+ $result = $main->getResult();
+ $result->addValue( null, 'mime', 'text/plain' );
+ $result->addArrayType( null, 'default' );
+ $result->addValue( null, 'some key', 'some value' );
+
+ $printer = new ApiFormatRaw( $main );
+ $printer->initPrinter();
+ $printer->execute();
+ ob_start();
+ try {
+ $printer->closePrinter();
+ } catch ( Exception $ex ) {
+ throw $ex;
+ }
+ ob_end_clean();
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/401405
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I63ce42dd61f6e47f7278c436cad1e4f05e287b04
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits