Skip to content

Commit

Permalink
UserGroupPropertyAnnotatorTest.php
Browse files Browse the repository at this point in the history
- update test
- use MediaWikiIntegrationTestCase instead of \PHPUnit\Framework\TestCase
- use MediaWikiIntegrationTestCase getTestUser() to create user with ID
  • Loading branch information
gesinn-it-ilm committed Jan 2, 2025
1 parent 8f1b615 commit 3d116c2
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace SESP\Tests\PropertyAnnotators;

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

// use MediaWiki\User\UserGroupManager;

/**
* @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 @@ -29,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 @@ -53,23 +56,15 @@ 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();

// We can't mock this as we call this directly in addAnnotation so not
// reachable to mock.
foreach ( $groups as $group ) {
MediaWikiServices::getInstance()
->getUserGroupManager()
->addUserToGroup( $user, $group );
}

// $userGroupManager = $this->createMock( UserGroupManager::class );
// $userGroupManager
// ->method( 'getUserGroups' )
// ->willReturn( $groups );

$this->appFactory->expects( $this->once() )
->method( 'newUserFromTitle' )
->willReturn( $user );
Expand Down Expand Up @@ -98,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 3d116c2

Please sign in to comment.