diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f632a29..4646f92 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 }} diff --git a/src/PropertyAnnotators/UserGroupPropertyAnnotator.php b/src/PropertyAnnotators/UserGroupPropertyAnnotator.php index 29cc969..6ee7350 100644 --- a/src/PropertyAnnotators/UserGroupPropertyAnnotator.php +++ b/src/PropertyAnnotators/UserGroupPropertyAnnotator.php @@ -2,6 +2,7 @@ namespace SESP\PropertyAnnotators; +use MediaWiki\MediaWikiServices; use SESP\AppFactory; use SESP\PropertyAnnotator; use SMW\DIProperty; @@ -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 ) ); } } diff --git a/tests/phpunit/Unit/PropertyAnnotators/UserGroupPropertyAnnotatorTest.php b/tests/phpunit/Unit/PropertyAnnotators/UserGroupPropertyAnnotatorTest.php index 6bf7ceb..cbfd663 100644 --- a/tests/phpunit/Unit/PropertyAnnotators/UserGroupPropertyAnnotatorTest.php +++ b/tests/phpunit/Unit/PropertyAnnotators/UserGroupPropertyAnnotatorTest.php @@ -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; @@ -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() { @@ -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' ) @@ -86,9 +93,6 @@ public function testAddAnnotation( $groups, $expected ) { ->method( 'getSubject' ) ->willReturn( $subject ); - $semanticData->expects( $expected ) - ->method( 'addPropertyObjectValue' ); - $instance = new UserGroupPropertyAnnotator( $this->appFactory );