r79532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79531‎ | r79532 | r79533 >
Date:21:36, 3 January 2011
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
Add API format testing
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/api/ApiSetup.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/api/format (added) (history)
  • /trunk/phase3/tests/phpunit/includes/api/format/ApiFormatPhpTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/api/format/ApiFormatTestBase.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/ApiSetup.php
@@ -17,7 +17,7 @@
1818 $this->setupUser();
1919 }
2020
21 - protected function doApiRequest( $params, $data = null ) {
 21+ protected function doApiRequest( $params, $data = null, $appendModule = false ) {
2222 $_SESSION = isset( $data[2] ) ? $data[2] : array();
2323
2424 $req = new FauxRequest( $params, true, $_SESSION );
@@ -27,6 +27,8 @@
2828 $data[0] = $module->getResultData();
2929 $data[1] = $req;
3030 $data[2] = $_SESSION;
 31+
 32+ if( $appendModule ) $data[3] = $module;
3133
3234 return $data;
3335 }
Index: trunk/phase3/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
@@ -0,0 +1,26 @@
 2+<?php
 3+
 4+require_once dirname( __FILE__ ) . '/ApiFormatTestBase.php';
 5+
 6+/**
 7+ * @group API
 8+ */
 9+class ApiFormatPhpTest extends ApiFormatTestBase {
 10+
 11+ /*function setUp() {
 12+ parent::setUp();
 13+ $this->doLogin();
 14+ }*/
 15+
 16+
 17+ function testValidPHPSyntax() {
 18+
 19+ $data = $this->apiRequest( 'php', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
 20+
 21+ $this->assertInternalType( 'array', unserialize( $data ) );
 22+ $this->assertGreaterThan( 0, count( (array) $data ) );
 23+
 24+
 25+ }
 26+
 27+}
Property changes on: trunk/phase3/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
___________________________________________________________________
Added: svn:eol-style
128 + native
Index: trunk/phase3/tests/phpunit/includes/api/format/ApiFormatTestBase.php
@@ -0,0 +1,28 @@
 2+<?php
 3+
 4+require_once dirname( dirname( __FILE__ ) ) . '/ApiSetup.php';
 5+
 6+abstract class ApiFormatTestBase extends ApiTestSetup {
 7+
 8+ protected function apiRequest( $format, $params, $data = null ) {
 9+
 10+ $data = parent::doApiRequest( $params, $data, true );
 11+
 12+ $module = $data[3];
 13+
 14+ $printer = $module->createPrinterByName( $format );
 15+ $printer->setUnescapeAmps(false);
 16+
 17+ $printer->initPrinter(false, true);
 18+
 19+ ob_start();
 20+ $printer->execute();
 21+ $out = ob_get_clean();
 22+
 23+ $printer->closePrinter();
 24+
 25+ return $out;
 26+ }
 27+
 28+}
 29+
Property changes on: trunk/phase3/tests/phpunit/includes/api/format/ApiFormatTestBase.php
___________________________________________________________________
Added: svn:eol-style
130 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r79544Followup to r79532: Did I really need to implement a parameter? No, I did not.soxred9301:35, 4 January 2011
r79569Fix r79532: Strct standardssoxred9311:58, 4 January 2011
r79658Follow up r79532. Do not setup a user needlessly.platonides19:35, 5 January 2011
r80182Mark as needing a Database, as noted in r79532 CR....platonides17:51, 13 January 2011

Comments

#Comment by Platonides (talk | contribs)   11:08, 4 January 2011

PHP Strict Standards: Declaration of UploadFromUrlTest::doApiRequest() should be compatible with that of ApiTestSetup::doApiRequest() in tests/phpunit/includes/UploadFromUrlTest.php on line 353

ApiFormatPhpTest::testValidPHPSyntax needs a database and is not in Database group.

#Comment by X! (talk | contribs)   11:43, 4 January 2011

I don't see anything there that needs a database...

#Comment by Platonides (talk | contribs)   12:01, 4 January 2011

Ah, but it needs:

DBConnectionError: DB connection error: No such file or directory (localhost)

  • phase3/includes/db/Database.php:588
  • phase3/includes/db/DatabaseMysql.php:131
  • phase3/includes/db/Database.php:526
  • phase3/includes/db/LoadBalancer.php:639
  • phase3/includes/db/LoadBalancer.php:513
  • phase3/includes/db/LoadBalancer.php:436
  • phase3/includes/GlobalFunctions.php:3024
  • phase3/includes/LocalisationCache.php:767
  • phase3/includes/LocalisationCache.php:321
  • phase3/includes/LocalisationCache.php:350
  • phase3/includes/LocalisationCache.php:262
  • phase3/includes/LocalisationCache.php:205
  • phase3/languages/Language.php:252
  • phase3/languages/Language.php:307
  • phase3/includes/Title.php:506
  • phase3/includes/Title.php:304
  • phase3/includes/User.php:416
  • phase3/includes/User.php:210
  • phase3/includes/User.php:1468
  • phase3/tests/phpunit/includes/api/ApiSetup.php:82
  • phase3/tests/phpunit/includes/api/ApiSetup.php:38
  • phase3/tests/phpunit/includes/api/ApiSetup.php:17
  • phase3/tests/phpunit/MediaWikiTestCase.php:53
  • phase3/tests/phpunit/MediaWikiPHPUnitCommand.php:20
  • phase3/tests/phpunit/phpunit.php:39
#Comment by Platonides (talk | contribs)   19:36, 5 January 2011

After r79658, the only reason it needs a Database now is in order to call getServerVersion() to provide dbversion.

Status & tagging log