Skip to content

Commit

Permalink
Fix Issue 27 (#28)
Browse files Browse the repository at this point in the history
* add integration test to demonstrate #27
* fix #27 by updating the signature of Hooks::onChangeRevision
  • Loading branch information
gesinn-it-wam authored Mar 15, 2022
1 parent ec4a8c3 commit 41a9609
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ composer.lock
composer.phar

vendor/
extensions/
extensions/
.phpunit.result.cache
8 changes: 2 additions & 6 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,14 @@ public function onIsApprovedRevision( $title, $latestRevID ) {
* @since 1.0
*
* @param Title $title
* @param ?Revision $revision
* @param ?RevisionStoreRecord $record
*/
public function onChangeRevision( $title, ?Revision $revision ) {
public function onChangeRevision( $title, ?RevisionStoreRecord $record ) {

$approvedRevsHandler = new ApprovedRevsHandler(
new ApprovedRevsFacade()
);

$record = null;
if ( $revision !== null ) {
$record = $revision->getRevisionRecord();
}
$approvedRevsHandler->doChangeRevision( $title, $record );

return true;
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/Integration/ApproveRevisionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace SMW\ApprovedRevs\Tests\Integration;

use ApiTestCase;

/**
* @group SemanticApprovedRevs
* @group API
* @group Database
* @group medium
*
* @covers \SMW\ApprovedRevs\Hooks
*/
class ApproveRevisionTest extends ApiTestCase {

public function testApprove() {
// NOTE: this test is known not to work when using MySql
// Seems like an SMW problem with temporary tables; the following would help:
// \MediaWikiCliOptions::$additionalOptions['use-normal-tables'] = true

// Re-register SMW hook handlers
// TODO: find a way to have the test use the Wiki "as it is" without having to re-register manually
\SemanticMediaWiki::onExtensionFunction();
\SMW\ApprovedRevs\Hooks::onExtensionFunction();

$page = $this->getExistingTestPage('ApproveRevisionApiTest');
$revId = $page->getRevisionRecord()->getId();
$tokens = $this->getTokenList($this->getTestSysop());

$result = $this->doApiRequest( [
'action' => 'approve',
'revid' => $revId,
'token' => $tokens['edittoken']
] );

$this->assertEquals("Revision was successfully approved.", $result[0]["approve"]["result"]);
}
}

0 comments on commit 41a9609

Please sign in to comment.