<commit_before><?php

namespace GoogleLogin;

use MediaWiki\User\UserIdentityValue;
use MediaWikiUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\LoadBalancer;

class GoogleIdProviderTest extends MediaWikiUnitTestCase {

	/**
	 * @var IDatabase|MockObject
	 */
	private $dbConnection;

	/**
	 * @var LoadBalancer
	 */
	private $loadBalancer;

	protected function setUp() : void {
		parent::setUp();

		$this->dbConnection = $this->getMockBuilder( IDatabase::class )
				->disableOriginalConstructor()
				->getMock();

		$this->loadBalancer = $this->getMockBuilder( ILoadBalancer::class )
			->disableOriginalConstructor()
			->getMock();
		$this->loadBalancer->method( 'getConnection' )->willReturn( $this->dbConnection );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserAnonymousUser() {
		$this->dbConnection->expects( $this->never() )->method( 'select' );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 0, '127.0.0.1', 0 );
		$this->assertEmpty( $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserNoAssociatedIds() {
		$this->dbConnection->expects( $this->once() )
			->method( 'select' )
			->with( $this->anything(), $this->anything(), [ 'user_id' => 123 ] )
			->willReturn( false );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 123, __CLASS__, 222 );
		$this->assertEmpty( $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserAssociatedIds() {
		$aResult = (object)[ 'user_googleid' => 1 ];
		$anotherResult = (object)[ 'user_googleid' => 2 ];
		$this->dbConnection->expects( $this->once() )
			->method( 'select' )
			->with( $this->anything(), $this->anything(), [ 'user_id' => 123 ] )
			->willReturn( [ $aResult, $anotherResult ] );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 123, __CLASS__, 222 );
		$this->assertEquals( [ 1, 2 ], $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @dataProvider provideIsAssociated
	 * @param $resultCount
	 * @param $expected<commit_msg>Remove incomplete @param from test function<commit_after><?php

namespace GoogleLogin;

use MediaWiki\User\UserIdentityValue;
use MediaWikiUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\LoadBalancer;

class GoogleIdProviderTest extends MediaWikiUnitTestCase {

	/**
	 * @var IDatabase|MockObject
	 */
	private $dbConnection;

	/**
	 * @var LoadBalancer
	 */
	private $loadBalancer;

	protected function setUp() : void {
		parent::setUp();

		$this->dbConnection = $this->getMockBuilder( IDatabase::class )
				->disableOriginalConstructor()
				->getMock();

		$this->loadBalancer = $this->getMockBuilder( ILoadBalancer::class )
			->disableOriginalConstructor()
			->getMock();
		$this->loadBalancer->method( 'getConnection' )->willReturn( $this->dbConnection );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserAnonymousUser() {
		$this->dbConnection->expects( $this->never() )->method( 'select' );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 0, '127.0.0.1', 0 );
		$this->assertEmpty( $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserNoAssociatedIds() {
		$this->dbConnection->expects( $this->once() )
			->method( 'select' )
			->with( $this->anything(), $this->anything(), [ 'user_id' => 123 ] )
			->willReturn( false );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 123, __CLASS__, 222 );
		$this->assertEmpty( $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @covers \GoogleLogin\GoogleIdProvider::getFromUser()
	 */
	public function testGetFromUserAssociatedIds() {
		$aResult = (object)[ 'user_googleid' => 1 ];
		$anotherResult = (object)[ 'user_googleid' => 2 ];
		$this->dbConnection->expects( $this->once() )
			->method( 'select' )
			->with( $this->anything(), $this->anything(), [ 'user_id' => 123 ] )
			->willReturn( [ $aResult, $anotherResult ] );
		$googleIdProvider = new GoogleIdProvider( $this->loadBalancer );

		$user = new UserIdentityValue( 123, __CLASS__, 222 );
		$this->assertEquals( [ 1, 2 ], $googleIdProvider->getFromUser( $user ) );
	}

	/**
	 * @dataProvider provideIsAssociated
{'fraction_non_alphanumeric': 0.16551579828415985, 'fraction_numerical': 0.012554927809165096, 'mean_word_length': 4.7729468599033815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1212045', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1529, 'n_words': 286}