<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 *
 * @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 Test\Integration\Competition;

use App\MasterData\Competition;
use App\MasterData\CompetitionState;
use App\MasterData\User;
use App\Tasting\Commission;
use App\Tasting\Taster;
use App\Tasting\TastingSession;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\JsonResponse;
use Test\TestCase;
use function factory;

class TasterTest extends TestCase {

	use DatabaseTransactions;

	public function testListTasters() {
		$user = factory(User::class)->create();
		$competition = factory(Competition::class)->create([
			'competition_state_id' => CompetitionState::STATE_TASTING1,
		]);
		$tastingSession = factory(TastingSession::class)->create([
			'competition_id' => $competition->id,
			'wuser_username' => $user->username,
		]);
		$commission = factory(Commission::class)->create([
			'tastingsession_id' => $tastingSession->id,
		]);
		factory(Taster::class, 5)->create([
			'commission_id' => $commission->id,
		]);

		$this->be($user);<commit_msg>test more taster/session acces permissions<commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 *
 * @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 Test\Integration\Competition;

use App\MasterData\Competition;
use App\MasterData\CompetitionState;
use App\MasterData\User;
use App\Tasting\Commission;
use App\Tasting\Taster;
use App\Tasting\TastingSession;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\JsonResponse;
use Test\TestCase;
use function factory;

class TasterTest extends TestCase {

	use DatabaseTransactions;

	public function tastingSessionUrlsData() {
		return [
			['session/{sessionId}'],
			['session/{sessionId}/edit'],
			['session/{sessionId}/edit', 'POST'],
			['tasters?commission_id={commissionId}'],
		];
	}

	/**
	 * @dataProvider tastingSessionUrlsData
	 */
	public function testNonTastingSessionAdmin($url, $method = 'GET') {
		$user = factory(User::class)->create();
		$tastingSession = factory(TastingSession::class)->create([
			'wuser_username' => $user->username,
		]);
		$commission = factory(Commission::class)->create([
			'tastingsession_id' => $tastingSession->id,
		]);
		$url = str_replace('{sessionId}', $tastingSession->id, $url);
		$url = str_replace('{commissionId}', $commission->id, $url);

		$this->be($user);
		$this->call($method, $url);
		$this->assertResponseStatus(403);
	}

	public function testListTasters() {
		$user = factory(User::class)->create();
		$competition = factory(Competition::class)->create([
			'competition_state_id' => CompetitionState::STATE_TASTING1,
		]);
		$tastingSession = factory(TastingSession::class)->create([
			'competition_id' => $competition->id,
			'wuser_username' => $user->username,
		]);
		$commission = factory(Commission::class)->create([
			'tastingsession_id' => $tastingSession->id,
		]);
		factory(Taster::class, 5)->create([
			'commission_id' => $commission->id,
		]);

		$this->be($user);
{'fraction_non_alphanumeric': 0.13596386974090802, 'fraction_numerical': 0.0035654860946042312, 'mean_word_length': 4.893557422969188, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, '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': '1075198', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1263, 'n_words': 343}