<commit_before><?php
/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 *
 * @copyright Copyright (c) 2016, Project Seminar "PSSL16" at the University of Muenster.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

namespace OCA\OAuth2\Tests\Unit\Controller;

use OCA\OAuth2\AppInfo\Application;
use OCA\OAuth2\Controller\PageController;
use OCA\OAuth2\Db\AuthorizationCodeMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Http\RedirectResponse;
use PHPUnit_Framework_TestCase;

use OCP\AppFramework\Http\TemplateResponse;


class PageControllerTest extends PHPUnit_Framework_TestCase {

	/** @var PageController $controller */
	private $controller;

	/** @var string $userId */
	private $userId = 'john';

	public function setUp() {
		$request = $this->getMockBuilder('OCP\IRequest')->getMock();

		$app = new Application();
		$container = $app->getContainer();

		/** @var ClientMapper $clientMapper */
		$clientMapper = $container->query('ClientMapper');

		$client = new Client();
		$client->setId('testId7890');
		$client->setSecret('topSecret123');
		$client->setRedirectUri('https://www.example.org');
		$client->setName('Example');
		$clientMapper->insert($client);

		/** @var AuthorizationCodeMapper $authorizationCodeMapper */
		$authorizationCodeMapper = $container->query('AuthorizationCodeMapper');

		$this->controller = new PageController('oauth2', $request, $clientMapper, $authorizationCodeMapper, $this->userId);
	}

	public function testAuthorize() {
		$result = $this->controller->authorize('code', 'client_id', 'redirect_uri', 'state');
		$this->assertTrue($result instanceof RedirectResponse);

		$result = $this->controller->authorize('code', 'testId7890', urldecode('https://www.example.org'), 'state');
		$this->assertTrue($result instanceof TemplateResponse);
	}

}<commit_msg>Improve PageControllerTest<commit_after><?php
/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 *
 * @copyright Copyright (c) 2016, Project Seminar "PSSL16" at the University of Muenster.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

namespace OCA\OAuth2\Tests\Unit\Controller;

use OCA\OAuth2\AppInfo\Application;
use OCA\OAuth2\Controller\PageController;
use OCA\OAuth2\Db\AuthorizationCodeMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Http\RedirectResponse;
use PHPUnit_Framework_TestCase;

use OCP\AppFramework\Http\TemplateResponse;


class PageControllerTest extends PHPUnit_Framework_TestCase {

	/** @var PageController $controller */
	private $controller;

	/** @var ClientMapper $clientMapper */
	private $clientMapper;

	/** @var string $userId */
	private $userId = 'john';

	public function setUp() {
		$request = $this->getMockBuilder('OCP\IRequest')->getMock();

		$app = new Application();
		$container = $app->getContainer();

		$this->clientMapper = $container->query('ClientMapper');

		/** @var Client $client */
		$client = new Client();
		$client->setId('clientId1234567890');
		$client->setSecret('topSecret123');
		$client->setRedirectUri('https://www.example.org');
		$client->setName('Example');
		$this->clientMapper->insert($client);

		/** @var AuthorizationCodeMapper $authorizationCodeMapper */
		$authorizationCodeMapper = $container->query('AuthorizationCodeMapper');

		$this->controller = new PageController('oauth2', $request, $this->clientMapper, $authorizationCodeMapper, $this->userId);
	}

	public function tearDown() {
		$this->clientMapper->delete($this->clientMapper->find('clientId1234567890'));
	}

	public function testAuthorize() {
		$result = $this->controller->authorize('code', 'client_id', 'redirect_uri', 'state');
		$this->assertTrue($result instanceof RedirectResponse);

		$result = $this->controller->authorize('code', 'clientId1234567890', urldecode('https://www.example.org'), 'state');
		$this->assertTrue($result instanceof TemplateResponse);
	}

}
{'fraction_non_alphanumeric': 0.13676869430453312, 'fraction_numerical': 0.015110422316931422, 'mean_word_length': 5.088443396226415, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 58, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, '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': '7477616', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1513, 'n_words': 420}