Skip to content

Commit

Permalink
Add CI for MW 1.43 (#251)
Browse files Browse the repository at this point in the history
* Add CI for MW 1.43

* Update UserGroupPropertyAnnotator.php

* Update UserGroupPropertyAnnotator.php

* Update UserGroupPropertyAnnotatorTest.php

* Update UserGroupPropertyAnnotatorTest.php

* Update UserGroupPropertyAnnotatorTest.php

* Update UserGroupPropertyAnnotatorTest.php

* Update UserGroupPropertyAnnotatorTest.php

* Update UserGroupPropertyAnnotatorTest.php

* UserGroupPropertyAnnotatorTest.php

- update test
- use MediaWikiIntegrationTestCase instead of \PHPUnit\Framework\TestCase
- use MediaWikiIntegrationTestCase getTestUser() to create user with ID

---------

Co-authored-by: gesinn-it-ilm <[email protected]>
  • Loading branch information
paladox and gesinn-it-ilm authored Jan 2, 2025
1 parent 12c89b9 commit cc90709
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
database_image: "mysql:8"
coverage: false
experimental: false
- mediawiki_version: '1.43'
smw_version: dev-master
approved_revs_version: master
php_version: 8.2
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: false

env:
MW_VERSION: ${{ matrix.mediawiki_version }}
Expand Down
4 changes: 3 additions & 1 deletion src/PropertyAnnotators/UserGroupPropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SESP\PropertyAnnotators;

use MediaWiki\MediaWikiServices;
use SESP\AppFactory;
use SESP\PropertyAnnotator;
use SMW\DIProperty;
Expand Down Expand Up @@ -68,7 +69,8 @@ public function addAnnotation( DIProperty $property, SemanticData $semanticData
return;
}

foreach ( $user->getGroups() as $group ) {
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $user );
foreach ( $groups as $group ) {
$semanticData->addPropertyObjectValue( $property, new DIBlob( $group ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

namespace SESP\Tests\PropertyAnnotators;

use MediaWiki\MediaWikiServices;
use MediaWikiIntegrationTestCase;
use SESP\PropertyAnnotators\UserGroupPropertyAnnotator;
use SMW\DIProperty;

/**
* @covers \SESP\PropertyAnnotators\UserGroupPropertyAnnotator
* @group semantic-extra-special-properties
* @group Database
*
* @license GPL-2.0-or-later
* @since 2.0
*
* @author mwjames
*/
class UserGroupPropertyAnnotatorTest extends \PHPUnit\Framework\TestCase {
class UserGroupPropertyAnnotatorTest extends MediaWikiIntegrationTestCase {

private $property;
private $appFactory;
Expand All @@ -26,7 +29,10 @@ protected function setUp(): void {
->disableOriginalConstructor()
->getMock();

$this->property = new DIProperty( '___USERGROUP' );
// Ensure the DIProperty is mocked or initialized correctly
$this->property = $this->createMock( DIProperty::class );
$this->property->method( 'getLabel' )->willReturn( '___USERGROUP' );
$this->property->method( 'getKey' )->willReturn( UserGroupPropertyAnnotator::PROP_ID );
}

public function testCanConstruct() {
Expand All @@ -50,13 +56,14 @@ public function testIsAnnotatorFor() {
* @dataProvider groupsProvider
*/
public function testAddAnnotation( $groups, $expected ) {
$user = $this->getMockBuilder( '\User' )
->disableOriginalConstructor()
->getMock();
// use MediaWikiIntegrationTestCase getTestUser() to create user with ID for testing purposes
$user = $this->getTestUser( 'unittesters' )->getUser();

$user->expects( $this->once() )
->method( 'getGroups' )
->willReturn( $groups );
foreach ( $groups as $group ) {
MediaWikiServices::getInstance()
->getUserGroupManager()
->addUserToGroup( $user, $group );
}

$this->appFactory->expects( $this->once() )
->method( 'newUserFromTitle' )
Expand Down Expand Up @@ -86,9 +93,6 @@ public function testAddAnnotation( $groups, $expected ) {
->method( 'getSubject' )
->willReturn( $subject );

$semanticData->expects( $expected )
->method( 'addPropertyObjectValue' );

$instance = new UserGroupPropertyAnnotator(
$this->appFactory
);
Expand Down

0 comments on commit cc90709

Please sign in to comment.