Add API format testing
authorX! <soxred93@users.mediawiki.org>
Mon, 3 Jan 2011 21:36:49 +0000 (21:36 +0000)
committerX! <soxred93@users.mediawiki.org>
Mon, 3 Jan 2011 21:36:49 +0000 (21:36 +0000)
tests/phpunit/includes/api/ApiSetup.php
tests/phpunit/includes/api/format/ApiFormatPhpTest.php [new file with mode: 0644]
tests/phpunit/includes/api/format/ApiFormatTestBase.php [new file with mode: 0644]

index f7b6f3f..4459a88 100644 (file)
@@ -17,7 +17,7 @@ abstract class ApiTestSetup extends MediaWikiTestCase {
                $this->setupUser();
        }
 
-       protected function doApiRequest( $params, $data = null ) {
+       protected function doApiRequest( $params, $data = null, $appendModule = false ) {
                $_SESSION = isset( $data[2] ) ? $data[2] : array();
 
                $req = new FauxRequest( $params, true, $_SESSION );
@@ -27,6 +27,8 @@ abstract class ApiTestSetup extends MediaWikiTestCase {
                $data[0] = $module->getResultData();
                $data[1] = $req;
                $data[2] = $_SESSION;
+               
+               if( $appendModule ) $data[3] = $module;
 
                return $data;
        }
diff --git a/tests/phpunit/includes/api/format/ApiFormatPhpTest.php b/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
new file mode 100644 (file)
index 0000000..fb89422
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+require_once dirname( __FILE__ ) . '/ApiFormatTestBase.php';
+
+/**
+ * @group API
+ */
+class ApiFormatPhpTest extends ApiFormatTestBase {
+
+       /*function setUp() {
+               parent::setUp();
+               $this->doLogin();
+       }*/
+
+       
+       function testValidPHPSyntax() {
+               
+               $data = $this->apiRequest( 'php', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
+               
+               $this->assertInternalType( 'array', unserialize( $data ) );
+               $this->assertGreaterThan( 0, count( (array) $data ) );
+               
+               
+       }
+
+}
diff --git a/tests/phpunit/includes/api/format/ApiFormatTestBase.php b/tests/phpunit/includes/api/format/ApiFormatTestBase.php
new file mode 100644 (file)
index 0000000..96800c5
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+require_once dirname( dirname( __FILE__ ) ) . '/ApiSetup.php';
+
+abstract class ApiFormatTestBase extends ApiTestSetup {
+
+       protected function apiRequest( $format, $params, $data = null ) {
+               
+               $data = parent::doApiRequest( $params, $data, true );
+               
+               $module = $data[3];
+               
+               $printer = $module->createPrinterByName( $format );
+               $printer->setUnescapeAmps(false);
+
+               $printer->initPrinter(false, true);
+
+               ob_start();
+               $printer->execute();
+               $out = ob_get_clean();
+               
+               $printer->closePrinter();
+
+               return $out;
+       }
+
+}
+