<commit_before><?php

namespace OCA\User_Hiorg\Tests\Hiorg;

use OCP\ILogger;
use OCP\IConfig;
use OCA\User_Hiorg\IDataRetriever;
use OCA\User_Hiorg\Hiorg\SingleSignOn;
use PHPUnit\Framework\TestCase;

class SingleSignOnTest extends TestCase
{
	const AJAXLOGIN = 'https://www.hiorg-server.de/ajax/login.php';

	private $logger;
	private $config;
	private $dataRetriever;

	private $androidRestAPI;

	public function setUp()
	{
		parent::setUp();

		$this->logger = $this->createMock(ILogger::class);
		$this->config = $this->createMock(IConfig::class);
		$this->dataRetriever = $this->createMock(IDataRetriever::class);

		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('user_hiorg', 'ov')
			->willReturn('dummy_ov');

		$this->androidRestAPI = new SingleSignOn(
			$this->logger,
			$this->config,
			$this->dataRetriever
		);
	}

	public function testUnavailableSSO()
	{
		$this->mockDataRetriever([
			'body' => false
		]);
		$this->mockLogWarning('Hiorg SSO not reachable.');

		$result = $this->androidRestAPI->getUserInfo('dummy_user', 'dummy_password');

		$this->assertFalse($result);
	}

	public function testInvalidCredentials()
	{
		$this->mockDataRetriever([
			'body' => 'foo'
		]);
		$this->mockLogInfo('Wrong HIORG password.');

		$result = $this->androidRestAPI->getUserInfo('dummy_user', 'dummy_password');

		$this->assertFalse($result);
	}

	public function testMissingToken()
	{<commit_msg>adapt tests<commit_after><?php

namespace OCA\User_Hiorg\Tests\Hiorg;

use OCP\ILogger;
use OCP\IConfig;
use OCP\ISession;
use OCA\User_Hiorg\IDataRetriever;
use OCA\User_Hiorg\Hiorg\SingleSignOn;
use PHPUnit\Framework\TestCase;

class SingleSignOnTest extends TestCase
{
	const AJAXLOGIN = 'https://www.hiorg-server.de/ajax/login.php';

	private $logger;
	private $config;
	private $session;
	private $dataRetriever;

	private $androidRestAPI;

	public function setUp()
	{
		parent::setUp();

		$this->logger = $this->createMock(ILogger::class);
		$this->config = $this->createMock(IConfig::class);
		$this->session = $this->createMock(ISession::class);
		$this->dataRetriever = $this->createMock(IDataRetriever::class);

		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('user_hiorg', 'ov')
			->willReturn('dummy_ov');

		$this->androidRestAPI = new SingleSignOn(
			$this->logger,
			$this->config,
			$this->session,
			$this->dataRetriever
		);
	}

	public function testUnavailableSSO()
	{
		$this->mockDataRetriever([
			'body' => false
		]);
		$this->mockLogWarning('Hiorg SSO not reachable.');

		$result = $this->androidRestAPI->getUserInfo('dummy_user', 'dummy_password');

		$this->assertFalse($result);
	}

	public function testInvalidCredentials()
	{
		$this->mockDataRetriever([
			'body' => 'foo'
		]);
		$this->mockLogInfo('Wrong HIORG password.');

		$result = $this->androidRestAPI->getUserInfo('dummy_user', 'dummy_password');

		$this->assertFalse($result);
	}

	public function testMissingToken()
	{
{'fraction_non_alphanumeric': 0.16761268781302172, 'fraction_numerical': 0.0, 'mean_word_length': 4.992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '2349790', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1082, 'n_words': 168}